diff options
| author | Jesper S Moller | 2013-03-03 02:16:31 +0000 |
|---|---|---|
| committer | ssankaran | 2013-03-03 02:16:31 +0000 |
| commit | f6b16290d9141509dffddf2d9dc5a88115698e2a (patch) | |
| tree | eae65823e7428c75d3978529aa595d511d2c7f7a | |
| parent | ea1d73d076a4d2059d27cd885c8695d80d6d0cda (diff) | |
| download | eclipse.jdt.core-f6b16290d9141509dffddf2d9dc5a88115698e2a.tar.gz eclipse.jdt.core-f6b16290d9141509dffddf2d9dc5a88115698e2a.tar.xz eclipse.jdt.core-f6b16290d9141509dffddf2d9dc5a88115698e2a.zip | |
Fixed Bug 384567 - [1.5][compiler] Compiler accepts illegal modifiers on
package declaration
6 files changed, 70 insertions, 1 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java index 4536ac6552..410e446305 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java @@ -18,6 +18,8 @@ * bug 384663 - Package Based Annotation Compilation Error in JDT 3.8/4.2 (works in 3.7.2) * bug 386356 - Type mismatch error with annotations and generics * bug 331649 - [compiler][null] consider null annotations for fields + * Jesper S Moller - Contributions for + * bug 384567 - [1.5][compiler] Compiler accepts illegal modifiers on package declaration *******************************************************************************/ package org.eclipse.jdt.core.tests.compiler.regression; @@ -10804,4 +10806,45 @@ public void test398657_2() throws Exception { checkDisassembledClassFile(OUTPUT_DIR + File.separator +"X.class", "X", expectedOutput, ClassFileBytesDisassembler.DETAILED); } +// check invalid and annotations on package +public void test384567() { + this.runNegativeTest( + new String[] { + "xy/X.java", + "public final synchronized @Foo private package xy;\n" + + "class X {\n" + + "}\n" + + "\n" + + "@interface Foo {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in xy\\X.java (at line 1)\n" + + " public final synchronized @Foo private package xy;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Syntax error, modifiers are not allowed here\n" + + "----------\n" + + "2. ERROR in xy\\X.java (at line 1)\n" + + " public final synchronized @Foo private package xy;\n" + + " ^^^^\n" + + "Package annotations must be in file package-info.java\n" + + "----------\n"); +} +//check invalid modifiers on package +public void test384567_2() { + this.runNegativeTest( + new String[] { + "xy/X.java", + "public final synchronized private package xy;\n" + + "class X {\n" + + "}\n" + + "\n" + }, + "----------\n" + + "1. ERROR in xy\\X.java (at line 1)\n" + + " public final synchronized private package xy;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Syntax error, modifiers are not allowed here\n" + + "----------\n"); +} } diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java index d01bbfd739..42913490f9 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java @@ -30,6 +30,7 @@ * Jesper S Moller - Contributions for * bug 382701 - [1.8][compiler] Implement semantic analysis of Lambda expressions & Reference expression * bug 382721 - [1.8][compiler] Effectively final variables needs special treatment + * bug 384567 - [1.5][compiler] Compiler accepts illegal modifiers on package declaration *******************************************************************************/ package org.eclipse.jdt.core.tests.compiler.regression; @@ -545,6 +546,7 @@ public void test011_problem_categories() { expectedProblemAttributes.put("IllegalModifierForMethod", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); expectedProblemAttributes.put("IllegalModifierForVariable", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); expectedProblemAttributes.put("IllegalModifiersForElidedType", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("IllegalModifiersForPackage", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); expectedProblemAttributes.put("IllegalPrimitiveOrArrayTypeForEnclosingInstance", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); expectedProblemAttributes.put("IllegalQualifiedEnumConstantLabel", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); expectedProblemAttributes.put("IllegalQualifiedParameterizedTypeAllocation", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); @@ -1316,6 +1318,7 @@ public void test012_compiler_problems_tuning() { expectedProblemAttributes.put("IllegalModifierForMethod", SKIP); expectedProblemAttributes.put("IllegalModifierForVariable", SKIP); expectedProblemAttributes.put("IllegalModifiersForElidedType", SKIP); + expectedProblemAttributes.put("IllegalModifiersForPackage", SKIP); expectedProblemAttributes.put("IllegalPrimitiveOrArrayTypeForEnclosingInstance", SKIP); expectedProblemAttributes.put("IllegalQualifiedEnumConstantLabel", SKIP); expectedProblemAttributes.put("IllegalQualifiedParameterizedTypeAllocation", SKIP); diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java index 55fabd83b7..bb404bb65d 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java @@ -177,6 +177,7 @@ * Jesper S Moller - added the following constants * TargetTypeNotAFunctionalInterface * OuterLocalMustBeEffectivelyFinal + * IllegalModifiersForPackage *******************************************************************************/ package org.eclipse.jdt.core.compiler; @@ -1664,6 +1665,8 @@ void setSourceStart(int sourceStart); // Java 8 work /** @since 3.9 */ int IllegalModifiersForElidedType = Internal + 1001; + /** @since 3.9 */ + int IllegalModifiersForPackage = Internal + 1002; // default methods: /** @since 3.9 */ 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 c0b1b8281f..2714245c0d 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 @@ -22,6 +22,7 @@ * Jesper S Moller - Contributions for * bug 382701 - [1.8][compiler] Implement semantic analysis of Lambda expressions & Reference expression * bug 399695 - [1.8][compiler] [1.8][compiler] migrate parser to other syntax for default methods + * bug 384567 - [1.5][compiler] Compiler accepts illegal modifiers on package declaration *******************************************************************************/ package org.eclipse.jdt.internal.compiler.parser; @@ -5554,6 +5555,7 @@ protected void consumePackageDeclarationNameWithModifiers() { length); int packageModifiersSourceStart = this.intStack[this.intPtr--]; + int packageModifiersSourceEnd = packageModifiersSourceStart; // Unless there were any int packageModifiers = this.intStack[this.intPtr--]; impt = new ImportReference(tokens, positions, false, packageModifiers); @@ -5567,15 +5569,21 @@ protected void consumePackageDeclarationNameWithModifiers() { 0, length); impt.declarationSourceStart = packageModifiersSourceStart; - this.intPtr--; // we don't need the position of the 'package keyword + packageModifiersSourceEnd = this.intStack[this.intPtr--] - 2; // we don't need the position of the 'package keyword } else { impt.declarationSourceStart = this.intStack[this.intPtr--]; + packageModifiersSourceEnd = impt.declarationSourceStart - 2; // get possible comment source start if (this.javadoc != null) { impt.declarationSourceStart = this.javadoc.sourceStart; } } + if (packageModifiers != 0) { + problemReporter().illegalModifiersForPackage(packageModifiersSourceStart, packageModifiersSourceEnd); + } + + if (this.currentToken == TokenNameSEMICOLON){ impt.declarationSourceEnd = this.scanner.currentPosition - 1; } else { 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 2d20bb1a68..f937e5c304 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 @@ -36,6 +36,7 @@ * Jesper S Moller <jesper@selskabet.org> - Contributions for * bug 382701 - [1.8][compiler] Implement semantic analysis of Lambda expressions & Reference expression * bug 382721 - [1.8][compiler] Effectively final variables needs special treatment + * bug 384567 - [1.5][compiler] Compiler accepts illegal modifiers on package declaration *******************************************************************************/ package org.eclipse.jdt.internal.compiler.problem; @@ -9142,6 +9143,15 @@ public void illegalModifiersForElidedType(Argument argument) { argument.declarationSourceEnd); } +public void illegalModifiersForPackage(int modifierSourceStart, int modifiersSourceEnd) { + this.handle( + IProblem.IllegalModifiersForPackage, + NoArgument, + NoArgument, + modifierSourceStart, + modifiersSourceEnd); +} + public void arrayReferencePotentialNullReference(ArrayReference arrayReference) { // TODO(stephan): merge with other expressions this.handle(IProblem.ArrayReferencePotentialNullReference, NoArgument, NoArgument, arrayReference.sourceStart, arrayReference.sourceEnd); diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties index afe9c6131c..7a20e154cf 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties @@ -31,6 +31,7 @@ # bug 402028 - [1.8][compiler] null analysis for reference expressions # Jesper S Moller <jesper@selskabet.org> - Contributions for # bug 382701 - [1.8][compiler] Implement semantic analysis of Lambda expressions & Reference expression +# bug 384567 - [1.5][compiler] Compiler accepts illegal modifiers on package declaration ############################################################################### 0 = {0} 1 = super cannot be used in java.lang.Object @@ -773,6 +774,7 @@ // Java 8 1001 = Syntax error, modifiers and annotations are not allowed for the lambda parameter {0} as its type is elided +1002 = Syntax error, modifiers are not allowed here # Default methods: # variant of 359: |
