type annotations inside javac
Jonathan Gibbons
jonathan.gibbons at oracle.com
Wed Jan 30 17:39:14 PST 2013
I've been investigating why javadoc is not generating type annotations
in its output, and as part of that, I've been investigating types within
javac, with an eye to viewing which should be annotated types. I think
this will also be of interest as we work on supporting javax.lang.model
for type annotations.
I've attached a patch (which I hope stays attached) for a demo and
potential proto-test for looking at these types.
The test code is the following simple program, in which DAnno is a
delcartion annotation, and TAnno is a type annotation.
public class Test {
@DAnno @TAnno int mAnnotatedReturn() { return 0; }
void mAnnotatedIntParam(@DAnno @TAnno int a) { }
void mAnnotatedIntArrayParam(@DAnno int @TAnno [] a) { }
void mAnnotatedThrows() throws @TAnno Exception { }
}
I've then created and run an annotation processor over the code, to look
at the internal types at the time of annotation processing -- which is
of interest to javax.lang.model users, and is effectively the same time
that javadoc needs the info.
For the declarations within the test classes, I print out the symbol,
and the types of the various parts within the symbol, where I expect to
see some representation of an annotated type. The output is generated
with the new DPrinter utility API, and is also attached.
Here's the summary:
-- mAnnotatedReturn: type annotations are within the symbol, but the
return type is not annotated.
-- mAnnotatedIntParam: type annotations are within the symbol but the
parameter type is not annotated. The same TypeCompund seems to end up on
both the VarSymbol for the paramater and the MethodSymbol. The decl
annotation just ends up on the declaration, which is more what I would
expect.
-- mAnnotatedIntArrayParam: type annotation seems very confused on this
one, showing up in 3 places. The debug output is not (yet) detailed
enough to identify which of these are ==.
The type of the param looks correct on this one.
-- mAnnotatedThrows: this actually looks as I would expect, although the
debug output is a little confusing w.r.t. the display of an annotated
type, since AnnotatedType shows the tag of the underlying type.
-- Jon
-------------- next part --------------
A non-text attachment was scrubbed...
Name: demo.patch
Type: text/x-patch
Size: 8574 bytes
Desc: not available
Url : http://mail.openjdk.java.net/pipermail/type-annotations-dev/attachments/20130130/949bc37d/demo.patch
-------------- next part --------------
Element Test()
symbol: 0x10--CONSTRUCTOR CONSTRUCTOR <init> #1f846cd
src: public <init>() { super(); }
flags: 0x1000000001--public
completer: #null
owner: Test
type: ()void
erasure: #null
params: [0]
savedParameterNames: #null
annotations:
attributes: [0]
type_attributes: [0]
returns: VOID #4e6138
tsym: void
constValue: #null
impl: com.sun.tools.javac.code.Type$JCNoType
Element mAnnotatedReturn()
symbol: 0x10--METHOD METHOD mAnnotatedReturn #1d0c37d
src: @DAnno() @TAnno() [...]turn 0; }
flags: 0x0--
completer: #null
owner: Test
type: ()int
erasure: #null
params: [0]
savedParameterNames: #null
annotations:
attributes: [1]
0: Compound
synthesized: false
values: [0]
type: DAnno
type_attributes: [1]
0: TypeCompound
position: [METHOD_RETURN, pos = 1090]
synthesized: false
values: [0]
type: TAnno
returns: INT #fa1f2f
tsym: int
constValue: #null
Element mAnnotatedIntParam(int)
symbol: 0x10--METHOD METHOD mAnnotatedIntParam #1157866
src: void mAnnotatedInt[...]nt a) { }
flags: 0x0--
completer: #null
owner: Test
type: (int)void
erasure: #null
params: [1]
0: 0x4--VAR PARAMETER a #9393f9
flags: 0x200000000--parameter
completer: #null
owner: mAnnotatedIntParam(int)
type: int
erasure: #null
pos: 1173
adm: -1
data: #null
annotations:
attributes: [1]
0: Compound
synthesized: false
values: [0]
type: DAnno
type_attributes: [1]
0: TypeCompound
position: [METHOD_FORMAL_PARAMETER, param_index = 0, pos = 1169]
synthesized: false
values: [0]
type: TAnno
savedParameterNames: #null
annotations:
attributes: [0]
type_attributes: [1]
0: TypeCompound
position: [METHOD_FORMAL_PARAMETER, param_index = 0, pos = 1169]
synthesized: false
values: [0]
type: TAnno
param 1: INT #fa1f2f
tsym: int
constValue: #null
returns: VOID #4e6138
tsym: void
constValue: #null
impl: com.sun.tools.javac.code.Type$JCNoType
Element mAnnotatedIntArrayParam((@TAnno :: int[]))
symbol: 0x10--METHOD METHOD mAnnotatedIntArrayParam #134d2bf
src: void mAnnotatedInt[...][] a) { }
flags: 0x0--
completer: #null
owner: Test
type: ((@TAnno :: int[]))void
erasure: #null
params: [1]
0: 0x4--VAR PARAMETER a #f7fa37
flags: 0x200000000--parameter
completer: #null
owner: mAnnotatedIntArrayParam((@TAnno :: int[]))
type: (@TAnno :: int[])
erasure: #null
pos: 1234
adm: -1
data: #null
annotations:
attributes: [1]
0: Compound
synthesized: false
values: [0]
type: DAnno
type_attributes: [1]
0: TypeCompound
position: [UNKNOWN, position UNKNOWN!, pos = -1]
synthesized: false
values: [0]
type: TAnno
savedParameterNames: #null
annotations:
attributes: [0]
type_attributes: [2]
0: TypeCompound
position: [METHOD_FORMAL_PARAMETER, param_index = 0, pos = 1234]
synthesized: false
values: [0]
type: TAnno
1: TypeCompound
position: [UNKNOWN, position UNKNOWN!, pos = -1]
synthesized: false
values: [0]
type: TAnno
param 1: ARRAY #4c4b05
tsym: Array
constValue: #null
typeAnnotations: [1]
0: TypeCompound
position: [METHOD_FORMAL_PARAMETER, param_index = 0, pos = 1234]
synthesized: false
values: [0]
type: TAnno
underlyingType: ARRAY #fa206f
tsym: Array
constValue: #null
elemType: INT #fa1f2f
tsym: int
constValue: #null
returns: VOID #4e6138
tsym: void
constValue: #null
impl: com.sun.tools.javac.code.Type$JCNoType
Element mAnnotatedThrows()
symbol: 0x10--METHOD METHOD mAnnotatedThrows #d1511c
src: void mAnnotatedThr[...]ption { }
flags: 0x0--
completer: #null
owner: Test
type: ()void
erasure: #null
params: [0]
savedParameterNames: #null
annotations:
attributes: [0]
type_attributes: [1]
0: TypeCompound
position: [THROWS, type_index = 0, pos = 1250]
synthesized: false
values: [0]
type: TAnno
returns: VOID #4e6138
tsym: void
constValue: #null
impl: com.sun.tools.javac.code.Type$JCNoType
throws: CLASS #242ba3
tsym: java.lang.Exception
constValue: #null
typeAnnotations: [1]
0: TypeCompound
position: [THROWS, type_index = 0, pos = 1250]
synthesized: false
values: [0]
type: TAnno
underlyingType: CLASS #ad15e6
tsym: java.lang.Exception
constValue: #null
outer: <none>
typarams: [0]
allparams: #null
supertype: java.lang.Throwable
interfaces: [0]
allinterfaces: #null
More information about the type-annotations-dev
mailing list