Skip to content

Commit 89e5e7a

Browse files
committed
8349155: The "log" parameter to Lint.logIfEnabled() is not needed
Reviewed-by: mcimadamore
1 parent aad6664 commit 89e5e7a

File tree

8 files changed

+47
-46
lines changed

8 files changed

+47
-46
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ public Lint suppress(LintCategory... lc) {
109109

110110
private final Context context;
111111
private final Options options;
112+
private final Log log;
112113

113114
// These are initialized lazily to avoid dependency loops
114115
private Symtab syms;
@@ -125,13 +126,15 @@ protected Lint(Context context) {
125126
this.context = context;
126127
context.put(lintKey, this);
127128
options = Options.instance(context);
129+
log = Log.instance(context);
128130
}
129131

130132
// Instantiate a non-root ("symbol scoped") instance
131133
protected Lint(Lint other) {
132134
other.initializeRootIfNeeded();
133135
this.context = other.context;
134136
this.options = other.options;
137+
this.log = other.log;
135138
this.syms = other.syms;
136139
this.names = other.names;
137140
this.values = other.values.clone();
@@ -434,21 +437,19 @@ public boolean isSuppressed(LintCategory lc) {
434437
/**
435438
* Helper method. Log a lint warning if its lint category is enabled.
436439
*
437-
* @param log warning destination
438440
* @param warning key for the localized warning message
439441
*/
440-
public void logIfEnabled(Log log, LintWarning warning) {
441-
logIfEnabled(log, null, warning);
442+
public void logIfEnabled(LintWarning warning) {
443+
logIfEnabled(null, warning);
442444
}
443445

444446
/**
445447
* Helper method. Log a lint warning if its lint category is enabled.
446448
*
447-
* @param log warning destination
448449
* @param pos source position at which to report the warning
449450
* @param warning key for the localized warning message
450451
*/
451-
public void logIfEnabled(Log log, DiagnosticPosition pos, LintWarning warning) {
452+
public void logIfEnabled(DiagnosticPosition pos, LintWarning warning) {
452453
if (isEnabled(warning.getLintCategory())) {
453454
log.warning(pos, warning);
454455
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1949,7 +1949,7 @@ private Symbol enumConstant(JCTree tree, Type enumType) {
19491949
public void visitSynchronized(JCSynchronized tree) {
19501950
chk.checkRefType(tree.pos(), attribExpr(tree.lock, env));
19511951
if (isValueBased(tree.lock.type)) {
1952-
env.info.lint.logIfEnabled(log, tree.pos(), LintWarnings.AttemptToSynchronizeOnInstanceOfValueBasedClass);
1952+
env.info.lint.logIfEnabled(tree.pos(), LintWarnings.AttemptToSynchronizeOnInstanceOfValueBasedClass);
19531953
}
19541954
attribStat(tree.body, env);
19551955
result = null;
@@ -2056,7 +2056,7 @@ void checkAutoCloseable(DiagnosticPosition pos, Env<AttrContext> env, Type resou
20562056
if (close.kind == MTH &&
20572057
close.overrides(syms.autoCloseableClose, resource.tsym, types, true) &&
20582058
chk.isHandled(syms.interruptedExceptionType, types.memberType(resource, close).getThrownTypes())) {
2059-
env.info.lint.logIfEnabled(log, pos, LintWarnings.TryResourceThrowsInterruptedExc(resource));
2059+
env.info.lint.logIfEnabled(pos, LintWarnings.TryResourceThrowsInterruptedExc(resource));
20602060
}
20612061
}
20622062
}
@@ -4456,7 +4456,7 @@ public void visitSelect(JCFieldAccess tree) {
44564456
sym.kind == MTH &&
44574457
sym.name.equals(names.close) &&
44584458
sym.overrides(syms.autoCloseableClose, sitesym.type.tsym, types, true)) {
4459-
env.info.lint.logIfEnabled(log, tree, LintWarnings.TryExplicitCloseCall);
4459+
env.info.lint.logIfEnabled(tree, LintWarnings.TryExplicitCloseCall);
44604460
}
44614461

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

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ public void warnDeclaredUsingPreview(DiagnosticPosition pos, Symbol sym) {
285285
* @param msg A Warning describing the problem.
286286
*/
287287
public void warnRestrictedAPI(DiagnosticPosition pos, Symbol sym) {
288-
lint.logIfEnabled(log, pos, LintWarnings.RestrictedMethod(sym.enclClass(), sym));
288+
lint.logIfEnabled(pos, LintWarnings.RestrictedMethod(sym.enclClass(), sym));
289289
}
290290

291291
/** Warn about unchecked operation.
@@ -649,7 +649,7 @@ public void checkRedundantCast(Env<AttrContext> env, final JCTypeCast tree) {
649649
&& !(ignoreAnnotatedCasts && TreeInfo.containsTypeAnnotation(tree.clazz))
650650
&& !is292targetTypeCast(tree)) {
651651
deferredLintHandler.report(_l -> {
652-
lint.logIfEnabled(log, tree.pos(), LintWarnings.RedundantCast(tree.clazz.type));
652+
lint.logIfEnabled(tree.pos(), LintWarnings.RedundantCast(tree.clazz.type));
653653
});
654654
}
655655
}
@@ -954,7 +954,7 @@ void checkVarargsMethodDecl(Env<AttrContext> env, JCMethodDecl tree) {
954954
}
955955
} else if (hasTrustMeAnno && varargElemType != null &&
956956
types.isReifiable(varargElemType)) {
957-
lint.logIfEnabled(log, tree, LintWarnings.VarargsRedundantTrustmeAnno(
957+
lint.logIfEnabled(tree, LintWarnings.VarargsRedundantTrustmeAnno(
958958
syms.trustMeType.tsym,
959959
diags.fragment(Fragments.VarargsTrustmeOnReifiableVarargs(varargElemType))));
960960
}
@@ -1323,7 +1323,7 @@ && checkDisjoint(pos, flags,
13231323
private void warnOnExplicitStrictfp(DiagnosticPosition pos) {
13241324
DiagnosticPosition prevLintPos = deferredLintHandler.setPos(pos);
13251325
try {
1326-
deferredLintHandler.report(_ -> lint.logIfEnabled(log, pos, LintWarnings.Strictfp));
1326+
deferredLintHandler.report(_ -> lint.logIfEnabled(pos, LintWarnings.Strictfp));
13271327
} finally {
13281328
deferredLintHandler.setPos(prevLintPos);
13291329
}
@@ -1542,7 +1542,7 @@ void checkRaw(JCTree tree, Env<AttrContext> env) {
15421542
!TreeInfo.isDiamond(tree) &&
15431543
!withinAnonConstr(env) &&
15441544
tree.type.isRaw()) {
1545-
lint.logIfEnabled(log, tree.pos(), LintWarnings.RawClassUse(tree.type, tree.type.tsym.type));
1545+
lint.logIfEnabled(tree.pos(), LintWarnings.RawClassUse(tree.type, tree.type.tsym.type));
15461546
}
15471547
}
15481548
//where
@@ -1866,7 +1866,7 @@ else if (unhandledUnerased.nonEmpty()) {
18661866

18671867
// Optional warning if varargs don't agree
18681868
if ((((m.flags() ^ other.flags()) & Flags.VARARGS) != 0)) {
1869-
lint.logIfEnabled(log, TreeInfo.diagnosticPositionFor(m, tree),
1869+
lint.logIfEnabled(TreeInfo.diagnosticPositionFor(m, tree),
18701870
((m.flags() & Flags.VARARGS) != 0)
18711871
? LintWarnings.OverrideVarargsMissing(varargsOverrides(m, other))
18721872
: LintWarnings.OverrideVarargsExtra(varargsOverrides(m, other)));
@@ -4121,7 +4121,7 @@ void checkDivZero(final DiagnosticPosition pos, Symbol operator, Type operand) {
41214121
int opc = ((OperatorSymbol)operator).opcode;
41224122
if (opc == ByteCodes.idiv || opc == ByteCodes.imod
41234123
|| opc == ByteCodes.ldiv || opc == ByteCodes.lmod) {
4124-
deferredLintHandler.report(_ -> lint.logIfEnabled(log, pos, LintWarnings.DivZero));
4124+
deferredLintHandler.report(_ -> lint.logIfEnabled(pos, LintWarnings.DivZero));
41254125
}
41264126
}
41274127
}
@@ -4135,7 +4135,7 @@ void checkDivZero(final DiagnosticPosition pos, Symbol operator, Type operand) {
41354135
void checkLossOfPrecision(final DiagnosticPosition pos, Type found, Type req) {
41364136
if (found.isNumeric() && req.isNumeric() && !types.isAssignable(found, req)) {
41374137
deferredLintHandler.report(_ ->
4138-
lint.logIfEnabled(log, pos, LintWarnings.PossibleLossOfPrecision(found, req)));
4138+
lint.logIfEnabled(pos, LintWarnings.PossibleLossOfPrecision(found, req)));
41394139
}
41404140
}
41414141

@@ -4144,7 +4144,7 @@ void checkLossOfPrecision(final DiagnosticPosition pos, Type found, Type req) {
41444144
*/
41454145
void checkEmptyIf(JCIf tree) {
41464146
if (tree.thenpart.hasTag(SKIP) && tree.elsepart == null) {
4147-
lint.logIfEnabled(log, tree.thenpart.pos(), LintWarnings.EmptyIf);
4147+
lint.logIfEnabled(tree.thenpart.pos(), LintWarnings.EmptyIf);
41484148
}
41494149
}
41504150

@@ -4291,7 +4291,7 @@ void checkForBadAuxiliaryClassAccess(DiagnosticPosition pos, Env<AttrContext> en
42914291
rs.isAccessible(env, c) &&
42924292
!fileManager.isSameFile(c.sourcefile, env.toplevel.sourcefile))
42934293
{
4294-
lint.logIfEnabled(log, pos,
4294+
lint.logIfEnabled(pos,
42954295
LintWarnings.AuxiliaryClassAccessedFromOutsideOfItsSourceFile(c, c.sourcefile));
42964296
}
42974297
}
@@ -4335,7 +4335,7 @@ void checkDefaultConstructor(ClassSymbol c, DiagnosticPosition pos) {
43354335
// annotations; check again for being
43364336
// enabled in the deferred context.
43374337
deferredLintHandler.report(_ ->
4338-
lint.logIfEnabled(log, pos, LintWarnings.MissingExplicitCtor(c, pkg, modle)));
4338+
lint.logIfEnabled(pos, LintWarnings.MissingExplicitCtor(c, pkg, modle)));
43394339
} else {
43404340
return;
43414341
}
@@ -4371,7 +4371,7 @@ public void warn(LintCategory lint) {
43714371
method.attribute(syms.trustMeType.tsym) != null &&
43724372
isTrustMeAllowedOnMethod(method) &&
43734373
!types.isReifiable(method.type.getParameterTypes().last())) {
4374-
Check.this.lint.logIfEnabled(log, pos(), LintWarnings.VarargsUnsafeUseVarargsParam(method.params.last()));
4374+
Check.this.lint.logIfEnabled(pos(), LintWarnings.VarargsUnsafeUseVarargsParam(method.params.last()));
43754375
}
43764376
break;
43774377
default:
@@ -4670,15 +4670,15 @@ private void checkVisible(DiagnosticPosition pos, Symbol what, PackageSymbol inP
46704670
void checkModuleExists(final DiagnosticPosition pos, ModuleSymbol msym) {
46714671
if (msym.kind != MDL) {
46724672
deferredLintHandler.report(_ ->
4673-
lint.logIfEnabled(log, pos, LintWarnings.ModuleNotFound(msym)));
4673+
lint.logIfEnabled(pos, LintWarnings.ModuleNotFound(msym)));
46744674
}
46754675
}
46764676

46774677
void checkPackageExistsForOpens(final DiagnosticPosition pos, PackageSymbol packge) {
46784678
if (packge.members().isEmpty() &&
46794679
((packge.flags() & Flags.HAS_RESOURCE) == 0)) {
46804680
deferredLintHandler.report(_ ->
4681-
lint.logIfEnabled(log, pos, LintWarnings.PackageEmptyOrNotFound(packge)));
4681+
lint.logIfEnabled(pos, LintWarnings.PackageEmptyOrNotFound(packge)));
46824682
}
46834683
}
46844684

@@ -4688,7 +4688,7 @@ void checkModuleRequires(final DiagnosticPosition pos, final RequiresDirective r
46884688
if (rd.isTransitive() && lint.isEnabled(LintCategory.REQUIRES_TRANSITIVE_AUTOMATIC)) {
46894689
log.warning(pos, LintWarnings.RequiresTransitiveAutomatic);
46904690
} else {
4691-
lint.logIfEnabled(log, pos, LintWarnings.RequiresAutomatic);
4691+
lint.logIfEnabled(pos, LintWarnings.RequiresAutomatic);
46924692
}
46934693
});
46944694
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ public void visitSwitch(JCSwitch tree) {
724724
// Warn about fall-through if lint switch fallthrough enabled.
725725
if (alive == Liveness.ALIVE &&
726726
c.stats.nonEmpty() && l.tail.nonEmpty())
727-
lint.logIfEnabled(log, l.tail.head.pos(),
727+
lint.logIfEnabled(l.tail.head.pos(),
728728
LintWarnings.PossibleFallThroughIntoCase);
729729
}
730730
tree.isExhaustive = tree.hasUnconditionalPattern ||
@@ -1232,7 +1232,7 @@ public void visitTry(JCTry tree) {
12321232
scanStat(tree.finalizer);
12331233
tree.finallyCanCompleteNormally = alive != Liveness.DEAD;
12341234
if (alive == Liveness.DEAD) {
1235-
lint.logIfEnabled(log, TreeInfo.diagEndPos(tree.finalizer),
1235+
lint.logIfEnabled(TreeInfo.diagEndPos(tree.finalizer),
12361236
LintWarnings.FinallyCannotComplete);
12371237
} else {
12381238
while (exits.nonEmpty()) {

src/jdk.compiler/share/classes/com/sun/tools/javac/file/Locations.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ private Iterable<Path> getPathEntries(String searchPath, Path emptyPathDefault)
225225
try {
226226
entries.add(getPath(s));
227227
} catch (IllegalArgumentException e) {
228-
lint.logIfEnabled(log, LintWarnings.InvalidPath(s));
228+
lint.logIfEnabled(LintWarnings.InvalidPath(s));
229229
}
230230
}
231231
}
@@ -319,7 +319,7 @@ public SearchPath addDirectories(String dirs) {
319319
private void addDirectory(Path dir, boolean warn) {
320320
if (!Files.isDirectory(dir)) {
321321
if (warn) {
322-
lint.logIfEnabled(log, LintWarnings.DirPathElementNotFound(dir));
322+
lint.logIfEnabled(LintWarnings.DirPathElementNotFound(dir));
323323
}
324324
return;
325325
}
@@ -364,7 +364,7 @@ public void addFile(Path file, boolean warn) {
364364
if (!fsInfo.exists(file)) {
365365
/* No such file or directory exists */
366366
if (warn) {
367-
lint.logIfEnabled(log, LintWarnings.PathElementNotFound(file));
367+
lint.logIfEnabled(LintWarnings.PathElementNotFound(file));
368368
}
369369
super.add(file);
370370
return;
@@ -386,12 +386,12 @@ public void addFile(Path file, boolean warn) {
386386
try {
387387
FileSystems.newFileSystem(file, (ClassLoader)null).close();
388388
if (warn) {
389-
lint.logIfEnabled(log, LintWarnings.UnexpectedArchiveFile(file));
389+
lint.logIfEnabled(LintWarnings.UnexpectedArchiveFile(file));
390390
}
391391
} catch (IOException | ProviderNotFoundException e) {
392392
// FIXME: include e.getLocalizedMessage in warning
393393
if (warn) {
394-
lint.logIfEnabled(log, LintWarnings.InvalidArchiveFile(file));
394+
lint.logIfEnabled(LintWarnings.InvalidArchiveFile(file));
395395
}
396396
return;
397397
}
@@ -1654,7 +1654,7 @@ private boolean isSeparator(char ch) {
16541654

16551655
void add(Map<String, List<Path>> map, Path prefix, Path suffix) {
16561656
if (!Files.isDirectory(prefix)) {
1657-
lint.logIfEnabled(log, Files.exists(prefix) ?
1657+
lint.logIfEnabled(Files.exists(prefix) ?
16581658
LintWarnings.DirPathElementNotDirectory(prefix) :
16591659
LintWarnings.DirPathElementNotFound(prefix));
16601660
return;

src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@ protected boolean accepts(AttributeKind kind) {
854854
if (!warnedAttrs.contains(name)) {
855855
JavaFileObject prev = log.useSource(currentClassFile);
856856
try {
857-
lint.logIfEnabled(log,
857+
lint.logIfEnabled(
858858
LintWarnings.FutureAttr(name, version.major, version.minor, majorVersion, minorVersion));
859859
} finally {
860860
log.useSource(prev);
@@ -1608,7 +1608,7 @@ void readParameterAnnotations(Symbol meth) {
16081608
} else if (parameterAnnotations.length != numParameters) {
16091609
//the RuntimeVisibleParameterAnnotations and RuntimeInvisibleParameterAnnotations
16101610
//provide annotations for a different number of parameters, ignore:
1611-
lint.logIfEnabled(log, LintWarnings.RuntimeVisibleInvisibleParamAnnotationsMismatch(currentClassFile));
1611+
lint.logIfEnabled(LintWarnings.RuntimeVisibleInvisibleParamAnnotationsMismatch(currentClassFile));
16121612
for (int pnum = 0; pnum < numParameters; pnum++) {
16131613
readAnnotations();
16141614
}
@@ -2074,9 +2074,9 @@ MethodSymbol findAccessMethod(Type container, Name name) {
20742074
JavaFileObject prevSource = log.useSource(requestingOwner.classfile);
20752075
try {
20762076
if (failure == null) {
2077-
lint.logIfEnabled(log, LintWarnings.AnnotationMethodNotFound(container, name));
2077+
lint.logIfEnabled(LintWarnings.AnnotationMethodNotFound(container, name));
20782078
} else {
2079-
lint.logIfEnabled(log, LintWarnings.AnnotationMethodNotFoundReason(container,
2079+
lint.logIfEnabled(LintWarnings.AnnotationMethodNotFoundReason(container,
20802080
name,
20812081
failure.getDetailValue()));//diagnostic, if present
20822082
}
@@ -2954,7 +2954,7 @@ void adjustParameterAnnotations(MethodSymbol sym, Type methodDescriptor,
29542954

29552955
private void dropParameterAnnotations() {
29562956
parameterAnnotations = null;
2957-
lint.logIfEnabled(log, LintWarnings.RuntimeInvisibleParameterAnnotations(currentClassFile));
2957+
lint.logIfEnabled(LintWarnings.RuntimeInvisibleParameterAnnotations(currentClassFile));
29582958
}
29592959
/**
29602960
* Creates the parameter at the position {@code mpIndex} in the parameter list of the owning method.

src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacFiler.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ private void checkName(String name) throws FilerException {
707707

708708
private void checkName(String name, boolean allowUnnamedPackageInfo) throws FilerException {
709709
if (!SourceVersion.isName(name) && !isPackageInfo(name, allowUnnamedPackageInfo)) {
710-
lint.logIfEnabled(log, LintWarnings.ProcIllegalFileName(name));
710+
lint.logIfEnabled(LintWarnings.ProcIllegalFileName(name));
711711
throw new FilerException("Illegal name " + name);
712712
}
713713
}
@@ -735,11 +735,11 @@ private void checkNameAndExistence(ModuleSymbol mod, String typename, boolean al
735735
initialClassNames.contains(typename) ||
736736
containedInInitialInputs(typename);
737737
if (alreadySeen) {
738-
lint.logIfEnabled(log, LintWarnings.ProcTypeRecreate(typename));
738+
lint.logIfEnabled(LintWarnings.ProcTypeRecreate(typename));
739739
throw new FilerException("Attempt to recreate a file for type " + typename);
740740
}
741741
if (existing != null) {
742-
lint.logIfEnabled(log, LintWarnings.ProcTypeAlreadyExists(typename));
742+
lint.logIfEnabled(LintWarnings.ProcTypeAlreadyExists(typename));
743743
}
744744
if (!mod.isUnnamed() && !typename.contains(".")) {
745745
throw new FilerException("Attempt to create a type in unnamed package of a named module: " + typename);
@@ -768,7 +768,7 @@ private boolean containedInInitialInputs(String typename) {
768768
*/
769769
private void checkFileReopening(FileObject fileObject, boolean forWriting) throws FilerException {
770770
if (isInFileObjectHistory(fileObject, forWriting)) {
771-
lint.logIfEnabled(log, LintWarnings.ProcFileReopening(fileObject.getName()));
771+
lint.logIfEnabled(LintWarnings.ProcFileReopening(fileObject.getName()));
772772
throw new FilerException("Attempt to reopen a file for path " + fileObject.getName());
773773
}
774774
if (forWriting)

0 commit comments

Comments
 (0)