Question on remapping type annotations when casts are discarded by the compiler

18 views
Skip to first unread message

Andrew Clement

unread,
Jun 4, 2013, 2:25:55 PM6/4/13
to jsr308-...@googlegroups.com
Hi,

I'm in one of the corners of the JSR308 spec, Section 3.3.10:

===

If the compiler eliminates an annotated cast, it is required to retain the annotations on the cast in the class file (if the annotation type has at least RetentionPolicy.CLASS retention). When a cast is removed, the compiler may need to adjust (the locations of) the annotations, to account for the relationship between the expression’s type and the casted-to type. Consider:

  class C<S, T> { ... }
  class D<A, B> extends C<B, A> { ... }
  ...
  ... (C<@A1 X, @A2 Y>) myD ...

The compiler may leave out the upcast, but in that case it must record that @A1 is attached to the second type argument of D, even though it was originally attached to the first type argument of C.

===

I have this (hopefully sane?) testcase:

class C<X,Y,Z> {}

class D<A,B> extends C<B,String,A> {}

D<Integer,Float> d = new D<Integer,Float>();

C<Float,String,Integer> o2 = (C<@Anno1 Float,@Anno2 String, @Anno3 Integer>) d;

If the cast were not discarded, the type anno attributes would look like a bit like:

@Anno1 TYPE_ARGUMENT(0)
@Anno2 TYPE_ARGUMENT(1)
@Anno3 TYPE_ARGUMENT(2)

But the cast is discarded so I need to remap the annotation positions based on the spec section above, mapping them to where they exist on D.

@Anno1 becomes TYPE_ARGUMENT(1)
@Anno3 becomes TYPE_ARGUMENT(0)

What happens to @Anno2?

thanks
Andy

Andrew Clement

unread,
Jun 11, 2013, 5:31:52 PM6/11/13
to jsr308-...@googlegroups.com
Just want to check I've posted this query on the right discussion list? Should I post somewhere else?

thanks,
Andy

Werner Dietl

unread,
Jun 11, 2013, 9:26:54 PM6/11/13
to jsr308-...@googlegroups.com
Hi Andy,

If you're interested in the JSR 308 reference implementation, the
right mailing list is:

http://mail.openjdk.java.net/pipermail/type-annotations-dev/

Comments about the spec should go to:

http://mail.openjdk.java.net/pipermail/type-annotations-spec-comments/

jsr308-discuss is for jsr308-langtools, which is an extension of the
official JSR 308 RI.

I'm not sure whether your question is about the spec or the RI; please
repost accordingly.

(See my previous message:
https://groups.google.com/d/msg/jsr308-discuss/3Yphjqw587o/GmLKjactPVUJ
)

Cheers,
cu, WMD.
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "Type annotations (JSR 308) discussions" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to jsr308-discus...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>



--
http://www.google.com/profiles/wdietl
Reply all
Reply to author
Forward
0 new messages