Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate CollectionIncompatibleType from the deprecated withSignature to named(...).withParameters(...). #4551

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,25 @@ public final class ContainmentMatchers {
// "Normal" cases, e.g. Collection#remove(Object)
// Make sure to keep that the type or one of its supertype should be present in
// FIRST_ORDER_MATCHER
new MethodArgMatcher("java.util.Collection", "contains(java.lang.Object)", 0, 0),
new MethodArgMatcher("java.util.Collection", "remove(java.lang.Object)", 0, 0),
new MethodArgMatcher("java.util.Deque", "removeFirstOccurrence(java.lang.Object)", 0, 0),
new MethodArgMatcher("java.util.Deque", "removeLastOccurrence(java.lang.Object)", 0, 0),
new MethodArgMatcher("java.util.Dictionary", "get(java.lang.Object)", 0, 0),
new MethodArgMatcher("java.util.Dictionary", "remove(java.lang.Object)", 0, 0),
new MethodArgMatcher("java.util.List", "indexOf(java.lang.Object)", 0, 0),
new MethodArgMatcher("java.util.List", "lastIndexOf(java.lang.Object)", 0, 0),
new MethodArgMatcher("java.util.Map", "containsKey(java.lang.Object)", 0, 0),
new MethodArgMatcher("java.util.Map", "containsValue(java.lang.Object)", 1, 0),
new MethodArgMatcher("java.util.Map", "get(java.lang.Object)", 0, 0),
new MethodArgMatcher("java.util.Map", "getOrDefault(java.lang.Object,V)", 0, 0),
new MethodArgMatcher("java.util.Map", "remove(java.lang.Object)", 0, 0),
new MethodArgMatcher("java.util.Stack", "search(java.lang.Object)", 0, 0),
new MethodArgMatcher("java.util.Vector", "indexOf(java.lang.Object,int)", 0, 0),
new MethodArgMatcher("java.util.Vector", "lastIndexOf(java.lang.Object,int)", 0, 0),
new MethodArgMatcher("java.util.Vector", "removeElement(java.lang.Object)", 0, 0));
new MethodArgMatcher("java.util.Collection", 0, 0, "contains", "java.lang.Object"),
new MethodArgMatcher("java.util.Collection", 0, 0, "remove", "java.lang.Object"),
new MethodArgMatcher(
"java.util.Deque", 0, 0, "removeFirstOccurrence", "java.lang.Object"),
new MethodArgMatcher("java.util.Deque", 0, 0, "removeLastOccurrence", "java.lang.Object"),
new MethodArgMatcher("java.util.Dictionary", 0, 0, "get", "java.lang.Object"),
new MethodArgMatcher("java.util.Dictionary", 0, 0, "remove", "java.lang.Object"),
new MethodArgMatcher("java.util.List", 0, 0, "indexOf", "java.lang.Object"),
new MethodArgMatcher("java.util.List", 0, 0, "lastIndexOf", "java.lang.Object"),
new MethodArgMatcher("java.util.Map", 0, 0, "containsKey", "java.lang.Object"),
new MethodArgMatcher("java.util.Map", 1, 0, "containsValue", "java.lang.Object"),
new MethodArgMatcher("java.util.Map", 0, 0, "get", "java.lang.Object"),
new MethodArgMatcher(
"java.util.Map", 0, 0, "getOrDefault", "java.lang.Object", "java.lang.Object"),
new MethodArgMatcher("java.util.Map", 0, 0, "remove", "java.lang.Object"),
new MethodArgMatcher("java.util.Stack", 0, 0, "search", "java.lang.Object"),
new MethodArgMatcher("java.util.Vector", 0, 0, "indexOf", "java.lang.Object", "int"),
new MethodArgMatcher("java.util.Vector", 0, 0, "lastIndexOf", "java.lang.Object", "int"),
new MethodArgMatcher("java.util.Vector", 0, 0, "removeElement", "java.lang.Object"));

/**
* Cases where we need to extract the type argument from a method argument, e.g.
Expand All @@ -74,25 +76,28 @@ public final class ContainmentMatchers {
// FIRST_ORDER_MATCHER
new TypeArgOfMethodArgMatcher(
"java.util.Collection", // class that defines the method
"containsAll(java.util.Collection<?>)", // method signature
0, // index of the owning class's type argument to extract
0, // index of the method argument whose type argument to extract
"java.util.Collection", // type of the method argument
0), // index of the method argument's type argument to extract
0, // index of the method argument's type argument to extract
"containsAll", // method name
"java.util.Collection"), // method parameter
new TypeArgOfMethodArgMatcher(
"java.util.Collection", // class that defines the method
"removeAll(java.util.Collection<?>)", // method signature
0, // index of the owning class's type argument to extract
0, // index of the method argument whose type argument to extract
"java.util.Collection", // type of the method argument
0), // index of the method argument's type argument to extract
0, // index of the method argument's type argument to extract
"removeAll", // method name
"java.util.Collection"), // method parameter
new TypeArgOfMethodArgMatcher(
"java.util.Collection", // class that defines the method
"retainAll(java.util.Collection<?>)", // method signature
0, // index of the owning class's type argument to extract
0, // index of the method argument whose type argument to extract
"java.util.Collection", // type of the method argument
0)); // index of the method argument's type argument to extract
0, // index of the method argument's type argument to extract
"retainAll", // method name
"java.util.Collection")); // method parameter

private static final ImmutableList<BinopMatcher> STATIC_MATCHERS =
ImmutableList.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,24 @@ final class MethodArgMatcher extends AbstractCollectionIncompatibleTypeMatcher {

/**
* @param typeName The fully-qualified name of the type whose descendants to match on
* @param signature The signature of the method to match on
* @param typeArgIndex The index of the type argument that should match the method argument
* @param methodArgIndex The index of the method argument that should match the type argument
* @param name The name of the method to match on
* @param firstParam The type of the first parameter of the method
* @param otherParams The types of any additional parameters of the method
*/
MethodArgMatcher(String typeName, String signature, int typeArgIndex, int methodArgIndex) {
this.methodMatcher = instanceMethod().onDescendantOf(typeName).withSignature(signature);
MethodArgMatcher(
String typeName,
int typeArgIndex,
int methodArgIndex,
String name,
String firstParam,
String... otherParams) {
this.methodMatcher =
instanceMethod()
.onDescendantOf(typeName)
.named(name)
.withParameters(firstParam, otherParams);
this.typeName = typeName;
this.typeArgIndex = typeArgIndex;
this.methodArgIndex = methodArgIndex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,30 @@ class TypeArgOfMethodArgMatcher extends AbstractCollectionIncompatibleTypeMatche
/**
* @param receiverTypeName The fully-qualified name of the type of the method receiver whose
* descendants to match on
* @param signature The signature of the method to match on
* @param receiverTypeArgIndex The index of the type argument that should match the method
* argument
* @param methodArgIndex The index of the method argument whose type argument we should extract
* @param methodArgTypeName The fully-qualified name of the type of the method argument whose type
* argument we should extract
* @param methodArgTypeArgIndex The index of the type argument to extract from the method argument
* @param name The name of the method to match on
* @param firstParam The type of the first parameter of the method
* @param otherParams The types of any additional parameters of the method
*/
public TypeArgOfMethodArgMatcher(
String receiverTypeName,
String signature,
int receiverTypeArgIndex,
int methodArgIndex,
String methodArgTypeName,
int methodArgTypeArgIndex) {
this.methodMatcher = instanceMethod().onDescendantOf(receiverTypeName).withSignature(signature);
int methodArgTypeArgIndex,
String name,
String firstParam,
String... otherParams) {
this.methodMatcher =
instanceMethod()
.onDescendantOf(receiverTypeName)
.named(name)
.withParameters(firstParam, otherParams);
this.receiverTypeName = receiverTypeName;
this.receiverTypeArgIndex = receiverTypeArgIndex;
this.methodArgIndex = methodArgIndex;
Expand Down
Loading