src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java
changeset 49580 62b908c9f0e6
parent 49543 2d5d75263e77
child 50518 e775444c555e
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java	Thu Apr 12 09:23:34 2018 +0200
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java	Thu Apr 12 13:55:20 2018 +0100
@@ -95,6 +95,9 @@
     /** The Source language setting. */
     private Source source;
 
+    /** The Preview language setting. */
+    private Preview preview;
+
     /** The name table. */
     private Names names;
 
@@ -169,6 +172,7 @@
         this.log = fac.log;
         this.names = fac.names;
         this.source = fac.source;
+        this.preview = fac.preview;
         this.allowStringFolding = fac.options.getBoolean("allowStringFolding", true);
         this.keepDocComments = keepDocComments;
         this.parseModuleInfo = parseModuleInfo;
@@ -4219,8 +4223,15 @@
     }
 
     protected void checkSourceLevel(int pos, Feature feature) {
-        if (!feature.allowedInSource(source)) {
+        if (preview.isPreview(feature) && !preview.isEnabled()) {
+            //preview feature without --preview flag, error
+            log.error(DiagnosticFlag.SOURCE_LEVEL, pos, preview.disabledError(feature));
+        } else if (!feature.allowedInSource(source)) {
+            //incompatible source level, error
             log.error(DiagnosticFlag.SOURCE_LEVEL, pos, feature.error(source.name));
+        } else if (preview.isPreview(feature)) {
+            //use of preview feature, warn
+            preview.warnPreview(pos, feature);
         }
     }