Move (most) SOURCE_LEVEL flags into compiler.properties.

This commit is contained in:
Archie L. Cobbs 2025-06-27 17:31:20 -05:00
parent 2ebeefc949
commit 95b368fb41
5 changed files with 13 additions and 26 deletions

View File

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

View File

@ -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) {

View File

@ -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;

View File

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

View File

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