Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVikas Chandra2020-08-12 16:41:53 +0000
committerVikas Chandra2020-08-17 13:09:10 +0000
commit9cd8f4ece021d58db4fdfa4aa4603ece71baf7f7 (patch)
tree46c6d92ab29e276cc923ea002271ae7a0dc0b1ca
parentf283097bad85669ee08dfa2a363f9ad7772a773b (diff)
downloadeclipse.jdt.core-P20200821-0510.tar.gz
eclipse.jdt.core-P20200821-0510.tar.xz
eclipse.jdt.core-P20200821-0510.zip
Change-Id: I37418a63ffb257318732a8864a9574a6881ede3e Also-by: Manoj Palat<manpalat@in.ibm.com> Signed-off-by: Vikas Chandra <Vikas.Chandra@in.ibm.com> Signed-off-by: Manoj Palat<manpalat@in.ibm.com>
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SealedTypes15Tests.java47
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java8
2 files changed, 53 insertions, 2 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SealedTypes15Tests.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SealedTypes15Tests.java
index 255740b8c9..7323d6ceba 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SealedTypes15Tests.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SealedTypes15Tests.java
@@ -35,7 +35,7 @@ public class SealedTypes15Tests extends AbstractRegressionTest9 {
static {
// TESTS_NUMBERS = new int [] { 40 };
// TESTS_RANGE = new int[] { 1, -1 };
-// TESTS_NAMES = new String[] { "testBug565782"};
+// TESTS_NAMES = new String[] { "testBug565847_001"};
}
public static Class<?> testClass() {
@@ -5264,4 +5264,49 @@ public class SealedTypes15Tests extends AbstractRegressionTest9 {
"}";
verifyClassFile(expectedOutput, "X.class", ClassFileBytesDisassembler.SYSTEM);
}
+ public void testBug565847_001() {
+ Map<String, String> options =getCompilerOptions();
+ options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.WARNING);
+
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public sealed class X permits Y {" +
+ "Zork();\n" +
+ "}\n" +
+ "final class Y extends X{}\n" +
+ "sealed interface I{}\n" +
+ "final class Z implements I{}",
+ },
+ "----------\n" +
+ "1. WARNING in X.java (at line 1)\n" +
+ " public sealed class X permits Y {Zork();\n" +
+ " ^^^^^^\n" +
+ "You are using a preview language feature that may or may not be supported in a future release\n" +
+ "----------\n" +
+ "2. WARNING in X.java (at line 1)\n" +
+ " public sealed class X permits Y {Zork();\n" +
+ " ^^^^^^^\n" +
+ "You are using a preview language feature that may or may not be supported in a future release\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 1)\n" +
+ " public sealed class X permits Y {Zork();\n" +
+ " ^^^^^^\n" +
+ "Return type for the method is missing\n" +
+ "----------\n" +
+ "4. ERROR in X.java (at line 1)\n" +
+ " public sealed class X permits Y {Zork();\n" +
+ " ^^^^^^\n" +
+ "This method requires a body instead of a semicolon\n" +
+ "----------\n" +
+ "5. WARNING in X.java (at line 4)\n" +
+ " sealed interface I{}\n" +
+ " ^^^^^^\n" +
+ "You are using a preview language feature that may or may not be supported in a future release\n" +
+ "----------\n",
+ null,
+ true,
+ options
+ );
+ }
}
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 9baa6f99fa..138d3ec78c 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
@@ -1226,6 +1226,10 @@ protected void checkAndSetModifiers(int flag){
if (this.currentElement != null) {
this.currentElement.addModifier(flag, this.modifiersSourceStart);
}
+ if (flag == ExtraCompilerModifiers.AccSealed || flag == ExtraCompilerModifiers.AccNonSealed) {
+ problemReporter().validateJavaFeatureSupport(JavaFeature.SEALED_CLASSES, this.scanner.startPosition,
+ this.scanner.currentPosition - 1);
+ }
}
public void checkComment() {
@@ -10298,7 +10302,6 @@ protected void consumeToken(int type) {
case TokenNamebreak :
case TokenNamecontinue :
case TokenNamereturn :
-// case TokenNamecase :
case TokenNamemodule:
case TokenNamerequires:
case TokenNameexports:
@@ -10306,7 +10309,10 @@ protected void consumeToken(int type) {
case TokenNameuses:
case TokenNameprovides:
case TokenNameRestrictedIdentifierYield:
+ pushOnIntStack(this.scanner.startPosition);
+ break;
case TokenNameRestrictedIdentifierpermits:
+ problemReporter().validateJavaFeatureSupport(JavaFeature.SEALED_CLASSES, this.scanner.startPosition,this.scanner.currentPosition - 1);
pushOnIntStack(this.scanner.startPosition);
break;
case TokenNamecase :

Back to the top