Community
Participate
Working Groups
Calling getParameterAnnotations on a IMethodBinding object from a MethodCall node *outside* the compilation unit where the called method is defined returns an empty annotation array even when annotations are defined for the parameter with the given index. Conversely, if the MethodCall occurs in the same compilation unit as the called method, or the IMethodBinding was retrieved from a MethodDeclaration AST node, then getParameterAnnotations returns annotations where they are defined. In the following example, calling "resolveMethodBinding().getParameterAnnotations(0)" on an AST node for "D.bar(7)" will return a 0-element array. It should return a 1-element array with an IAnnotationBinding for @Baz. (Notice that D.bar(int) is defined in a different compilation unit than where it is called.) Conversely: Calling "resolveMethodBinding().getParameterAnnotations(0)" on an AST node for "C.foo(5)" will yield a 1-element array with a IAnnotationBinding for @Baz. <<comp-unit C.java>> public class C { public C() { C.foo(5); D.bar(7); } @Baz public void foo(@Baz int x) { ... } } <<comp-unit D.java>> public class D { @Baz public void bar(@Baz int y) { ... } } <<comp-unit Baz.java>> public @Interface Baz { }
This bug report refers to org.eclipse.jdt.core.dom.IMethodBinding.
Created attachment 85570 [details] Proposed patch Compiler needs to be modified to resolve and store parameter annotations even if the method declaration was not parsed yet (thanks to Philippe for his implementation).
Released for 3.4M4 in HEAD stream.
Verified for 3.4M5 using build I20080204-0010.