Skip to content

Commit 1c75e97

Browse files
6957438: improve code for generating warning messages containing option names
Reviewed-by: mcimadamore
1 parent ccd014e commit 1c75e97

File tree

15 files changed

+263
-105
lines changed

15 files changed

+263
-105
lines changed

langtools/src/share/classes/com/sun/tools/javac/code/Lint.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ protected Lint(Lint other) {
119119
this.suppressedValues = other.suppressedValues.clone();
120120
}
121121

122+
@Override
122123
public String toString() {
123124
return "Lint:[values" + values + " suppressedValues" + suppressedValues + "]";
124125
}

langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3111,23 +3111,27 @@ private void checkSerialVersionUID(JCClassDecl tree, ClassSymbol c) {
31113111
Scope.Entry e = c.members().lookup(names.serialVersionUID);
31123112
while (e.scope != null && e.sym.kind != VAR) e = e.next();
31133113
if (e.scope == null) {
3114-
log.warning(tree.pos(), "missing.SVUID", c);
3114+
log.warning(Lint.LintCategory.SERIAL,
3115+
tree.pos(), "missing.SVUID", c);
31153116
return;
31163117
}
31173118

31183119
// check that it is static final
31193120
VarSymbol svuid = (VarSymbol)e.sym;
31203121
if ((svuid.flags() & (STATIC | FINAL)) !=
31213122
(STATIC | FINAL))
3122-
log.warning(TreeInfo.diagnosticPositionFor(svuid, tree), "improper.SVUID", c);
3123+
log.warning(Lint.LintCategory.SERIAL,
3124+
TreeInfo.diagnosticPositionFor(svuid, tree), "improper.SVUID", c);
31233125

31243126
// check that it is long
31253127
else if (svuid.type.tag != TypeTags.LONG)
3126-
log.warning(TreeInfo.diagnosticPositionFor(svuid, tree), "long.SVUID", c);
3128+
log.warning(Lint.LintCategory.SERIAL,
3129+
TreeInfo.diagnosticPositionFor(svuid, tree), "long.SVUID", c);
31273130

31283131
// check constant
31293132
else if (svuid.getConstValue() == null)
3130-
log.warning(TreeInfo.diagnosticPositionFor(svuid, tree), "constant.SVUID", c);
3133+
log.warning(Lint.LintCategory.SERIAL,
3134+
TreeInfo.diagnosticPositionFor(svuid, tree), "constant.SVUID", c);
31313135
}
31323136

31333137
private Type capture(Type type) {

langtools/src/share/classes/com/sun/tools/javac/comp/Check.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,13 @@ protected Check(Context context) {
111111
boolean enforceMandatoryWarnings = source.enforceMandatoryWarnings();
112112

113113
deprecationHandler = new MandatoryWarningHandler(log, verboseDeprecated,
114-
enforceMandatoryWarnings, "deprecated");
114+
enforceMandatoryWarnings, "deprecated", LintCategory.DEPRECATION);
115115
uncheckedHandler = new MandatoryWarningHandler(log, verboseUnchecked,
116-
enforceMandatoryWarnings, "unchecked");
116+
enforceMandatoryWarnings, "unchecked", LintCategory.UNCHECKED);
117117
unsafeVarargsHandler = new MandatoryWarningHandler(log, verboseVarargs,
118-
enforceMandatoryWarnings, "varargs");
118+
enforceMandatoryWarnings, "varargs", LintCategory.VARARGS);
119119
sunApiHandler = new MandatoryWarningHandler(log, verboseSunApi,
120-
enforceMandatoryWarnings, "sunapi");
120+
enforceMandatoryWarnings, "sunapi", null);
121121
}
122122

123123
/** Switch: generics enabled?
@@ -209,7 +209,7 @@ public void warnSunApi(DiagnosticPosition pos, String msg, Object... args) {
209209

210210
public void warnStatic(DiagnosticPosition pos, String msg, Object... args) {
211211
if (lint.isEnabled(LintCategory.STATIC))
212-
log.warning(pos, msg, args);
212+
log.warning(LintCategory.STATIC, pos, msg, args);
213213
}
214214

215215
/**
@@ -929,7 +929,8 @@ void checkRaw(JCTree tree, Env<AttrContext> env) {
929929
!TreeInfo.isDiamond(tree) &&
930930
!env.enclClass.name.isEmpty() && //anonymous or intersection
931931
tree.type.isRaw()) {
932-
log.warning(tree.pos(), "raw.class.use", tree.type, tree.type.tsym.type);
932+
log.warning(Lint.LintCategory.RAW,
933+
tree.pos(), "raw.class.use", tree.type, tree.type.tsym.type);
933934
}
934935
}
935936

@@ -2156,7 +2157,8 @@ void checkDeprecatedAnnotation(DiagnosticPosition pos, Symbol s) {
21562157
(s.flags() & DEPRECATED) != 0 &&
21572158
!syms.deprecatedType.isErroneous() &&
21582159
s.attribute(syms.deprecatedType.tsym) == null) {
2159-
log.warning(pos, "missing.deprecated.annotation");
2160+
log.warning(Lint.LintCategory.DEP_ANN,
2161+
pos, "missing.deprecated.annotation");
21602162
}
21612163
}
21622164

@@ -2307,7 +2309,7 @@ void checkDivZero(DiagnosticPosition pos, Symbol operator, Type operand) {
23072309
int opc = ((OperatorSymbol)operator).opcode;
23082310
if (opc == ByteCodes.idiv || opc == ByteCodes.imod
23092311
|| opc == ByteCodes.ldiv || opc == ByteCodes.lmod) {
2310-
log.warning(pos, "div.zero");
2312+
log.warning(Lint.LintCategory.DIVZERO, pos, "div.zero");
23112313
}
23122314
}
23132315
}
@@ -2317,7 +2319,7 @@ void checkDivZero(DiagnosticPosition pos, Symbol operator, Type operand) {
23172319
*/
23182320
void checkEmptyIf(JCIf tree) {
23192321
if (tree.thenpart.getTag() == JCTree.SKIP && tree.elsepart == null && lint.isEnabled(Lint.LintCategory.EMPTY))
2320-
log.warning(tree.thenpart.pos(), "empty.if");
2322+
log.warning(Lint.LintCategory.EMPTY, tree.thenpart.pos(), "empty.if");
23212323
}
23222324

23232325
/** Check that symbol is unique in given scope.

langtools/src/share/classes/com/sun/tools/javac/comp/Flow.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,8 @@ public void visitSwitch(JCSwitch tree) {
942942
alive &&
943943
lint.isEnabled(Lint.LintCategory.FALLTHROUGH) &&
944944
c.stats.nonEmpty() && l.tail.nonEmpty())
945-
log.warning(l.tail.head.pos(),
945+
log.warning(Lint.LintCategory.FALLTHROUGH,
946+
l.tail.head.pos(),
946947
"possible.fall-through.into.case");
947948
}
948949
if (!hasDefault) {
@@ -1081,8 +1082,9 @@ public void visitTry(JCTry tree) {
10811082
thrown = chk.union(thrown, thrownPrev);
10821083
if (!loopPassTwo &&
10831084
lint.isEnabled(Lint.LintCategory.FINALLY)) {
1084-
log.warning(TreeInfo.diagEndPos(tree.finalizer),
1085-
"finally.cannot.complete");
1085+
log.warning(Lint.LintCategory.FINALLY,
1086+
TreeInfo.diagEndPos(tree.finalizer),
1087+
"finally.cannot.complete");
10861088
}
10871089
} else {
10881090
thrown = chk.union(thrown, chk.diff(thrownInTry, caughtInTry));
@@ -1353,7 +1355,8 @@ public void visitTypeCast(JCTypeCast tree) {
13531355
&& lint.isEnabled(Lint.LintCategory.CAST)
13541356
&& types.isSameType(tree.expr.type, tree.clazz.type)
13551357
&& !(ignoreAnnotatedCasts && containsTypeAnnotation(tree.clazz))) {
1356-
log.warning(tree.pos(), "redundant.cast", tree.expr.type);
1358+
log.warning(Lint.LintCategory.CAST,
1359+
tree.pos(), "redundant.cast", tree.expr.type);
13571360
}
13581361
}
13591362

langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1797,13 +1797,13 @@ JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind,
17971797
return null;
17981798

17991799
if (isOperator(name)) {
1800-
return diags.create(dkind, false, log.currentSource(), pos,
1800+
return diags.create(dkind, log.currentSource(), pos,
18011801
"operator.cant.be.applied", name, argtypes);
18021802
}
18031803
boolean hasLocation = false;
18041804
if (!site.tsym.name.isEmpty()) {
18051805
if (site.tsym.kind == PCK && !site.tsym.exists()) {
1806-
return diags.create(dkind, false, log.currentSource(), pos,
1806+
return diags.create(dkind, log.currentSource(), pos,
18071807
"doesnt.exist", site.tsym);
18081808
}
18091809
hasLocation = true;
@@ -1814,13 +1814,13 @@ JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind,
18141814
Name idname = isConstructor ? site.tsym.name : name;
18151815
String errKey = getErrorKey(kindname, typeargtypes.nonEmpty(), hasLocation);
18161816
if (hasLocation) {
1817-
return diags.create(dkind, false, log.currentSource(), pos,
1817+
return diags.create(dkind, log.currentSource(), pos,
18181818
errKey, kindname, idname, //symbol kindname, name
18191819
typeargtypes, argtypes, //type parameters and arguments (if any)
18201820
typeKindName(site), site); //location kindname, type
18211821
}
18221822
else {
1823-
return diags.create(dkind, false, log.currentSource(), pos,
1823+
return diags.create(dkind, log.currentSource(), pos,
18241824
errKey, kindname, idname, //symbol kindname, name
18251825
typeargtypes, argtypes); //type parameters and arguments (if any)
18261826
}
@@ -1886,12 +1886,12 @@ JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind,
18861886
return null;
18871887

18881888
if (isOperator(name)) {
1889-
return diags.create(dkind, false, log.currentSource(),
1889+
return diags.create(dkind, log.currentSource(),
18901890
pos, "operator.cant.be.applied", name, argtypes);
18911891
}
18921892
else {
18931893
Symbol ws = sym.asMemberOf(site, types);
1894-
return diags.create(dkind, false, log.currentSource(), pos,
1894+
return diags.create(dkind, log.currentSource(), pos,
18951895
"cant.apply.symbol" + (explanation != null ? ".1" : ""),
18961896
kindName(ws),
18971897
ws.name == names.init ? ws.owner.name : ws.name,
@@ -1974,18 +1974,18 @@ JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind,
19741974
else if ((sym.flags() & PUBLIC) != 0
19751975
|| (env != null && this.site != null
19761976
&& !isAccessible(env, this.site))) {
1977-
return diags.create(dkind, false, log.currentSource(),
1977+
return diags.create(dkind, log.currentSource(),
19781978
pos, "not.def.access.class.intf.cant.access",
19791979
sym, sym.location());
19801980
}
19811981
else if ((sym.flags() & (PRIVATE | PROTECTED)) != 0) {
1982-
return diags.create(dkind, false, log.currentSource(),
1982+
return diags.create(dkind, log.currentSource(),
19831983
pos, "report.access", sym,
19841984
asFlagSet(sym.flags() & (PRIVATE | PROTECTED)),
19851985
sym.location());
19861986
}
19871987
else {
1988-
return diags.create(dkind, false, log.currentSource(),
1988+
return diags.create(dkind, log.currentSource(),
19891989
pos, "not.def.public.cant.access", sym, sym.location());
19901990
}
19911991
}
@@ -2011,7 +2011,7 @@ JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind,
20112011
Symbol errSym = ((sym.kind == TYP && sym.type.tag == CLASS)
20122012
? types.erasure(sym.type).tsym
20132013
: sym);
2014-
return diags.create(dkind, false, log.currentSource(), pos,
2014+
return diags.create(dkind, log.currentSource(), pos,
20152015
"non-static.cant.be.ref", kindName(sym), errSym);
20162016
}
20172017
}
@@ -2048,7 +2048,7 @@ else if (pair.sym2.kind == AMBIGUOUS)
20482048
}
20492049
Name sname = pair.sym.name;
20502050
if (sname == names.init) sname = pair.sym.owner.name;
2051-
return diags.create(dkind, false, log.currentSource(),
2051+
return diags.create(dkind, log.currentSource(),
20522052
pos, "ref.ambiguous", sname,
20532053
kindName(pair.sym),
20542054
pair.sym,

langtools/src/share/classes/com/sun/tools/javac/file/Paths.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,8 @@ public Path addDirectories(String dirs) {
246246
private void addDirectory(File dir, boolean warn) {
247247
if (!dir.isDirectory()) {
248248
if (warn)
249-
log.warning("dir.path.element.not.found", dir);
249+
log.warning(Lint.LintCategory.PATH,
250+
"dir.path.element.not.found", dir);
250251
return;
251252
}
252253

@@ -280,8 +281,10 @@ public void addFile(File file, boolean warn) {
280281

281282
if (! fsInfo.exists(file)) {
282283
/* No such file or directory exists */
283-
if (warn)
284-
log.warning("path.element.not.found", file);
284+
if (warn) {
285+
log.warning(Lint.LintCategory.PATH,
286+
"path.element.not.found", file);
287+
}
285288
} else if (fsInfo.isFile(file)) {
286289
/* File is an ordinary file. */
287290
if (!isArchive(file)) {
@@ -290,12 +293,16 @@ public void addFile(File file, boolean warn) {
290293
try {
291294
ZipFile z = new ZipFile(file);
292295
z.close();
293-
if (warn)
294-
log.warning("unexpected.archive.file", file);
296+
if (warn) {
297+
log.warning(Lint.LintCategory.PATH,
298+
"unexpected.archive.file", file);
299+
}
295300
} catch (IOException e) {
296301
// FIXME: include e.getLocalizedMessage in warning
297-
if (warn)
298-
log.warning("invalid.archive.file", file);
302+
if (warn) {
303+
log.warning(Lint.LintCategory.PATH,
304+
"invalid.archive.file", file);
305+
}
299306
return;
300307
}
301308
}

0 commit comments

Comments
 (0)