Impl for javax.lang.model API
Werner Dietl
wdietl at gmail.com
Tue Feb 19 23:37:10 PST 2013
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
>
--
http://www.google.com/profiles/wdietl
More information about the type-annotations-dev
mailing list