Skip to content

Commit

Permalink
Add missing lint categories in compiler.properties
Browse files Browse the repository at this point in the history
Simplify some lambda expressions
Simplify Lint::logIfEnabled by accepting a log parameter
  • Loading branch information
mcimadamore committed Dec 5, 2024
1 parent 9a657f2 commit 64883bb
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ public Lint suppress(LintCategory... lc) {
return l;
}

private final Log log;
private final AugmentVisitor augmentor;

private final EnumSet<LintCategory> values;
Expand Down Expand Up @@ -150,14 +149,12 @@ protected Lint(Context context) {

context.put(lintKey, this);
augmentor = new AugmentVisitor(context);
log = Log.instance(context);
}

protected Lint(Lint other) {
this.augmentor = other.augmentor;
this.values = other.values.clone();
this.suppressedValues = other.suppressedValues.clone();
this.log = other.log;
}

@Override
Expand Down Expand Up @@ -394,7 +391,7 @@ public boolean isSuppressed(LintCategory lc) {
/**
* Helper method. Log a lint warning if its lint category is enabled.
*/
public void logIfEnabled(DiagnosticPosition pos, LintWarning warning) {
public void logIfEnabled(Log log, DiagnosticPosition pos, LintWarning warning) {
if (isEnabled(warning.getLintCategory())) {
log.warning(pos, warning);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1940,7 +1940,7 @@ private Symbol enumConstant(JCTree tree, Type enumType) {
public void visitSynchronized(JCSynchronized tree) {
chk.checkRefType(tree.pos(), attribExpr(tree.lock, env));
if (isValueBased(tree.lock.type)) {
env.info.lint.logIfEnabled(tree.pos(), LintWarnings.AttemptToSynchronizeOnInstanceOfValueBasedClass);
env.info.lint.logIfEnabled(log, tree.pos(), LintWarnings.AttemptToSynchronizeOnInstanceOfValueBasedClass);
}
attribStat(tree.body, env);
result = null;
Expand Down Expand Up @@ -2047,7 +2047,7 @@ void checkAutoCloseable(DiagnosticPosition pos, Env<AttrContext> env, Type resou
if (close.kind == MTH &&
close.overrides(syms.autoCloseableClose, resource.tsym, types, true) &&
chk.isHandled(syms.interruptedExceptionType, types.memberType(resource, close).getThrownTypes())) {
env.info.lint.logIfEnabled(pos, LintWarnings.TryResourceThrowsInterruptedExc(resource));
env.info.lint.logIfEnabled(log, pos, LintWarnings.TryResourceThrowsInterruptedExc(resource));
}
}
}
Expand Down Expand Up @@ -4442,7 +4442,7 @@ public void visitSelect(JCFieldAccess tree) {
sym.kind == MTH &&
sym.name.equals(names.close) &&
sym.overrides(syms.autoCloseableClose, sitesym.type.tsym, types, true)) {
env.info.lint.logIfEnabled(tree, LintWarnings.TryExplicitCloseCall);
env.info.lint.logIfEnabled(log, tree, LintWarnings.TryExplicitCloseCall);
}

// Disallow selecting a type from an expression
Expand All @@ -4469,9 +4469,9 @@ public void visitSelect(JCFieldAccess tree) {
// If the qualified item is not a type and the selected item is static, report
// a warning. Make allowance for the class of an array type e.g. Object[].class)
if (!sym.owner.isAnonymous()) {
chk.lint.logIfEnabled(tree, LintWarnings.StaticNotQualifiedByType(sym.kind.kindName(), sym.owner));
chk.lint.logIfEnabled(log, tree, LintWarnings.StaticNotQualifiedByType(sym.kind.kindName(), sym.owner));
} else {
chk.lint.logIfEnabled(tree, LintWarnings.StaticNotQualifiedByType2(sym.kind.kindName()));
chk.lint.logIfEnabled(log, tree, LintWarnings.StaticNotQualifiedByType2(sym.kind.kindName()));
}
}

Expand Down
Loading

0 comments on commit 64883bb

Please sign in to comment.