diff options
| author | ssankaran | 2013-09-21 08:38:40 +0000 |
|---|---|---|
| committer | ssankaran | 2013-09-21 08:39:27 +0000 |
| commit | af8e4657dabc36f9f429517d3e6a26c71037fd72 (patch) | |
| tree | 12e3d104907988b4fee7689cbfc8cbbfd87c5bde | |
| parent | a419574dd82f4f874fda50161133fcff8afd89ba (diff) | |
| download | eclipse.jdt.core-af8e4657dabc36f9f429517d3e6a26c71037fd72.tar.gz eclipse.jdt.core-af8e4657dabc36f9f429517d3e6a26c71037fd72.tar.xz eclipse.jdt.core-af8e4657dabc36f9f429517d3e6a26c71037fd72.zip | |
Fixed Bug 417660 - [1.8][compiler] Incorrect parsing of Annotations
with array dimensions in arguments
Signed-off-by: ssankaran <srikanth_sankaran@in.ibm.com>
2 files changed, 60 insertions, 0 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TypeAnnotationTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TypeAnnotationTest.java index dd1403aba2..44068758a6 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TypeAnnotationTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TypeAnnotationTest.java @@ -5512,5 +5512,61 @@ public class TypeAnnotationTest extends AbstractRegressionTest { "Missing cannot be resolved to a type\n" + "----------\n"); } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=417660, [1.8][compiler] Incorrect parsing of Annotations with array dimensions in arguments + public void test417660() { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.Documented;\n" + + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.RetentionPolicy;\n" + + "import java.lang.annotation.Target;\n" + + "public class X {\n" + + " int bar(int [] @TakeType(int[].class)[] x) { \n" + + " return x[0][0]; \n" + + " } \n" + + " public static void main(String[] args) {\n" + + " System.out.println(new X().bar(new int [][] { { 1234 }}));\n" + + " }\n" + + "}\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@Documented\n" + + "@interface TakeType {\n" + + " Class value() default int[].class;\n" + + "}\n" + }, + "1234"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=417660, [1.8][compiler] Incorrect parsing of Annotations with array dimensions in arguments + public void test417660b() { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.Documented;\n" + + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.RetentionPolicy;\n" + + "import java.lang.annotation.Target;\n" + + "public class X {\n" + + " int bar(int [][] @TakeType(int[].class)[][] x @TakeType(int[].class)[]) { \n" + + " return x[0][0][0][0][0]; \n" + + " } \n" + + " public static void main(String[] args) {\n" + + " System.out.println(new X().bar(new int [][][][][] { { { { { 1234 } } } } }));\n" + + " }\n" + + "}\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@Documented\n" + + "@interface TakeType {\n" + + " Class value() default int[].class;\n" + + "}\n" + }, + "1234"); + } } diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java index 4796584fe8..2947079e35 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java @@ -5390,6 +5390,7 @@ protected void consumeTypeAnnotation() { Annotation annotation = this.typeAnnotationStack[this.typeAnnotationPtr]; problemReporter().invalidUsageOfTypeAnnotations(annotation); } + this.dimensions = this.intStack[this.intPtr--]; // https://bugs.eclipse.org/bugs/show_bug.cgi?id=417660 } protected void consumeOneMoreTypeAnnotation() { // TypeAnnotations ::= TypeAnnotations TypeAnnotation @@ -8977,6 +8978,9 @@ protected void consumeToken(int type) { this.lParenPos = this.scanner.startPosition; break; case TokenNameAT308: + pushOnIntStack(this.dimensions); // https://bugs.eclipse.org/bugs/show_bug.cgi?id=417660: Stack the dimensions, they get unstacked in consumeTypeAnnotation. + this.dimensions = 0; + //$FALL-THROUGH$ case TokenNameAT : pushOnIntStack(this.scanner.startPosition); break; |
