diff options
author | Jay Arthanareeswaran | 2017-08-16 23:03:03 +0000 |
---|---|---|
committer | Jay Arthanareeswaran | 2017-08-16 23:04:18 +0000 |
commit | 6c24ddae93764d9d6cb3f81654b051a09e2227e9 (patch) | |
tree | 944391c1eda647e3219533f2a5e92e28c3d009cf | |
parent | 40575084a51619788a032ee4ee3698c47358575b (diff) | |
download | eclipse.jdt.core-6c24ddae93764d9d6cb3f81654b051a09e2227e9.tar.gz eclipse.jdt.core-6c24ddae93764d9d6cb3f81654b051a09e2227e9.tar.xz eclipse.jdt.core-6c24ddae93764d9d6cb3f81654b051a09e2227e9.zip |
Bug 420045 - Start reporting annotations on dimensions of a classI20170818-0100I20170818-0040I20170817-2140I20170817-2000
literal expression
Change-Id: I41852fefcd0d4ce2f837da64c819f3fc611fa388
Signed-off-by: Jay Arthanareeswaran <jarthana@in.ibm.com>
6 files changed, 43 insertions, 97 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GrammarCoverageTests308.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GrammarCoverageTests308.java index 8085d745b4..ec0b940e40 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GrammarCoverageTests308.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GrammarCoverageTests308.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2014 IBM Corporation and others. + * Copyright (c) 2011, 2017 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 @@ -615,28 +615,13 @@ public class GrammarCoverageTests308 extends AbstractRegressionTest { "----------\n" + "3. ERROR in X.java (at line 4)\n" + " Object o2 = @Marker int @Marker[] [] @Marker[].class;\n" + - " ^^^^^^\n" + - "Marker cannot be resolved to a type\n" + - "----------\n" + - "4. WARNING in X.java (at line 4)\n" + - " Object o2 = @Marker int @Marker[] [] @Marker[].class;\n" + " ^^^^^^^\n" + "Syntax error, type annotations are illegal here\n" + "----------\n" + - "5. ERROR in X.java (at line 4)\n" + - " Object o2 = @Marker int @Marker[] [] @Marker[].class;\n" + - " ^^^^^^\n" + - "Marker cannot be resolved to a type\n" + - "----------\n" + - "6. WARNING in X.java (at line 4)\n" + + "4. ERROR in X.java (at line 4)\n" + " Object o2 = @Marker int @Marker[] [] @Marker[].class;\n" + " ^^^^^^^\n" + "Syntax error, type annotations are illegal here\n" + - "----------\n" + - "7. ERROR in X.java (at line 4)\n" + - " Object o2 = @Marker int @Marker[] [] @Marker[].class;\n" + - " ^^^^^^\n" + - "Marker cannot be resolved to a type\n" + "----------\n"); } // ReferenceExpression ::= PrimitiveType Dims '::' NonWildTypeArgumentsopt IdentifierOrNew diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JSR308SpecSnippetTests.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JSR308SpecSnippetTests.java index 84297888f5..fa34bd765f 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JSR308SpecSnippetTests.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JSR308SpecSnippetTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2014 IBM Corporation and others. + * Copyright (c) 2011, 2017 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 @@ -985,7 +985,7 @@ public class JSR308SpecSnippetTests extends AbstractRegressionTest { " ^^^^^\n" + "Syntax error, type annotations are illegal here\n" + "----------\n" + - "5. WARNING in X.java (at line 20)\n" + + "5. ERROR in X.java (at line 20)\n" + " o = int @NonEmpty [].class; // illegal!\n" + " ^^^^^^^^^\n" + "Syntax error, type annotations are illegal here\n" + @@ -1061,7 +1061,7 @@ public class JSR308SpecSnippetTests extends AbstractRegressionTest { " ^^^^^\n" + "Syntax error, type annotations are illegal here\n" + "----------\n" + - "5. WARNING in X.java (at line 27)\n" + + "5. ERROR in X.java (at line 27)\n" + " o = int @NonEmpty [].class; // illegal!\n" + " ^^^^^^^^^\n" + "Syntax error, type annotations are illegal here\n" + diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NegativeTypeAnnotationTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NegativeTypeAnnotationTest.java index 4910611a9e..df35ae633a 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NegativeTypeAnnotationTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NegativeTypeAnnotationTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2014 IBM Corporation and others. + * Copyright (c) 2011, 2017 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 @@ -849,57 +849,37 @@ public class NegativeTypeAnnotationTest extends AbstractRegressionTest { "@interface NonEmpty {\n" + "}\n", }, - "----------\n" + - "1. WARNING in X.java (at line 3)\n" + - " System.out.println(int @NonEmpty [] [] @NonEmpty @Empty [] [] @NonEmpty[].class); // illegal!\n" + - " ^^^^^^^^^\n" + - "Syntax error, type annotations are illegal here\n" + - "----------\n" + - "2. ERROR in X.java (at line 3)\n" + - " System.out.println(int @NonEmpty [] [] @NonEmpty @Empty [] [] @NonEmpty[].class); // illegal!\n" + - " ^^^^^^^^^\n" + - "Annotation types that do not specify explicit target element types cannot be applied here\n" + - "----------\n" + - "3. WARNING in X.java (at line 3)\n" + - " System.out.println(int @NonEmpty [] [] @NonEmpty @Empty [] [] @NonEmpty[].class); // illegal!\n" + - " ^^^^^^^^^^^^^^^^\n" + - "Syntax error, type annotations are illegal here\n" + - "----------\n" + - "4. ERROR in X.java (at line 3)\n" + - " System.out.println(int @NonEmpty [] [] @NonEmpty @Empty [] [] @NonEmpty[].class); // illegal!\n" + - " ^^^^^^^^^\n" + - "Annotation types that do not specify explicit target element types cannot be applied here\n" + - "----------\n" + - "5. ERROR in X.java (at line 3)\n" + - " System.out.println(int @NonEmpty [] [] @NonEmpty @Empty [] [] @NonEmpty[].class); // illegal!\n" + - " ^^^^^^\n" + - "Annotation types that do not specify explicit target element types cannot be applied here\n" + - "----------\n" + - "6. WARNING in X.java (at line 3)\n" + - " System.out.println(int @NonEmpty [] [] @NonEmpty @Empty [] [] @NonEmpty[].class); // illegal!\n" + - " ^^^^^^^^^\n" + - "Syntax error, type annotations are illegal here\n" + - "----------\n" + - "7. ERROR in X.java (at line 3)\n" + - " System.out.println(int @NonEmpty [] [] @NonEmpty @Empty [] [] @NonEmpty[].class); // illegal!\n" + - " ^^^^^^^^^\n" + - "Annotation types that do not specify explicit target element types cannot be applied here\n" + - "----------\n" + - "8. ERROR in X.java (at line 4)\n" + - " System.out.println(X @NonEmpty [] [] @NonEmpty @Empty [] [] @NonEmpty[].class); // illegal!\n" + - " ^^^^^^^^^\n" + - "Syntax error, type annotations are illegal here\n" + - "----------\n" + - "9. ERROR in X.java (at line 4)\n" + - " System.out.println(X @NonEmpty [] [] @NonEmpty @Empty [] [] @NonEmpty[].class); // illegal!\n" + - " ^^^^^^^^^^^^^^^^\n" + - "Syntax error, type annotations are illegal here\n" + - "----------\n" + - "10. ERROR in X.java (at line 4)\n" + - " System.out.println(X @NonEmpty [] [] @NonEmpty @Empty [] [] @NonEmpty[].class); // illegal!\n" + - " ^^^^^^^^^\n" + - "Syntax error, type annotations are illegal here\n" + - "----------\n"); + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " System.out.println(int @NonEmpty [] [] @NonEmpty @Empty [] [] @NonEmpty[].class); // illegal!\n" + + " ^^^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " System.out.println(int @NonEmpty [] [] @NonEmpty @Empty [] [] @NonEmpty[].class); // illegal!\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " System.out.println(int @NonEmpty [] [] @NonEmpty @Empty [] [] @NonEmpty[].class); // illegal!\n" + + " ^^^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "4. ERROR in X.java (at line 4)\n" + + " System.out.println(X @NonEmpty [] [] @NonEmpty @Empty [] [] @NonEmpty[].class); // illegal!\n" + + " ^^^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "5. ERROR in X.java (at line 4)\n" + + " System.out.println(X @NonEmpty [] [] @NonEmpty @Empty [] [] @NonEmpty[].class); // illegal!\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "6. ERROR in X.java (at line 4)\n" + + " System.out.println(X @NonEmpty [] [] @NonEmpty @Empty [] [] @NonEmpty[].class); // illegal!\n" + + " ^^^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n"); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383950 // [1.8][compiler] Type annotations must have target type meta annotation TYPE_USE @@ -4196,7 +4176,7 @@ public class NegativeTypeAnnotationTest extends AbstractRegressionTest { "}\n" }, "----------\n" + - "1. WARNING in X.java (at line 8)\n" + + "1. ERROR in X.java (at line 8)\n" + " Class<?> c = int @T [].class; \n" + " ^^\n" + "Syntax error, type annotations are illegal here\n" + diff --git a/org.eclipse.jdt.core.tests.model/workspace/FormatterJSR308/test014/X_out.java b/org.eclipse.jdt.core.tests.model/workspace/FormatterJSR308/test014/X_out.java index 8fe5cec72b..70e34ab60e 100644 --- a/org.eclipse.jdt.core.tests.model/workspace/FormatterJSR308/test014/X_out.java +++ b/org.eclipse.jdt.core.tests.model/workspace/FormatterJSR308/test014/X_out.java @@ -1,6 +1,6 @@ public class X { public void value() { Object o = @Marker int.class; - Object o2 = @Marker int @Marker [][] @Marker [].class; + Object o2 = @Marker int @Marker[][]@Marker[].class; } } 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 4df2cf5758..ed032b3164 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 @@ -5762,9 +5762,6 @@ protected void rejectIllegalLeadingTypeAnnotations(TypeReference typeReference) } } private void rejectIllegalTypeAnnotations(TypeReference typeReference) { - rejectIllegalTypeAnnotations(typeReference, false); -} -private void rejectIllegalTypeAnnotations(TypeReference typeReference, boolean tolerateAnnotationsOnDimensions) { // Reject misplaced annotations on type reference; Used when grammar is permissive enough to allow them in the first place. Annotation [][] annotations = typeReference.annotations; Annotation[] misplacedAnnotations; @@ -5775,23 +5772,15 @@ private void rejectIllegalTypeAnnotations(TypeReference typeReference, boolean t } } annotations = typeReference.getAnnotationsOnDimensions(true); - boolean tolerated = false; for (int i = 0, length = annotations == null ? 0 : annotations.length; i < length; i++) { misplacedAnnotations = annotations[i]; if (misplacedAnnotations != null) { - if (tolerateAnnotationsOnDimensions) { - problemReporter().toleratedMisplacedTypeAnnotations(misplacedAnnotations[0], misplacedAnnotations[misplacedAnnotations.length - 1]); - tolerated = true; - } - else problemReporter().misplacedTypeAnnotations(misplacedAnnotations[0], misplacedAnnotations[misplacedAnnotations.length - 1]); } } - if (!tolerated) { - typeReference.annotations = null; - typeReference.setAnnotationsOnDimensions(null); - typeReference.bits &= ~ASTNode.HasTypeAnnotations; - } +typeReference.annotations = null; +typeReference.setAnnotationsOnDimensions(null); +typeReference.bits &= ~ASTNode.HasTypeAnnotations; } protected void consumeQualifiedSuperReceiver() { // QualifiedSuperReceiver ::= Name '.' 'super' @@ -5827,7 +5816,7 @@ protected void consumePrimaryNoNewArrayPrimitiveArrayType() { ClassLiteralAccess cla; pushOnExpressionStack( cla = new ClassLiteralAccess(this.intStack[this.intPtr--], getTypeReference(this.intStack[this.intPtr--]))); - rejectIllegalTypeAnnotations(cla.type, true /* tolerate annotations on dimensions for bug compatibility for now */); + rejectIllegalTypeAnnotations(cla.type); } protected void consumePrimaryNoNewArrayPrimitiveType() { // PrimaryNoNewArray ::= PrimitiveType '.' 'class' diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java index 4046259fcc..f8dc8b5b77 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java @@ -4726,14 +4726,6 @@ public void invalidUsageOfTypeAnnotations(Annotation annotation) { annotation.sourceStart, annotation.sourceEnd); } -public void toleratedMisplacedTypeAnnotations(Annotation first, Annotation last) { - this.handle( - IProblem.ToleratedMisplacedTypeAnnotations, - NoArgument, - NoArgument, - first.sourceStart, - last.sourceEnd); -} public void misplacedTypeAnnotations(Annotation first, Annotation last) { this.handle( IProblem.MisplacedTypeAnnotations, |