Skip to content
Merged
Prev Previous commit
Next Next commit
remove unnecessary filters
  • Loading branch information
forozco committed Sep 12, 2019
commit 94fdb82033cf55013fbac83e2519d133af2209e3
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,9 @@
import static com.google.common.collect.Iterables.getOnlyElement;
import static com.google.errorprone.BugPattern.ProvidesFix.REQUIRES_HUMAN_ATTENTION;
import static com.google.errorprone.BugPattern.SeverityLevel.ERROR;
import static com.google.errorprone.util.ASTHelpers.findSuperMethodInType;
import static com.google.errorprone.util.ASTHelpers.getSymbol;
import static com.google.errorprone.util.ASTHelpers.getType;
import static com.google.errorprone.util.ASTHelpers.isSubtype;
import static com.google.errorprone.util.ASTHelpers.*;
import static com.google.errorprone.util.SideEffectAnalysis.hasSideEffect;
import static com.sun.source.tree.Tree.Kind.POSTFIX_DECREMENT;
import static com.sun.source.tree.Tree.Kind.POSTFIX_INCREMENT;
import static com.sun.source.tree.Tree.Kind.PREFIX_DECREMENT;
import static com.sun.source.tree.Tree.Kind.PREFIX_INCREMENT;
import static com.sun.source.tree.Tree.Kind.*;

import com.google.auto.service.AutoService;
import com.google.common.base.Ascii;
Expand Down Expand Up @@ -180,9 +174,6 @@ public Description matchCompilationUnit(CompilationUnitTree tree, VisitorState s
// and fields. As we go we remove those variables which are used.
Map<Symbol, TreePath> unusedElements = variableFinder.unusedElements;

// Whether a symbol should only be checked for reassignments (e.g. public methods' parameters).
Set<Symbol> onlyCheckForReassignments = variableFinder.onlyCheckForReassignments;

// Map of symbols to their usage sites. In this map we also include the definition site in
// addition to all the trees where symbol is used. This map is designed to keep the usage sites
// of variables (parameters, fields, locals).
Expand Down Expand Up @@ -219,15 +210,10 @@ public Description matchCompilationUnit(CompilationUnitTree tree, VisitorState s
}
SuggestedFix makeFirstAssignmentDeclaration =
makeAssignmentDeclaration(unusedSymbol, specs, allUsageSites, state);
// Don't complain if this is a public method and we only overwrote it once.
if (onlyCheckForReassignments.contains(unusedSymbol) && specs.size() <= 1) {
continue;
}
Tree unused = specs.iterator().next().variableTree().getLeaf();
Symbol.VarSymbol symbol = (Symbol.VarSymbol) unusedSymbol;
ImmutableList<SuggestedFix> fixes;
if (symbol.getKind() == ElementKind.PARAMETER
&& !onlyCheckForReassignments.contains(unusedSymbol)
&& !isEverUsed.contains(unusedSymbol)) {
fixes = buildUnusedParameterFixes(symbol, allUsageSites, state);
} else {
Expand Down Expand Up @@ -533,8 +519,6 @@ private static boolean exemptedByName(Name name) {
private class VariableFinder extends TreePathScanner<Void, Void> {
private final Map<Symbol, TreePath> unusedElements = new HashMap<>();

private final Set<Symbol> onlyCheckForReassignments = new HashSet<>();

private final ListMultimap<Symbol, TreePath> usageSites = ArrayListMultimap.create();

private final VisitorState state;
Expand Down Expand Up @@ -582,9 +566,6 @@ && exemptedFieldBySuperType(getType(variableTree), state)) {
return null;
}
unusedElements.put(symbol, getCurrentPath());
if (!isParameterSubjectToAnalysis(symbol)) {
onlyCheckForReassignments.add(symbol);
}
break;
default:
break;
Expand Down