Skip to content

Commit

Permalink
6957438: improve code for generating warning messages containing opti…
Browse files Browse the repository at this point in the history
…on names

Reviewed-by: mcimadamore
  • Loading branch information
jonathan-gibbons committed Jul 26, 2010
1 parent ccd014e commit 1c75e97
Show file tree
Hide file tree
Showing 15 changed files with 263 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ protected Lint(Lint other) {
this.suppressedValues = other.suppressedValues.clone();
}

@Override
public String toString() {
return "Lint:[values" + values + " suppressedValues" + suppressedValues + "]";
}
Expand Down
12 changes: 8 additions & 4 deletions langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java
Original file line number Diff line number Diff line change
Expand Up @@ -3111,23 +3111,27 @@ private void checkSerialVersionUID(JCClassDecl tree, ClassSymbol c) {
Scope.Entry e = c.members().lookup(names.serialVersionUID);
while (e.scope != null && e.sym.kind != VAR) e = e.next();
if (e.scope == null) {
log.warning(tree.pos(), "missing.SVUID", c);
log.warning(Lint.LintCategory.SERIAL,
tree.pos(), "missing.SVUID", c);
return;
}

// check that it is static final
VarSymbol svuid = (VarSymbol)e.sym;
if ((svuid.flags() & (STATIC | FINAL)) !=
(STATIC | FINAL))
log.warning(TreeInfo.diagnosticPositionFor(svuid, tree), "improper.SVUID", c);
log.warning(Lint.LintCategory.SERIAL,
TreeInfo.diagnosticPositionFor(svuid, tree), "improper.SVUID", c);

// check that it is long
else if (svuid.type.tag != TypeTags.LONG)
log.warning(TreeInfo.diagnosticPositionFor(svuid, tree), "long.SVUID", c);
log.warning(Lint.LintCategory.SERIAL,
TreeInfo.diagnosticPositionFor(svuid, tree), "long.SVUID", c);

// check constant
else if (svuid.getConstValue() == null)
log.warning(TreeInfo.diagnosticPositionFor(svuid, tree), "constant.SVUID", c);
log.warning(Lint.LintCategory.SERIAL,
TreeInfo.diagnosticPositionFor(svuid, tree), "constant.SVUID", c);
}

private Type capture(Type type) {
Expand Down
20 changes: 11 additions & 9 deletions langtools/src/share/classes/com/sun/tools/javac/comp/Check.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ protected Check(Context context) {
boolean enforceMandatoryWarnings = source.enforceMandatoryWarnings();

deprecationHandler = new MandatoryWarningHandler(log, verboseDeprecated,
enforceMandatoryWarnings, "deprecated");
enforceMandatoryWarnings, "deprecated", LintCategory.DEPRECATION);
uncheckedHandler = new MandatoryWarningHandler(log, verboseUnchecked,
enforceMandatoryWarnings, "unchecked");
enforceMandatoryWarnings, "unchecked", LintCategory.UNCHECKED);
unsafeVarargsHandler = new MandatoryWarningHandler(log, verboseVarargs,
enforceMandatoryWarnings, "varargs");
enforceMandatoryWarnings, "varargs", LintCategory.VARARGS);
sunApiHandler = new MandatoryWarningHandler(log, verboseSunApi,
enforceMandatoryWarnings, "sunapi");
enforceMandatoryWarnings, "sunapi", null);
}

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

public void warnStatic(DiagnosticPosition pos, String msg, Object... args) {
if (lint.isEnabled(LintCategory.STATIC))
log.warning(pos, msg, args);
log.warning(LintCategory.STATIC, pos, msg, args);
}

/**
Expand Down Expand Up @@ -929,7 +929,8 @@ void checkRaw(JCTree tree, Env<AttrContext> env) {
!TreeInfo.isDiamond(tree) &&
!env.enclClass.name.isEmpty() && //anonymous or intersection
tree.type.isRaw()) {
log.warning(tree.pos(), "raw.class.use", tree.type, tree.type.tsym.type);
log.warning(Lint.LintCategory.RAW,
tree.pos(), "raw.class.use", tree.type, tree.type.tsym.type);
}
}

Expand Down Expand Up @@ -2156,7 +2157,8 @@ void checkDeprecatedAnnotation(DiagnosticPosition pos, Symbol s) {
(s.flags() & DEPRECATED) != 0 &&
!syms.deprecatedType.isErroneous() &&
s.attribute(syms.deprecatedType.tsym) == null) {
log.warning(pos, "missing.deprecated.annotation");
log.warning(Lint.LintCategory.DEP_ANN,
pos, "missing.deprecated.annotation");
}
}

Expand Down Expand Up @@ -2307,7 +2309,7 @@ void checkDivZero(DiagnosticPosition pos, Symbol operator, Type operand) {
int opc = ((OperatorSymbol)operator).opcode;
if (opc == ByteCodes.idiv || opc == ByteCodes.imod
|| opc == ByteCodes.ldiv || opc == ByteCodes.lmod) {
log.warning(pos, "div.zero");
log.warning(Lint.LintCategory.DIVZERO, pos, "div.zero");
}
}
}
Expand All @@ -2317,7 +2319,7 @@ void checkDivZero(DiagnosticPosition pos, Symbol operator, Type operand) {
*/
void checkEmptyIf(JCIf tree) {
if (tree.thenpart.getTag() == JCTree.SKIP && tree.elsepart == null && lint.isEnabled(Lint.LintCategory.EMPTY))
log.warning(tree.thenpart.pos(), "empty.if");
log.warning(Lint.LintCategory.EMPTY, tree.thenpart.pos(), "empty.if");
}

/** Check that symbol is unique in given scope.
Expand Down
11 changes: 7 additions & 4 deletions langtools/src/share/classes/com/sun/tools/javac/comp/Flow.java
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,8 @@ public void visitSwitch(JCSwitch tree) {
alive &&
lint.isEnabled(Lint.LintCategory.FALLTHROUGH) &&
c.stats.nonEmpty() && l.tail.nonEmpty())
log.warning(l.tail.head.pos(),
log.warning(Lint.LintCategory.FALLTHROUGH,
l.tail.head.pos(),
"possible.fall-through.into.case");
}
if (!hasDefault) {
Expand Down Expand Up @@ -1081,8 +1082,9 @@ public void visitTry(JCTry tree) {
thrown = chk.union(thrown, thrownPrev);
if (!loopPassTwo &&
lint.isEnabled(Lint.LintCategory.FINALLY)) {
log.warning(TreeInfo.diagEndPos(tree.finalizer),
"finally.cannot.complete");
log.warning(Lint.LintCategory.FINALLY,
TreeInfo.diagEndPos(tree.finalizer),
"finally.cannot.complete");
}
} else {
thrown = chk.union(thrown, chk.diff(thrownInTry, caughtInTry));
Expand Down Expand Up @@ -1353,7 +1355,8 @@ public void visitTypeCast(JCTypeCast tree) {
&& lint.isEnabled(Lint.LintCategory.CAST)
&& types.isSameType(tree.expr.type, tree.clazz.type)
&& !(ignoreAnnotatedCasts && containsTypeAnnotation(tree.clazz))) {
log.warning(tree.pos(), "redundant.cast", tree.expr.type);
log.warning(Lint.LintCategory.CAST,
tree.pos(), "redundant.cast", tree.expr.type);
}
}

Expand Down
22 changes: 11 additions & 11 deletions langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java
Original file line number Diff line number Diff line change
Expand Up @@ -1797,13 +1797,13 @@ JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind,
return null;

if (isOperator(name)) {
return diags.create(dkind, false, log.currentSource(), pos,
return diags.create(dkind, log.currentSource(), pos,
"operator.cant.be.applied", name, argtypes);
}
boolean hasLocation = false;
if (!site.tsym.name.isEmpty()) {
if (site.tsym.kind == PCK && !site.tsym.exists()) {
return diags.create(dkind, false, log.currentSource(), pos,
return diags.create(dkind, log.currentSource(), pos,
"doesnt.exist", site.tsym);
}
hasLocation = true;
Expand All @@ -1814,13 +1814,13 @@ JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind,
Name idname = isConstructor ? site.tsym.name : name;
String errKey = getErrorKey(kindname, typeargtypes.nonEmpty(), hasLocation);
if (hasLocation) {
return diags.create(dkind, false, log.currentSource(), pos,
return diags.create(dkind, log.currentSource(), pos,
errKey, kindname, idname, //symbol kindname, name
typeargtypes, argtypes, //type parameters and arguments (if any)
typeKindName(site), site); //location kindname, type
}
else {
return diags.create(dkind, false, log.currentSource(), pos,
return diags.create(dkind, log.currentSource(), pos,
errKey, kindname, idname, //symbol kindname, name
typeargtypes, argtypes); //type parameters and arguments (if any)
}
Expand Down Expand Up @@ -1886,12 +1886,12 @@ JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind,
return null;

if (isOperator(name)) {
return diags.create(dkind, false, log.currentSource(),
return diags.create(dkind, log.currentSource(),
pos, "operator.cant.be.applied", name, argtypes);
}
else {
Symbol ws = sym.asMemberOf(site, types);
return diags.create(dkind, false, log.currentSource(), pos,
return diags.create(dkind, log.currentSource(), pos,
"cant.apply.symbol" + (explanation != null ? ".1" : ""),
kindName(ws),
ws.name == names.init ? ws.owner.name : ws.name,
Expand Down Expand Up @@ -1974,18 +1974,18 @@ JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind,
else if ((sym.flags() & PUBLIC) != 0
|| (env != null && this.site != null
&& !isAccessible(env, this.site))) {
return diags.create(dkind, false, log.currentSource(),
return diags.create(dkind, log.currentSource(),
pos, "not.def.access.class.intf.cant.access",
sym, sym.location());
}
else if ((sym.flags() & (PRIVATE | PROTECTED)) != 0) {
return diags.create(dkind, false, log.currentSource(),
return diags.create(dkind, log.currentSource(),
pos, "report.access", sym,
asFlagSet(sym.flags() & (PRIVATE | PROTECTED)),
sym.location());
}
else {
return diags.create(dkind, false, log.currentSource(),
return diags.create(dkind, log.currentSource(),
pos, "not.def.public.cant.access", sym, sym.location());
}
}
Expand All @@ -2011,7 +2011,7 @@ JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind,
Symbol errSym = ((sym.kind == TYP && sym.type.tag == CLASS)
? types.erasure(sym.type).tsym
: sym);
return diags.create(dkind, false, log.currentSource(), pos,
return diags.create(dkind, log.currentSource(), pos,
"non-static.cant.be.ref", kindName(sym), errSym);
}
}
Expand Down Expand Up @@ -2048,7 +2048,7 @@ else if (pair.sym2.kind == AMBIGUOUS)
}
Name sname = pair.sym.name;
if (sname == names.init) sname = pair.sym.owner.name;
return diags.create(dkind, false, log.currentSource(),
return diags.create(dkind, log.currentSource(),
pos, "ref.ambiguous", sname,
kindName(pair.sym),
pair.sym,
Expand Down
21 changes: 14 additions & 7 deletions langtools/src/share/classes/com/sun/tools/javac/file/Paths.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ public Path addDirectories(String dirs) {
private void addDirectory(File dir, boolean warn) {
if (!dir.isDirectory()) {
if (warn)
log.warning("dir.path.element.not.found", dir);
log.warning(Lint.LintCategory.PATH,
"dir.path.element.not.found", dir);
return;
}

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

if (! fsInfo.exists(file)) {
/* No such file or directory exists */
if (warn)
log.warning("path.element.not.found", file);
if (warn) {
log.warning(Lint.LintCategory.PATH,
"path.element.not.found", file);
}
} else if (fsInfo.isFile(file)) {
/* File is an ordinary file. */
if (!isArchive(file)) {
Expand All @@ -290,12 +293,16 @@ public void addFile(File file, boolean warn) {
try {
ZipFile z = new ZipFile(file);
z.close();
if (warn)
log.warning("unexpected.archive.file", file);
if (warn) {
log.warning(Lint.LintCategory.PATH,
"unexpected.archive.file", file);
}
} catch (IOException e) {
// FIXME: include e.getLocalizedMessage in warning
if (warn)
log.warning("invalid.archive.file", file);
if (warn) {
log.warning(Lint.LintCategory.PATH,
"invalid.archive.file", file);
}
return;
}
}
Expand Down
Loading

0 comments on commit 1c75e97

Please sign in to comment.