Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJayaprakash Arthanareeswaran2014-01-23 05:51:09 +0000
committerJayaprakash Arthanareeswaran2014-01-23 08:57:26 +0000
commit68f185fc63132d7b106a1c7ca52ed6d004b96329 (patch)
treee271bc4aa5f94e327ef090a0d833cdc0a3999666
parent768144d4a3d41ee7bf9dfd2621b7a9e45eb26f3e (diff)
downloadeclipse.jdt.core-68f185fc63132d7b106a1c7ca52ed6d004b96329.tar.gz
eclipse.jdt.core-68f185fc63132d7b106a1c7ca52ed6d004b96329.tar.xz
eclipse.jdt.core-68f185fc63132d7b106a1c7ca52ed6d004b96329.zip
Bug 425741 - [1.8][dom ast] ITypeBinding#getTypeDeclaration() doesn't
strip off type annotations
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter18Test.java41
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ITypeBinding.java7
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/TypeBinding.java4
3 files changed, 48 insertions, 4 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter18Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter18Test.java
index 5a6595677e..49cff24536 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter18Test.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter18Test.java
@@ -3868,4 +3868,45 @@ public class ASTConverter18Test extends ConverterTestSetup {
checkSourceRange(arrayType.getElementType(), "Object", contents);
assertTrue(arrayType.getDimensions() == 3);
}
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=420458
+ */
+ public void testBug425741() throws JavaModelException {
+ String contents =
+ "@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
+ "@interface Annot { String value(); }\n" +
+ "@Annot(\"decl\") public class X {\n" +
+ " @Annot(\"field\") X x = null;\n" +
+ " public void foo(@Annot(\"param\") X i) {\n" +
+ " }\n" +
+ "}";
+ this.workingCopy = getWorkingCopy("/Converter18/src/test/X.java", true/*resolve*/);
+ ASTNode node = buildAST(contents, this.workingCopy, false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ node = getASTNode(compilationUnit, 1);
+ assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, node.getNodeType());
+ FieldDeclaration field = ((TypeDeclaration) node).getFields()[0];
+ List fragments = field.fragments();
+ ITypeBinding typeBinding = field.getType().resolveBinding();
+ IAnnotationBinding[] annots = typeBinding.getTypeAnnotations();
+ assertEquals("Incorrect type annotations", 1, annots.length);
+ assertEquals("Incorrect annotation", "@Annot(value = field)", annots[0].toString());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ typeBinding = typeBinding.getTypeDeclaration();
+ annots = typeBinding.getTypeAnnotations();
+ assertEquals("Incorrect type annotations", 0, annots.length);
+ typeBinding = fragment.resolveBinding().getType().getTypeDeclaration();
+ annots = typeBinding.getTypeAnnotations();
+ assertEquals("Incorrect type annotations", 0, annots.length);
+ MethodDeclaration method = ((TypeDeclaration) node).getMethods()[0];
+ SingleVariableDeclaration param = (SingleVariableDeclaration) method.parameters().get(0);
+ typeBinding = param.getType().resolveBinding();
+ annots = typeBinding.getTypeAnnotations();
+ assertEquals("Incorrect type annotations", 1, annots.length);
+ assertEquals("Incorrect annotation", "@Annot(value = param)", annots[0].toString());
+ typeBinding = typeBinding.getTypeDeclaration();
+ annots = typeBinding.getTypeAnnotations();
+ assertEquals("Incorrect type annotations", 0, annots.length);
+ }
}
diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ITypeBinding.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ITypeBinding.java
index 13c96f8aeb..704f18d596 100644
--- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ITypeBinding.java
+++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ITypeBinding.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2013 IBM Corporation and others.
+ * Copyright (c) 2000, 2014 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -561,7 +561,10 @@ public interface ITypeBinding extends IBinding {
* type.</p>
* <p>A different non-generic binding will be returned when one of the declaring
* types/methods was parameterized.</p>
- * <p>For other type bindings, this returns the same binding.</p>
+ * <p>For other type bindings, this returns the binding for the type declaration
+ * corresponding to this type binding. In particular, for type bindings that
+ * correspond to an annotated type use, this returns the binding for the type
+ * declaration which will not have the type annotations from the use site.</p>
*
* @return the type binding
* @since 3.1
diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/TypeBinding.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/TypeBinding.java
index 140d3e2407..e85b213eac 100644
--- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/TypeBinding.java
+++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/TypeBinding.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2013 IBM Corporation and others.
+ * Copyright (c) 2000, 2014 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -467,7 +467,7 @@ class TypeBinding implements ITypeBinding {
public ITypeBinding getTypeDeclaration() {
if (this.binding instanceof ParameterizedTypeBinding)
return this.resolver.getTypeBinding(((ParameterizedTypeBinding)this.binding).genericType());
- return this;
+ return this.resolver.getTypeBinding(this.binding.unannotated());
}
/* (non-Javadoc)

Back to the top