简体   繁体   中英

How to define Eclipse external null annotations for parameters in JRE methods

I am trying to annotate the JRE method <T> T[] toArray(T[] a) from java.util.Set using Eclipse's external null annotations . The expected effect should be equivalent to this:

 public interface Set<E> extends Collection<E> {
     ...
     <T> T @NonNull[] toArray(T @NonNull[] a);
     ...
 }

When using Eclipse's Annotate command I can annotate the return type of the method properly (after I selected the T[] and position the cursor before the [ ). However trying to do the same with the parameter fails. Pressing Cmd-1 simply beeps, as does selecting "Annotate" when calling the command from the context menu.

I finally ended up editing the corresponding Set.eea file manually to defined the required annotation, taking care of the proper eea file layout . Ie I changed the annotatedSignature in:

class java/util/Set
toArray
 <T:Ljava/lang/Object;>([TT;)[TT;
 <T:Ljava/lang/Object;>([TT;)[1TT;

to

 <T:Ljava/lang/Object;>([1TT;)[1TT;

This works fine and the annotation is correctly processed by the compiler.

As I can annotate the return type but not a parameter type I am wondering what I am doing wrong. Or is this a limitation of the current Eclipse version?

I am using Eclipse Mars Release (4.5.0, Build id: 20150621-1200) and jdk1.8.0_60.

This is a bug indeed, I just filed https://bugs.eclipse.org/477461 to track this.

This was bug 464081 which got fixed for 4.6 M1 (ie, is available in current builds towards Eclipse Neon) and is currently proposed for 4.5.2 (Mars.2)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM