3

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. I.e. 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.

4

1 回答 1

2

这确实是一个错误,我刚刚提交了https://bugs.eclipse.org/477461来跟踪它。

这是在 4.6 M1 中修复的错误 464081(即,在当前面向 Eclipse Neon 的版本中可用),目前建议用于 4.5.2(Mars.2)

于 2015-09-15T14:56:05.227 回答