From 95b368fb41185cd6ced98c8c8a875ce86fa81682 Mon Sep 17 00:00:00 2001 From: "Archie L. Cobbs" Date: Fri, 27 Jun 2025 17:31:20 -0500 Subject: [PATCH] Move (most) SOURCE_LEVEL flags into compiler.properties. --- .../com/sun/tools/javac/code/Preview.java | 5 ++--- .../com/sun/tools/javac/comp/Attr.java | 7 ++----- .../sun/tools/javac/parser/JavaTokenizer.java | 19 +++---------------- .../sun/tools/javac/parser/JavacParser.java | 4 ++-- .../tools/javac/resources/compiler.properties | 4 ++++ 5 files changed, 13 insertions(+), 26 deletions(-) diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Preview.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Preview.java index 4f7a84844fb..c70202fd942 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Preview.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Preview.java @@ -34,7 +34,6 @@ import com.sun.tools.javac.resources.CompilerProperties.LintWarnings; import com.sun.tools.javac.resources.CompilerProperties.Warnings; import com.sun.tools.javac.util.Assert; import com.sun.tools.javac.util.Context; -import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag; import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; import com.sun.tools.javac.util.JCDiagnostic.Error; import com.sun.tools.javac.util.JCDiagnostic.LintWarning; @@ -265,10 +264,10 @@ public class Preview { public void checkSourceLevel(DiagnosticPosition pos, Feature feature) { if (isPreview(feature) && !isEnabled()) { //preview feature without --preview flag, error - log.error(DiagnosticFlag.SOURCE_LEVEL, pos, disabledError(feature)); + log.error(pos, disabledError(feature)); } else { if (!feature.allowedInSource(source)) { - log.error(DiagnosticFlag.SOURCE_LEVEL, pos, feature.error(source.name)); + log.error(pos, feature.error(source.name)); } if (isEnabled() && isPreview(feature)) { warnPreview(pos, feature); diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java index 9c9672151c7..8819acbe67e 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java @@ -79,7 +79,6 @@ import static com.sun.tools.javac.code.Kinds.Kind.*; import static com.sun.tools.javac.code.TypeTag.*; import static com.sun.tools.javac.code.TypeTag.WILDCARD; import static com.sun.tools.javac.tree.JCTree.Tag.*; -import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag; /** This is the main context-dependent analysis phase in GJC. It * encompasses name resolution, type checking and constant folding as @@ -4146,8 +4145,7 @@ public class Attr extends JCTree.Visitor { !exprtype.isErroneous() && !clazztype.isErroneous() && tree.pattern.getTag() != RECORDPATTERN) { if (!allowUnconditionalPatternsInstanceOf) { - log.error(DiagnosticFlag.SOURCE_LEVEL, tree.pos(), - Feature.UNCONDITIONAL_PATTERN_IN_INSTANCEOF.error(this.sourceName)); + log.error(tree.pos(), Feature.UNCONDITIONAL_PATTERN_IN_INSTANCEOF.error(this.sourceName)); } } typeTree = TreeInfo.primaryPatternTypeTree((JCPattern) tree.pattern); @@ -4167,8 +4165,7 @@ public class Attr extends JCTree.Visitor { if (allowReifiableTypesInInstanceof) { valid = checkCastablePattern(tree.expr.pos(), exprtype, clazztype); } else { - log.error(DiagnosticFlag.SOURCE_LEVEL, tree.pos(), - Feature.REIFIABLE_TYPES_INSTANCEOF.error(this.sourceName)); + log.error(tree.pos(), Feature.REIFIABLE_TYPES_INSTANCEOF.error(this.sourceName)); allowReifiableTypesInInstanceof = true; } if (!valid) { diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavaTokenizer.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavaTokenizer.java index d799975a76a..f3d0837398c 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavaTokenizer.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavaTokenizer.java @@ -181,10 +181,10 @@ public class JavaTokenizer extends UnicodeReader { protected void checkSourceLevel(int pos, Feature feature) { if (preview.isPreview(feature) && !preview.isEnabled()) { //preview feature without --preview flag, error - lexError(DiagnosticFlag.SOURCE_LEVEL, pos, preview.disabledError(feature)); + lexError(pos, preview.disabledError(feature)); } else if (!feature.allowedInSource(source)) { //incompatible source level, error - lexError(DiagnosticFlag.SOURCE_LEVEL, pos, feature.error(source.name)); + lexError(pos, feature.error(source.name)); } else if (preview.isPreview(feature)) { //use of preview feature, warn preview.warnPreview(pos, feature); @@ -199,20 +199,7 @@ public class JavaTokenizer extends UnicodeReader { */ protected void lexError(int pos, JCDiagnostic.Error key) { log.error(pos, key); - tk = TokenKind.ERROR; - errPos = pos; - } - - /** - * Report an error at the given position using the provided arguments. - * - * @param flags diagnostic flags. - * @param pos position in input buffer. - * @param key error key to report. - */ - protected void lexError(DiagnosticFlag flags, int pos, JCDiagnostic.Error key) { - log.error(flags, pos, key); - if (flags != DiagnosticFlag.SOURCE_LEVEL) { + if (!key.hasFlag(DiagnosticFlag.SOURCE_LEVEL)) { tk = TokenKind.ERROR; } errPos = pos; diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java index 7ebcd0c844b..b63374d9c6d 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java @@ -5611,10 +5611,10 @@ public class JavacParser implements Parser { protected void checkSourceLevel(int pos, Feature feature) { if (preview.isPreview(feature) && !preview.isEnabled()) { //preview feature without --preview flag, error - log.error(DiagnosticFlag.SOURCE_LEVEL, pos, preview.disabledError(feature)); + log.error(pos, preview.disabledError(feature)); } else if (!feature.allowedInSource(source)) { //incompatible source level, error - log.error(DiagnosticFlag.SOURCE_LEVEL, pos, feature.error(source.name)); + log.error(pos, feature.error(source.name)); } else if (preview.isPreview(feature)) { //use of preview feature, warn preview.warnPreview(pos, feature); diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties index e6c57169f0f..6c6f80ef58c 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties @@ -3260,11 +3260,13 @@ compiler.misc.inapplicable.method=\ ######################################## # 0: message segment (feature), 1: string (found version), 2: string (expected version) +# flags: source-level compiler.err.feature.not.supported.in.source=\ {0} is not supported in -source {1}\n\ (use -source {2} or higher to enable {0}) # 0: message segment (feature), 1: string (found version), 2: string (expected version) +# flags: source-level compiler.err.feature.not.supported.in.source.plural=\ {0} are not supported in -source {1}\n\ (use -source {2} or higher to enable {0}) @@ -3280,11 +3282,13 @@ compiler.misc.feature.not.supported.in.source.plural=\ (use -source {2} or higher to enable {0}) # 0: message segment (feature) +# flags: source-level compiler.err.preview.feature.disabled=\ {0} is a preview feature and is disabled by default.\n\ (use --enable-preview to enable {0}) # 0: message segment (feature) +# flags: source-level compiler.err.preview.feature.disabled.plural=\ {0} are a preview feature and are disabled by default.\n\ (use --enable-preview to enable {0})