Impl for javax.lang.model API

Jonathan Gibbons jonathan.gibbons at oracle.com
Wed Feb 20 18:55:10 PST 2013


I've pushed my initial impl for the new javax.lang.model API, and the
"work so far" on the test I was writing to verify the API.

The doc comments on the API are taken from Joe's recent patch,
and may need revision as needed.

The impl is relatively obvious, although the new code in JavacAnnoConstructs
can be cleaned up somewhat, by sharing more code between the Type and
Symbol cases.

The test is as far as I got before uncovering the issue described earlier.
The infrastructure for the test is overly general (for now) but is 
intended to
support more complex test cases involving repeated annotations.

I think it would be instructive to look at those types that you can get 
at via
multiple paths to verify whether they are equivalent (same type and
annotations).    In particular, for an ExecutableElement you can get at a
bunch of interesting types directly, or you can get at them via the
corresponding ExecutableType.  Likewise, for a TypeElement, you can
get at the type mirrors of the type parameters, or you can get to the type
args via the DeclaredType and getTypeArguments.

I've pushed this as a single changeset to type-annotations.  When we come to
push this to TL, I will push it in two parts -- removing the old API, 
and then
adding the new API. That will make the internal paperwork a bit easier.

Also note that we've (indirectly) added methods to TypeMirror, which has
broken code in the jaxws repo. In an ideal world, we would be able to use
default methods to solve this problem, but we are not there yet. The interim
solution, for now, is that I have pushed a fixup to the jaxws repo.

-- Jon

On 02/19/2013 11:37 PM, Werner Dietl wrote:
> Hi Jon,
>
> answers inline.
>
>
> On Tue, Feb 19, 2013 at 8:28 PM, Jonathan Gibbons
> <jonathan.gibbons at oracle.com> wrote:
>> On 02/19/2013 06:07 PM, Jonathan Gibbons wrote:
>>> Werner,
>>>
>>> I have an initial impl of the new javax.lang.model API, and some initial
>>> tests.
>>>
>>> One test is failing:  given an ExecutableType, the list returned by
>>> getParameterTypes is not returning parameters types with type annotations,
>>> when I think it should.  In particular, a toString() of the ExecutableType
>>> does not indicate any type-annotated parameters, although it does show type
>>> annotations on the return type and thrown types.
>>>
>>> What is the best way to proceed here?  Should I push the "work so far" to
>>> the type-annotations forest for you to investigate?
> Yes, I think pushing to type-annotations would be good and we can iron
> out all problems there.
>
> This is also related to this discussion:
>
> http://mail.openjdk.java.net/pipermail/type-annotations-dev/2013-January/000535.html
>
> to which you wanted to come back to.
>
>
>> Here is some corroborative detail, using DPrinter ...
>>
>> The method in question is
>>
>>      public int m1(@TA(4) float a) throws Exception { return 0; }
>>
>> The first section, labeled "element", is a dump of the ExecutableElement for
>> this method. In this element, the VarSymbol for the first parameter indeed
>> shows the annotation.    See element> params> 0> type.
>>
>> The second section, labeled "type", is a dump of the ExecutableType of the
>> method. The args of the type do not contain any annotations. See type >
>> argtypes > 0.
>>
>> So, the question is, would you expect to see the annotations here?
> I would expect a type annotation @TA on both the parameter type and
> element, yes.
>
> Looking at:
>
> com.sun.tools.javac.code.TypeAnnotations.TypeAnnotationPositions.separateAnnotationsKinds(JCTree,
> Type, Symbol, TypeAnnotationPosition)
>
> you'll see:
>
>              type = typeWithAnnotations(typetree, type, typeAnnotations, log);
>
>              if (sym.getKind() == ElementKind.METHOD) {
>                  sym.type.asMethodType().restype = type;
>              } else {
>                  sym.type = type;
>              }
>
>              sym.annotations.appendUniqueTypes(typeAnnotations);
>
> This constructs the annotated type and then sets it for the parameter symbol.
> Finally, the type annotations are attached to the symbol.
>
> You said that the annotated type shows up for the return type and
> elsewhere, so hopefully typeWithAnnotations does the right thing.
> So, maybe setting sym.type is not enough for a parameter and we also
> need to do something on sym.owner?
> E.g. note how later in that method we copy the type annotations from
> the parameter to the owning method.
>
> cu, WMD.
>
>
>
>
>> element: MethodSymbol,0x10--kindname.method,METHOD m1 #14d8af3
>>    flags: 0x1--public
>>    completer: #null
>>    owner: BasicAnnoTests
>>    type: (float)int
>>    erasure: #null
>>    params: [1]
>>      0: VarSymbol,0x4--kindname.variable,PARAMETER a #4e276f
>>        flags: 0x200000000--parameter
>>        completer: #null
>>        owner: m1(float)
>>        type: (@BasicAnnoTests.TA(4) :: float)
>>        erasure: #null
>>        pos: 9845
>>        adm: -1
>>        data: #null
>>        annotations: #193563d
>>          attributes: [0]
>>          type_attributes: [1]
>>            0: TypeCompound
>>              position: [METHOD_FORMAL_PARAMETER, param_index = 0, pos = 9839]
>>              synthesized: false
>>              values: [1]
>>                0: Pair[value(),4]
>>              type: BasicAnnoTests.TA
>>    savedParameterNames: #null
>>    annotations: #e37ebf
>>      attributes: [1]
>>        0: Compound
>>          synthesized: false
>>          values: [3]
>>            0: Pair[posn(),1]
>>            1: Pair[annoType(),BasicAnnoTests.TA.class]
>>            2: Pair[expect(),"4"]
>>          type: BasicAnnoTests.Test
>>      type_attributes: [1]
>>        0: TypeCompound
>>          position: [METHOD_FORMAL_PARAMETER, param_index = 0, pos = 9839]
>>          synthesized: false
>>          values: [1]
>>            0: Pair[value(),4]
>>          type: BasicAnnoTests.TA
>> type: MethodType,METHOD,EXECUTABLE #b96509
>>    tsym: Method
>>    constValue: #null
>>    annotations: [0]
>>    argtypes: [1]
>>      0: Type,FLOAT,FLOAT #15eb0cd
>>        tsym: float
>>        constValue: #null
>>        annotations: [0]
>>    restype: Type,INT,INT #f328e5
>>      tsym: int
>>      constValue: #null
>>      annotations: [0]
>>    thrown: [1]
>>      0: ClassType,CLASS,DECLARED #1eead82
>>        tsym: java.lang.Exception
>>        constValue: #null
>>        annotations: [0]
>>        outer: <none>
>>        typarams: [0]
>>        allparams: #null
>>        supertype: java.lang.Throwable
>>        interfaces: [0]
>>        allinterfaces: #null
>>
>
>



More information about the type-annotations-dev mailing list