diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Log.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Log.java index 6b0bea7feab..8d9f9817c3b 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Log.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Log.java @@ -170,8 +170,8 @@ public class Log extends AbstractLog { boolean emit = !diag.isFlagSet(DEFAULT_ENABLED) ? // is the warning not enabled by default? lint.isEnabled(category) : // then emit if the category is enabled category.annotationSuppression ? // else emit if the category is not suppressed, where - !lint.isSuppressed(category) : // ...suppression happens via @SuppressWarnings - !options.isExplicitlyDisabled(Option.XLINT, category); // ...suppression happens via -Xlint:-category + !lint.isSuppressed(category) : // ...suppression happens via @SuppressWarnings + !options.isDisabled(Option.XLINT, category); // ...suppression happens via -Xlint:-category if (!emit) return; } diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Options.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Options.java index c882fb4cf8a..cbc69feb421 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Options.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Options.java @@ -171,12 +171,46 @@ public class Options { return !isSet(option, value); } + /** + * Determine if a specific {@link LintCategory} is enabled via a custom + * option flag of the form {@code -Flag}, {@code -Flag:all}, or {@code -Flag:key}. + * + *
+ * Note: It's possible the category was also disabled; this method does not check that. + * + * @param option the plain (non-custom) version of the option (e.g., {@link Option#XLINT}) + * @param lc the {@link LintCategory} in question + * @return true if {@code lc} has been enabled + */ + public boolean isEnabled(Option option, LintCategory lc) { + Option custom = option.getCustom(); + return isExplicitlyEnabled(option, lc) || isSet(custom) || isSet(custom, Option.LINT_CUSTOM_ALL); + } + + /** + * Determine if a specific {@link LintCategory} is disabled via a custom + * option flag of the form {@code -Flag:none} or {@code -Flag:-key}. + * + *
+ * Note: It's possible the category was also enabled; this method does not check that. + * + * @param option the plain (non-custom) version of the option (e.g., {@link Option#XLINT}) + * @param lc the {@link LintCategory} in question + * @return true if {@code lc} has been disabled + */ + public boolean isDisabled(Option option, LintCategory lc) { + return isExplicitlyDisabled(option, lc) || isSet(option.getCustom(), Option.LINT_CUSTOM_NONE); + } + /** * Determine if a specific {@link LintCategory} is explicitly enabled via a custom * option flag of the form {@code -Flag:key}. * *
- * Note: It's possible the category was also explicitly disabled; this method does not check that. + * Note: This does not check for option flags of the form {@code -Flag} or {@code -Flag:all}. + * + *
+ * Note: It's possible the category was also disabled; this method does not check that. * * @param option the plain (non-custom) version of the option (e.g., {@link Option#XLINT}) * @param lc the {@link LintCategory} in question @@ -192,7 +226,10 @@ public class Options { * option flag of the form {@code -Flag:-key}. * *
- * Note: It's possible the category was also explicitly enabled; this method does not check that. + * Note: This does not check for an option flag of the form {@code -Flag:none}. + * + *
+ * Note: It's possible the category was also enabled; this method does not check that. * * @param option the plain (non-custom) version of the option (e.g., {@link Option#XLINT}) * @param lc the {@link LintCategory} in question diff --git a/test/langtools/tools/javac/lint/LintOptions.java b/test/langtools/tools/javac/lint/LintOptions.java index b5825fce728..10def72a31a 100644 --- a/test/langtools/tools/javac/lint/LintOptions.java +++ b/test/langtools/tools/javac/lint/LintOptions.java @@ -31,6 +31,8 @@ * @compile/fail/ref=LintOptions.out -Werror -XDrawDiagnostics -source 21 -target 21 -Xlint:options LintOptions.java * @compile -Werror -XDrawDiagnostics -source 21 -target 21 -Xlint:-options LintOptions.java * @compile -Werror -XDrawDiagnostics -source 21 -target 21 -Xlint:options -Xlint:-options LintOptions.java + * @compile -Werror -XDrawDiagnostics -source 21 -target 21 -Xlint:none LintOptions.java + * @compile -Werror -XDrawDiagnostics -source 21 -target 21 -Xlint:options -Xlint:none LintOptions.java */ class LintOptions { }