Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManoj Palat2013-04-26 15:03:08 +0000
committerJayaprakash Arthanareeswaran2013-04-26 15:03:08 +0000
commit377267c7b8a2a28bb5624532c958378e4aa9d9fb (patch)
treed32776bdafb2013ea6ab120ca310ffb95be7735d
parentd933dccfeeba25c2c3d8c1c59897e3604969c217 (diff)
downloadeclipse.jdt.core-377267c7b8a2a28bb5624532c958378e4aa9d9fb.tar.gz
eclipse.jdt.core-377267c7b8a2a28bb5624532c958378e4aa9d9fb.tar.xz
eclipse.jdt.core-377267c7b8a2a28bb5624532c958378e4aa9d9fb.zip
Fix for 406505 - [1.8][dom ast] Bad AST Node Error for Annotated
TypeParameter
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter18Test.java24
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java8
2 files changed, 30 insertions, 2 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 ce762bb632..4c57df278d 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
@@ -2357,4 +2357,28 @@ public class ASTConverter18Test extends ConverterTestSetup {
assertEquals("Incorrect no of annotations", 0, annotations.size());
assertEquals("Incorrect receiver", "J", castType.toString());
}
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=406505
+ * tests the source range issue that resulted in bad ast node.
+ *
+ * @throws JavaModelException
+ */
+ public void testBug406505() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter18/src/test406505/X.java",
+ true/* resolve */);
+ String contents = "package test406505;"
+ + "import java.lang.annotation.Target;\n"
+ + "import java.io.File;\n"
+ + "public class X {\n"
+ + " class Folder<@Marker F extends File> { }\n"
+ + "}\n"
+ + "@Target (java.lang.annotation.ElementType.TYPE_USE)\n"
+ + "@interface Marker {}\n";
+ CompilationUnit cu = (CompilationUnit) buildAST(contents, this.workingCopy);
+ TypeDeclaration typedeclaration = (TypeDeclaration) getASTNode(cu, 0);
+ typedeclaration = (TypeDeclaration)typedeclaration.bodyDeclarations().get(0);
+ TypeParameter typeParameter = (TypeParameter) typedeclaration.typeParameters().get(0);
+ checkSourceRange(typeParameter, "@Marker F extends File", contents);
+ }
+
}
diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java
index 151e91e4b6..2e48221b89 100644
--- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java
+++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java
@@ -2874,7 +2874,11 @@ class ASTConverter {
int end = typeParameter.sourceEnd;
simpleName.setSourceRange(start, end - start + 1);
typeParameter2.setName(simpleName);
- if (typeParameter.annotations != null) {
+ int annotationsStart = start;
+ org.eclipse.jdt.internal.compiler.ast.Annotation[] annotations = typeParameter.annotations;
+ if (annotations != null) {
+ if (annotations[0] != null)
+ annotationsStart = annotations[0].sourceStart;
annotateTypeParameter(typeParameter2, typeParameter.annotations);
}
final TypeReference superType = typeParameter.type;
@@ -2893,7 +2897,7 @@ class ASTConverter {
end = type.getStartPosition() + type.getLength() - 1;
}
}
- start = typeParameter.declarationSourceStart;
+ start = annotationsStart < typeParameter.declarationSourceStart ? annotationsStart : typeParameter.declarationSourceStart;
end = retrieveClosingAngleBracketPosition(end);
typeParameter2.setSourceRange(start, end - start + 1);
if (this.resolveBindings) {

Back to the top