[JSR308] bytecode representation of annotations
eu at javatx.org
Wed Jul 18 12:19:55 EDT 2007
I'd like bring bytecode representation of the JSR 308 annotations to
Current proposal is suggesting to use special target_type structure 
to specify location of the new annotations. That structure is quite
complicated and somehow mix annotations on methods/fields/classes
declaration with stuff that is located in the method code (new, cast,
instanceof, local vars).
I suggest to simplify representation of the first kind of annotations
(class, methods and fields). The idea is to use information from the
Signature attribute. It has all info about class types, its parameters,
generic types, exceptions, method parameters, basically everything. So,
we can use it to stick annotations to and when signature is omitted, we
can still reconstruct it from the class, method or field descriptor
assuming that there is no generic parameters used.
Just by looking trough signature value we can identify all slots (from
left to right) where annotation can be placed and then use single linear
index in the reference_info structure to specify such slot. This way
more variants of target_type could use same reference_info structure and
don't even need separate target_type. It should also simplify and make
more natural annotations on arrays. I think "location" element from the
"Generic Type Arguments or Arrays" is quite twisted and it will be much
easier to deal with it using suggested approach.
Alternatively we could introduce special AnnotatedSignature attribute
that would allow to explicitly mark annotation placeholders inside
signature value. For example (just to give an idea, using '&' marker):
@A Map<@B Foo<@C Object[@D][@E][@F]>, @G List<@H String>> foo;
would be represented by something like this:
then we can still use same linear array. Note that stripping '&' marker
would give us original signature value.
Any thoughts or opinions on this?
More information about the JSR308