-
Notifications
You must be signed in to change notification settings - Fork 745
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a test confirming that ArgumentSelectionDefectChecker works on re…
…cord construction, but _not_ record deconstruction. PiperOrigin-RevId: 691430462
- Loading branch information
1 parent
81e3cfa
commit 188b8b6
Showing
11 changed files
with
151 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,7 +43,7 @@ | |
* @author [email protected] (Andrew Rice) | ||
*/ | ||
@BugPattern(summary = "Arguments are swapped in assertEquals-like call", severity = WARNING) | ||
public class AssertEqualsArgumentOrderChecker extends BugChecker | ||
public final class AssertEqualsArgumentOrderChecker extends BugChecker | ||
implements MethodInvocationTreeMatcher { | ||
|
||
private final ArgumentChangeFinder argumentchangeFinder = | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,7 +41,8 @@ | |
* @author [email protected] (Andrew Rice) | ||
*/ | ||
@BugPattern(summary = "Arguments to AutoValue constructor are in the wrong order", severity = ERROR) | ||
public class AutoValueConstructorOrderChecker extends BugChecker implements NewClassTreeMatcher { | ||
public final class AutoValueConstructorOrderChecker extends BugChecker | ||
implements NewClassTreeMatcher { | ||
|
||
private final ArgumentChangeFinder argumentChangeFinder = | ||
ArgumentChangeFinder.builder() | ||
|
@@ -52,7 +53,7 @@ public class AutoValueConstructorOrderChecker extends BugChecker implements NewC | |
|
||
@Override | ||
public Description matchNewClass(NewClassTree tree, VisitorState state) { | ||
if (!Matchers.AUTOVALUE_CONSTRUCTOR.matches(tree, state)) { | ||
if (!Matchers.isAutoValueConstructor(tree)) { | ||
return Description.NO_MATCH; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,7 @@ | |
* | ||
* @author [email protected] (Andrew Rice) | ||
*/ | ||
class Costs { | ||
final class Costs { | ||
|
||
/** Formal parameters for the method being called. */ | ||
private final ImmutableList<Parameter> formals; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,7 @@ | |
* | ||
* @author [email protected] (Andrew Rice) | ||
*/ | ||
class CreatesDuplicateCallHeuristic implements Heuristic { | ||
final class CreatesDuplicateCallHeuristic implements Heuristic { | ||
|
||
/** | ||
* Returns true if there are no other calls to this method which already have an actual parameter | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,9 +16,12 @@ | |
|
||
package com.google.errorprone.bugpatterns.argumentselectiondefects; | ||
|
||
import static com.google.common.collect.Streams.stream; | ||
import static com.google.errorprone.names.NamingConventions.splitToLowercaseTerms; | ||
import static java.util.Collections.disjoint; | ||
|
||
import com.google.common.collect.ImmutableSet; | ||
import com.google.errorprone.VisitorState; | ||
import com.google.errorprone.names.NamingConventions; | ||
import com.sun.source.tree.ClassTree; | ||
import com.sun.source.tree.MethodTree; | ||
import com.sun.source.tree.Tree; | ||
|
@@ -32,7 +35,7 @@ | |
* | ||
* @author [email protected] (Andrew Rice) | ||
*/ | ||
class EnclosedByReverseHeuristic implements Heuristic { | ||
final class EnclosedByReverseHeuristic implements Heuristic { | ||
|
||
private static final ImmutableSet<String> DEFAULT_REVERSE_WORDS_TERMS = | ||
ImmutableSet.of( | ||
|
@@ -75,18 +78,12 @@ public boolean isAcceptableChange( | |
return findReverseWordsMatchInParentNodes(state) == null; | ||
} | ||
|
||
protected @Nullable String findReverseWordsMatchInParentNodes(VisitorState state) { | ||
for (Tree tree : state.getPath()) { | ||
Optional<String> name = getName(tree); | ||
if (name.isPresent()) { | ||
for (String term : NamingConventions.splitToLowercaseTerms(name.get())) { | ||
if (reverseWordsTerms.contains(term)) { | ||
return term; | ||
} | ||
} | ||
} | ||
} | ||
return null; | ||
private @Nullable String findReverseWordsMatchInParentNodes(VisitorState state) { | ||
return stream(state.getPath()) | ||
.flatMap(t -> getName(t).stream()) | ||
.filter(n -> !disjoint(splitToLowercaseTerms(n), reverseWordsTerms)) | ||
.findFirst() | ||
.orElse(null); | ||
} | ||
|
||
private static Optional<String> getName(Tree tree) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,7 @@ | |
* | ||
* @author [email protected] (Andrew Rice) | ||
*/ | ||
class LowInformationNameHeuristic implements Heuristic { | ||
final class LowInformationNameHeuristic implements Heuristic { | ||
|
||
private static final ImmutableSet<String> DEFAULT_FORMAL_PARAMETER_EXCLUSION_REGEXS = | ||
ImmutableSet.of( | ||
|
@@ -60,11 +60,9 @@ public boolean isAcceptableChange( | |
* parameter name. | ||
*/ | ||
protected @Nullable String findMatch(Parameter parameter) { | ||
for (String regex : overloadedNamesRegexs) { | ||
if (parameter.name().matches(regex)) { | ||
return regex; | ||
} | ||
} | ||
return null; | ||
return overloadedNamesRegexs.stream() | ||
.filter(r -> parameter.name().matches(r)) | ||
.findFirst() | ||
.orElse(null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ | |
* | ||
* @author [email protected] (Andrew Rice) | ||
*/ | ||
class NameInCommentHeuristic implements Heuristic { | ||
final class NameInCommentHeuristic implements Heuristic { | ||
|
||
/** | ||
* Return true if there are no comments on the original actual parameter of a change which match | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,7 @@ | |
* | ||
* @author [email protected] (Andrew Rice) | ||
*/ | ||
class PenaltyThresholdHeuristic implements Heuristic { | ||
final class PenaltyThresholdHeuristic implements Heuristic { | ||
|
||
private final double threshold; | ||
|
||
|
Oops, something went wrong.