Type annotations in static initializers
Werner Dietl
wdietl at gmail.com
Mon Feb 18 17:23:11 PST 2013
Jon, all,
I just noticed that type annotations in a static initializer block are
not stored in bytecode.
Take this example:
class Test {
static {
Object o = new @TA Object();
}
}
Attr.visitBlock correctly attributes the annotation and in the end
localEnv.info.scope.owner contains the @TA annotation.
The owner.toString() gives "Test" and is of kind STATIC_INIT.
However, in com.sun.tools.javac.jvm.ClassWriter.writeMethod(MethodSymbol)
I later see a MethodSymbol for "<clinit>()" of kind STATIC_INIT.
This symbol no longer contains the type annotations and therefore
nothing gets written to bytecode.
Can somebody point me to the place where the MethodSymbol from Attr is
re-written into the MethodSymbol that ends up in the ClassWriter?
I spent some time looking through the code but didn't find this.
Maybe type annotations should be copied over whenever one symbol is
re-written into another one?
Thanks for any hints!
cu, WMD.
--
http://www.google.com/profiles/wdietl
More information about the type-annotations-dev
mailing list