Bug 212834 - [dom] IMethodBinding.getParameterAnnotations does not return annotations
Summary: [dom] IMethodBinding.getParameterAnnotations does not return annotations
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.4 M5   Edit
Assignee: Frederic Fusier CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-12-12 20:50 EST by Kevin CLA
Modified: 2008-02-05 05:19 EST (History)
2 users (show)

See Also:


Attachments
Proposed patch (12.69 KB, patch)
2007-12-19 10:56 EST, Frederic Fusier CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Kevin CLA 2007-12-12 20:50:14 EST
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 { }
Comment 1 Kevin CLA 2007-12-12 20:54:23 EST
This bug report refers to org.eclipse.jdt.core.dom.IMethodBinding.
Comment 2 Frederic Fusier CLA 2007-12-19 10:56:08 EST
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).
Comment 3 Frederic Fusier CLA 2007-12-19 11:59:06 EST
Released for 3.4M4 in HEAD stream.
Comment 4 David Audel CLA 2008-02-05 05:19:02 EST
Verified for 3.4M5 using build I20080204-0010.