From 55262200dce162f7bc4f78c3596ec5e25f3376fd Mon Sep 17 00:00:00 2001 From: Maurizio Cimadamore Date: Mon, 2 Dec 2024 15:23:38 +0000 Subject: [PATCH] Simplify code --- .../tools/propertiesparser/parser/MessageLine.java | 1 - .../classes/com/sun/tools/javac/code/Preview.java | 2 +- .../share/classes/com/sun/tools/javac/comp/Check.java | 8 ++++---- .../com/sun/tools/javac/parser/JavaTokenizer.java | 7 +++---- .../sun/tools/javac/util/MandatoryWarningHandler.java | 11 +---------- 5 files changed, 9 insertions(+), 20 deletions(-) diff --git a/make/langtools/tools/propertiesparser/parser/MessageLine.java b/make/langtools/tools/propertiesparser/parser/MessageLine.java index 559b5c60f6497..c73021e08274e 100644 --- a/make/langtools/tools/propertiesparser/parser/MessageLine.java +++ b/make/langtools/tools/propertiesparser/parser/MessageLine.java @@ -25,7 +25,6 @@ package propertiesparser.parser; -import java.util.Optional; import java.util.regex.Matcher; import java.util.regex.Pattern; 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 29b290b285e0a..baa0240365b80 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 @@ -102,7 +102,7 @@ protected Preview(Context context) { lint = Lint.instance(context); source = Source.instance(context); this.previewHandler = - new MandatoryWarningHandler(log, source, lint.isEnabled(LintCategory.PREVIEW), true, "preview", LintCategory.PREVIEW); + new MandatoryWarningHandler(log, source, lint.isEnabled(LintCategory.PREVIEW), true, "preview"); forcePreview = options.isSet("forcePreview"); majorVersionToSource = initMajorVersionToSourceMap(); } diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java index 367c086900aeb..043c0b2c6d23c 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java @@ -167,13 +167,13 @@ protected Check(Context context) { boolean enforceMandatoryWarnings = true; deprecationHandler = new MandatoryWarningHandler(log, null, verboseDeprecated, - enforceMandatoryWarnings, "deprecated", LintCategory.DEPRECATION); + enforceMandatoryWarnings, "deprecated"); removalHandler = new MandatoryWarningHandler(log, null, verboseRemoval, - enforceMandatoryWarnings, "removal", LintCategory.REMOVAL); + enforceMandatoryWarnings, "removal"); uncheckedHandler = new MandatoryWarningHandler(log, null, verboseUnchecked, - enforceMandatoryWarnings, "unchecked", LintCategory.UNCHECKED); + enforceMandatoryWarnings, "unchecked"); sunApiHandler = new MandatoryWarningHandler(log, null, false, - enforceMandatoryWarnings, "sunapi", null); + enforceMandatoryWarnings, "sunapi"); deferredLintHandler = DeferredLintHandler.instance(context); 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 28c443831bc41..a09d82aa70e1c 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 @@ -220,11 +220,10 @@ protected void lexError(DiagnosticFlag flags, int pos, JCDiagnostic.Error key) { /** * Report an error at the given position using the provided arguments. * - * @param lc lint category. * @param pos position in input buffer. * @param key error key to report. */ - protected void lexWarning(LintCategory lc, int pos, JCDiagnostic.Warning key) { + protected void lexWarning(int pos, JCDiagnostic.Warning key) { DiagnosticPosition dp = new SimpleDiagnosticPosition(pos) ; log.warning(dp, key); } @@ -1073,11 +1072,11 @@ public Token readToken() { Set checks = TextBlockSupport.checkWhitespace(string); if (checks.contains(TextBlockSupport.WhitespaceChecks.INCONSISTENT)) { - lexWarning(LintCategory.TEXT_BLOCKS, pos, + lexWarning(pos, Warnings.InconsistentWhiteSpaceIndentation); } if (checks.contains(TextBlockSupport.WhitespaceChecks.TRAILING)) { - lexWarning(LintCategory.TEXT_BLOCKS, pos, + lexWarning(pos, Warnings.TrailingWhiteSpaceWillBeRemoved); } } diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/MandatoryWarningHandler.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/MandatoryWarningHandler.java index 36391d5ea984f..463819afa698d 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/MandatoryWarningHandler.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/MandatoryWarningHandler.java @@ -110,17 +110,14 @@ private enum DeferredDiagnosticKind { * True if mandatory warnings and notes are being enforced. * @param prefix A common prefix for the set of message keys for * the messages that may be generated. - * @param lc An associated lint category for the warnings, or null if none. */ public MandatoryWarningHandler(Log log, Source source, boolean verbose, - boolean enforceMandatory, String prefix, - LintCategory lc) { + boolean enforceMandatory, String prefix) { this.log = log; this.source = source; this.verbose = verbose; this.prefix = prefix; this.enforceMandatory = enforceMandatory; - this.lintCategory = lc; } /** @@ -246,12 +243,6 @@ public void reportDeferredDiagnostic() { */ private final boolean enforceMandatory; - /** - * A LintCategory to be included in point-of-use diagnostics to indicate - * how messages might be suppressed (i.e. with @SuppressWarnings). - */ - private final LintCategory lintCategory; - /** * Reports a mandatory warning to the log. If mandatory warnings * are not being enforced, treat this as an ordinary warning.