Type Annotations for Inner class constructors

André Pankraz andre at pankraz.de
Fri Feb 7 01:02:02 PST 2014


Hi,

another question: May be I couldn't find the exact definition of "formal
parameter" for methods (I'm not a compiler / lang expert), but I observed
this:

If I have an Inner Class with a constructor, then artificial parameters are
generated to inject the outer class instance into the inner class and
remember the reference in attribute this$1 (for emulated outer access). In
javac such synthetic parameters are generated before the original Java
method parameters.

If I use type annotations in such constructor methods, then the formal
parameter index for TypeReference.METHOD_FORMAL_PARAMETER doesn't take such
generated parameters into account.

That means, if I have this:

    class Outer<W> {
        class Middle {
            class Inner extends
                    Outer<@Size(max = 21) String>. at Size(max = 22) Middle {

                @Nonnull
                private final Integer arg;

                public Inner(@Size(max = 23) Integer arg) {
                    this.arg = arg;
                }
    ....

and I "decompile" this without replacing synthetic parameters and fields, I
get this:

    class Outer<W> {
        final DecTestTypeAnnotations this$0;

        Outer(DecTestTypeAnnotations arg0) {
            this.this$0 = arg0;
        }

        class Middle {
            final Outer this$1;

            Middle(Outer arg0) {
                this.this$1 = arg0;
            }

            static Outer access$0(Middle arg0) {
                return arg0.this$1;
            }

            class Inner
                    extends
                    DecTestTypeAnnotations<U, V>.Outer<@Size(max = 21)
String>. at Size(max = 22) Middle {
                private final @Nonnull
                Integer arg;
                final Middle this$2;

                public Inner(@Size(max = 23) DecTestTypeAnnotations arg0,
                        Integer arg) {
                    this.this$2 = arg0;
                    super(Middle.access$0(arg0));
                    this.arg = arg;
                }
...



See how @Size(23) targets the synthetic parameter?

My question is, is this intentional?

Is a tool, that is interested in building a type model from the byteecode,
responsible to recognize synthetic parameters to map the annotation to the
right types?
Is yes, is this recognition allways unambigiously possible? Not for all
synthetic parameters are distinct rules enforced in the JVM spec, sometimes
it's more up to the implementor how to do it. Lock alone how differently
e.g. Eclipse and Java compile string-switches or concatanations - there are
differences. Or is this all already considered?

Cheers,
André
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/type-annotations-dev/attachments/20140207/f0576ee9/attachment.html 


More information about the type-annotations-dev mailing list