Merge branch 'JDK-8359596' into JDK-8348611

This commit is contained in:
Archie L. Cobbs 2025-06-18 12:58:00 -05:00
commit 38febc6b17
3 changed files with 54 additions and 34 deletions

View File

@ -172,55 +172,35 @@ public class Options {
}
/**
* Check whether the given lint category is explicitly enabled or disabled.
* Determine if a specific {@link LintCategory} is explicitly enabled via a custom
* option flag of the form {@code -Flag:key}.
*
* <p>
* If the category is neither enabled nor disabled, return the given default value.
* Note: It's possible the category was also explicitly disabled; this method does not check that.
*
* @param option the plain (non-custom) option
* @param lc the {@link LintCategory} in question
* @param defaultValue presumed default value
* @return true if {@code lc} would be included
*/
public boolean isSet(Option option, LintCategory lc, boolean defaultValue) {
Option customOption = option.getCustom();
if (lc.optionList.stream().anyMatch(alias -> isSet(customOption, alias))) {
return true;
}
if (lc.optionList.stream().anyMatch(alias -> isSet(customOption, "-" + alias))) {
return false;
}
if (isSet(option) || isSet(customOption, Option.LINT_CUSTOM_ALL)) {
return true;
}
if (isSet(customOption, Option.LINT_CUSTOM_NONE)) {
return false;
}
return defaultValue;
}
/**
* Determine if a specific {@link LintCategory} was explicitly enabled via a custom option flag
* of the form {@code -Flag:all} or {@code -Flag:key}.
*
* @param option the option
* @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 explicitly enabled
*/
public boolean isExplicitlyEnabled(Option option, LintCategory lc) {
return isSet(option, lc, false);
Option customOption = option.getCustom();
return lc.optionList.stream().anyMatch(alias -> isSet(customOption, alias));
}
/**
* Determine if a specific {@link LintCategory} was explicitly disabled via a custom option flag
* of the form {@code -Flag:none} or {@code -Flag:-key}.
* Determine if a specific {@link LintCategory} is explicitly disabled via a custom
* option flag of the form {@code -Flag:-key}.
*
* @param option the option
* <p>
* Note: It's possible the category was also explicitly 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 explicitly disabled
*/
public boolean isExplicitlyDisabled(Option option, LintCategory lc) {
return !isSet(option, lc, true);
Option customOption = option.getCustom();
return lc.optionList.stream().anyMatch(alias -> isSet(customOption, "-" + alias));
}
public void put(String name, String value) {

View File

@ -0,0 +1,36 @@
/*
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 8359596
* @summary Verify behavior when both "-Xlint:options" and "-Xlint:-options" are given
* @compile/fail/ref=LintOptions.out -Werror -XDrawDiagnostics -source 21 -target 21 LintOptions.java
* @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
*/
class LintOptions {
}

View File

@ -0,0 +1,4 @@
- compiler.warn.source.no.system.modules.path: 21, (compiler.misc.source.no.system.modules.path.with.target: 21, 21)
- compiler.err.warnings.and.werror
1 error
1 warning