mirror of
https://github.com/openjdk/jdk.git
synced 2026-03-20 04:43:32 +00:00
8033961: Formatting of -Xlint: command line help
Improving formatting of command line help for -Xlint, including a short description of each lint. Reviewed-by: jjg
This commit is contained in:
parent
55801d06ff
commit
e20546fe2a
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2006, 2014, 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
|
||||
@ -38,6 +38,7 @@ import javax.lang.model.SourceVersion;
|
||||
|
||||
import com.sun.tools.doclint.DocLint;
|
||||
import com.sun.tools.javac.code.Lint;
|
||||
import com.sun.tools.javac.code.Lint.LintCategory;
|
||||
import com.sun.tools.javac.code.Source;
|
||||
import com.sun.tools.javac.code.Type;
|
||||
import com.sun.tools.javac.jvm.Profile;
|
||||
@ -80,8 +81,34 @@ public enum Option {
|
||||
|
||||
XLINT("-Xlint", "opt.Xlint", EXTENDED, BASIC),
|
||||
|
||||
XLINT_CUSTOM("-Xlint:", "opt.Xlint.suboptlist",
|
||||
EXTENDED, BASIC, ANYOF, getXLintChoices()),
|
||||
XLINT_CUSTOM("-Xlint:", EXTENDED, BASIC, ANYOF, getXLintChoices()) {
|
||||
private static final String LINT_KEY_FORMAT = " %-19s %s";
|
||||
void help(Log log, OptionKind kind) {
|
||||
if (this.kind != kind)
|
||||
return;
|
||||
|
||||
log.printRawLines(WriterKind.NOTICE,
|
||||
String.format(HELP_LINE_FORMAT,
|
||||
log.localize(PrefixKind.JAVAC, "opt.Xlint.subopts"),
|
||||
log.localize(PrefixKind.JAVAC, "opt.Xlint.suboptlist")));
|
||||
log.printRawLines(WriterKind.NOTICE,
|
||||
String.format(LINT_KEY_FORMAT,
|
||||
"all",
|
||||
log.localize(PrefixKind.JAVAC, "opt.Xlint.all")));
|
||||
for (LintCategory lc : LintCategory.values()) {
|
||||
if (lc.hidden) continue;
|
||||
log.printRawLines(WriterKind.NOTICE,
|
||||
String.format(LINT_KEY_FORMAT,
|
||||
lc.option,
|
||||
log.localize(PrefixKind.JAVAC,
|
||||
"opt.Xlint.desc." + lc.option)));
|
||||
}
|
||||
log.printRawLines(WriterKind.NOTICE,
|
||||
String.format(LINT_KEY_FORMAT,
|
||||
"none",
|
||||
log.localize(PrefixKind.JAVAC, "opt.Xlint.none")));
|
||||
}
|
||||
},
|
||||
|
||||
XDOCLINT("-Xdoclint", "opt.Xdoclint", EXTENDED, BASIC),
|
||||
|
||||
@ -550,10 +577,9 @@ public enum Option {
|
||||
this(text, argsNameKey, descrKey, kind, group, null, null, doHasSuffix);
|
||||
}
|
||||
|
||||
Option(String text, String descrKey,
|
||||
OptionKind kind, OptionGroup group,
|
||||
Option(String text, OptionKind kind, OptionGroup group,
|
||||
ChoiceKind choiceKind, Map<String,Boolean> choices) {
|
||||
this(text, null, descrKey, kind, group, choiceKind, choices, false);
|
||||
this(text, null, null, kind, group, choiceKind, choices, false);
|
||||
}
|
||||
|
||||
Option(String text, String descrKey,
|
||||
@ -650,12 +676,14 @@ public enum Option {
|
||||
return process(helper, option, option);
|
||||
}
|
||||
|
||||
private static final String HELP_LINE_FORMAT = " %-26s %s";
|
||||
|
||||
void help(Log log, OptionKind kind) {
|
||||
if (this.kind != kind)
|
||||
return;
|
||||
|
||||
log.printRawLines(WriterKind.NOTICE,
|
||||
String.format(" %-26s %s",
|
||||
String.format(HELP_LINE_FORMAT,
|
||||
helpSynopsis(log),
|
||||
log.localize(PrefixKind.JAVAC, descrKey)));
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
#
|
||||
# Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
# Copyright (c) 1999, 2014, 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
|
||||
@ -142,8 +142,80 @@ javac.opt.arg.file=\
|
||||
<filename>
|
||||
javac.opt.Xlint=\
|
||||
Enable recommended warnings
|
||||
javac.opt.Xlint.suboptlist=\
|
||||
Enable or disable specific warnings
|
||||
javac.opt.Xlint.all=\
|
||||
Enable all warnings
|
||||
javac.opt.Xlint.none=\
|
||||
Disable all warnings
|
||||
#L10N: do not localize: -Xlint
|
||||
javac.opt.Xlint.subopts=\
|
||||
-Xlint:key,...
|
||||
javac.opt.Xlint.suboptlist=\n\
|
||||
\ Warnings to enable or disable, separated by comma.\n\
|
||||
\ Precede a key by '-' to disable the specified warning.\n\
|
||||
\ Supported keys are:
|
||||
javac.opt.Xlint.desc.auxiliaryclass=\
|
||||
Warn about an auxiliary class that is hidden in a source file, and is used from other files.
|
||||
|
||||
javac.opt.Xlint.desc.cast=\
|
||||
Warn about use of unnecessary casts.
|
||||
|
||||
javac.opt.Xlint.desc.classfile=\
|
||||
Warn about issues related to classfile contents.
|
||||
|
||||
javac.opt.Xlint.desc.deprecation=\
|
||||
Warn about use of deprecated items.
|
||||
|
||||
javac.opt.Xlint.desc.dep-ann=\
|
||||
Warn about items marked as deprecated in JavaDoc but not using the @Deprecated annotation.
|
||||
|
||||
javac.opt.Xlint.desc.divzero=\
|
||||
Warn about division by constant integer 0.
|
||||
|
||||
javac.opt.Xlint.desc.empty=\
|
||||
Warn about empty statement after if.
|
||||
|
||||
javac.opt.Xlint.desc.fallthrough=\
|
||||
Warn about falling through from one case of a switch statement to the next.
|
||||
|
||||
javac.opt.Xlint.desc.finally=\
|
||||
Warn about finally clauses that do not terminate normally.
|
||||
|
||||
javac.opt.Xlint.desc.options=\
|
||||
Warn about issues relating to use of command line options.
|
||||
|
||||
javac.opt.Xlint.desc.overloads=\
|
||||
Warn about issues regarding method overloads.
|
||||
|
||||
javac.opt.Xlint.desc.overrides=\
|
||||
Warn about issues regarding method overrides.
|
||||
|
||||
javac.opt.Xlint.desc.path=\
|
||||
Warn about invalid path elements on the command line.
|
||||
|
||||
javac.opt.Xlint.desc.processing=\
|
||||
Warn about issues regarding annotation processing.
|
||||
|
||||
javac.opt.Xlint.desc.rawtypes=\
|
||||
Warn about use of raw types.
|
||||
|
||||
javac.opt.Xlint.desc.serial=\
|
||||
Warn about Serializable classes that do not provide a serial version ID.
|
||||
|
||||
javac.opt.Xlint.desc.static=\
|
||||
Warn about accessing a static member using an instance.
|
||||
|
||||
javac.opt.Xlint.desc.sunapi=\
|
||||
Warn about proprietary API that may be removed in a future release.
|
||||
|
||||
javac.opt.Xlint.desc.try=\
|
||||
Warn about issues relating to use of try blocks (i.e. try-with-resources).
|
||||
|
||||
javac.opt.Xlint.desc.unchecked=\
|
||||
Warn about unchecked operations.
|
||||
|
||||
javac.opt.Xlint.desc.varargs=\
|
||||
Warn about potentially unsafe vararg methods
|
||||
|
||||
javac.opt.Xdoclint=\
|
||||
Enable recommended checks for problems in javadoc comments
|
||||
# L10N: do not localize: all none
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2010, 2014, 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
|
||||
@ -31,6 +31,7 @@ import java.io.*;
|
||||
import java.util.*;
|
||||
import javax.tools.*;
|
||||
import com.sun.tools.classfile.*;
|
||||
import com.sun.tools.javac.code.Lint.LintCategory;
|
||||
|
||||
/**
|
||||
* Compare string constants in javac classes against keys in javac resource bundles.
|
||||
@ -156,6 +157,20 @@ public class CheckResourceKeys {
|
||||
if (needToInvestigate.contains(rk))
|
||||
continue;
|
||||
|
||||
//check lint description keys:
|
||||
if (s.startsWith("opt.Xlint.desc.")) {
|
||||
String option = s.substring(15);
|
||||
boolean found = false;
|
||||
|
||||
for (LintCategory lc : LintCategory.values()) {
|
||||
if (option.equals(lc.option))
|
||||
found = true;
|
||||
}
|
||||
|
||||
if (found)
|
||||
continue;
|
||||
}
|
||||
|
||||
error("Resource key not found in code: " + rk);
|
||||
}
|
||||
}
|
||||
@ -274,6 +289,7 @@ public class CheckResourceKeys {
|
||||
// prefix/embedded strings
|
||||
"compiler.",
|
||||
"compiler.misc.",
|
||||
"opt.Xlint.desc.",
|
||||
"count.",
|
||||
"illegal.",
|
||||
"javac.",
|
||||
|
||||
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 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.
|
||||
*
|
||||
* 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 8033961
|
||||
* @summary Verify that all LintCategories have their descriptions filled.
|
||||
*/
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
import com.sun.tools.javac.code.Lint.LintCategory;
|
||||
import com.sun.tools.javac.util.Log.PrefixKind;
|
||||
|
||||
public class VerifyLintDescriptions {
|
||||
public static void main(String... args) {
|
||||
ResourceBundle b = ResourceBundle.getBundle("com.sun.tools.javac.resources.javac",
|
||||
Locale.US);
|
||||
|
||||
List<String> missing = new ArrayList<>();
|
||||
|
||||
for (LintCategory lc : LintCategory.values()) {
|
||||
try {
|
||||
b.getString(PrefixKind.JAVAC.key("opt.Xlint.desc." + lc.option));
|
||||
} catch (MissingResourceException ex) {
|
||||
missing.add(lc.option);
|
||||
}
|
||||
}
|
||||
|
||||
if (!missing.isEmpty()) {
|
||||
throw new UnsupportedOperationException("Lints that are missing description: " + missing);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user