Bug 420045 - Start reporting annotations on dimensions of a class
literal expression
Change-Id: I41852fefcd0d4ce2f837da64c819f3fc611fa388
Signed-off-by: Jay Arthanareeswaran <jarthana@in.ibm.com>
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 8085d74..ec0b940 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 @@
"----------\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 8429788..fa34bd7 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 @@
" ^^^^^\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 @@
" ^^^^^\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 4910611..df35ae6 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 @@
"@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 @@
"}\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 8fe5cec..70e34ab 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 4df2cf5..ed032b3 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 @@
}
}
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 @@
}
}
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 @@
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 4046259..f8dc8b5 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 @@
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,