Bug 565847 - [15] No preview warning on using sealed types

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>
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 255740b..7323d6c 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 @@
 	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 @@
 				"}";
 		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 9baa6f9..138d3ec 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 @@
 	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 @@
 		case TokenNamebreak :
 		case TokenNamecontinue :
 		case TokenNamereturn :
-//		case TokenNamecase :
 		case TokenNamemodule:
 		case TokenNamerequires:
 		case TokenNameexports:
@@ -10306,7 +10309,10 @@
 		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 :