--- 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);
}
}