Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Herrmann2015-07-11 21:27:43 +0000
committerStephan Herrmann2015-07-12 12:06:27 +0000
commit977e8ed039bc5fdb82d37a11a403feebdf8e113c (patch)
treeb97c8c0e1ee6506eec3863f0517a47fdbc4cca72
parentb7270c3ed9751063a7847ef78467ed5c4c4a29fb (diff)
downloadeclipse.jdt.core-977e8ed039bc5fdb82d37a11a403feebdf8e113c.tar.gz
eclipse.jdt.core-977e8ed039bc5fdb82d37a11a403feebdf8e113c.tar.xz
eclipse.jdt.core-977e8ed039bc5fdb82d37a11a403feebdf8e113c.zip
Bug 471611 - Error on hover on call to generic method with null
annotation Change-Id: Ie1826671f2b502957abe6cb7a54b859ef3e47114 Signed-off-by: Stephan Herrmann <stephan.herrmann@berlin.de>
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTModelBridgeTests.java42
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java3
2 files changed, 44 insertions, 1 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTModelBridgeTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTModelBridgeTests.java
index 99ea9a86a5..5f326400e3 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTModelBridgeTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTModelBridgeTests.java
@@ -505,6 +505,48 @@ public class ASTModelBridgeTests extends AbstractASTTests {
element
);
}
+
+ /*
+ * Ensures that the correct IBindings can be retrieved from an AST
+ * (parameter annotation)
+ */
+ public void testAnnotation15() throws Exception {
+ createFolder("/P/src/lib");
+ createFile("/P/src/lib/NonNull.java",
+ "package lib;\n" +
+ "import java.lang.annotation.*;\n" +
+ "@Target(ElementType.PARAMETER)\n" +
+ "public @interface NonNull{}\n");
+ createFile("/P/src/lib/Foo.java",
+ "package lib;\n" +
+ "public class Foo {\n" +
+ " public <T> void bug1(@NonNull T x) { return; }\n" +
+ " public static <T> void bug2(@NonNull String x) { return; }\n" +
+ "}\n");
+
+ String barSource =
+ "import lib.Foo;\n" +
+ "public class Bar {\n" +
+ " void m() { new Foo().bug1(\"x\"); Foo.bug2(\"x\"); }\n" +
+ "}\n";
+ this.workingCopies = new ICompilationUnit[2];
+ this.workingCopies[1] = getWorkingCopy("/P/src/Bar.java", barSource, this.wcOwner);
+
+ ASTParser parser = ASTParser.newParser(AST.JLS8);
+ parser.setProject(getJavaProject("P"));
+ parser.setSource(this.workingCopies[1]);
+ parser.setResolveBindings(true);
+ ASTNode send = NodeFinder.perform(parser.createAST(null), barSource.indexOf("bug1"), 0).getParent();
+ IBinding[] bindings = new IBinding[] { ((MethodInvocation) send).resolveMethodBinding() };
+ assertBindingsEqual(
+ "Llib/Foo;.bug1<T:Ljava/lang/Object;>(TT;)V%<Ljava/lang/String;>",
+ bindings);
+ IMethodBinding method = (IMethodBinding) bindings[0];
+ assertBindingsEqual(
+ "@Llib/NonNull;",
+ method.getParameterAnnotations(0));
+ }
+
/*
* Ensures that the IJavaElement of an IBinding representing an anonymous type is correct.
*/
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java
index dee8e47212..db267d771b 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java
@@ -26,6 +26,7 @@
* Bug 435805 - [1.8][compiler][null] Java 8 compiler does not recognize declaration style null annotations
* Bug 466713 - Null Annotations: NullPointerException using <int @Nullable []> as Type Param
* Bug 456584 - [1.8][null] Bogus warning for return type variable's @NonNull annotation being 'redundant'
+ * Bug 471611 - Error on hover on call to generic method with null annotation
* Jesper Steen Moller - Contributions for
* Bug 412150 [1.8] [compiler] Enable reflected parameter names during annotation processing
*******************************************************************************/
@@ -695,7 +696,7 @@ public AnnotationBinding[][] getParameterAnnotations() {
if (this.declaringClass instanceof SourceTypeBinding) {
SourceTypeBinding sourceType = (SourceTypeBinding) this.declaringClass;
if (sourceType.scope != null) {
- AbstractMethodDeclaration methodDecl = sourceType.scope.referenceType().declarationOf(this);
+ AbstractMethodDeclaration methodDecl = sourceType.scope.referenceType().declarationOf(originalMethod);
for (int i = 0; i < length; i++) {
Argument argument = methodDecl.arguments[i];
if (argument.annotations != null) {

Back to the top