Skip to content

Commit 0a5a5b8

Browse files
cpovirkError Prone Team
authored and
Error Prone Team
committed
Migrate CollectionIncompatibleType from the deprecated withSignature to named(...).withParameters(...).
PiperOrigin-RevId: 667601569
1 parent 78218f2 commit 0a5a5b8

File tree

3 files changed

+55
-30
lines changed

3 files changed

+55
-30
lines changed

core/src/main/java/com/google/errorprone/bugpatterns/collectionincompatibletype/ContainmentMatchers.java

+28-23
Original file line numberDiff line numberDiff line change
@@ -46,23 +46,25 @@ public final class ContainmentMatchers {
4646
// "Normal" cases, e.g. Collection#remove(Object)
4747
// Make sure to keep that the type or one of its supertype should be present in
4848
// FIRST_ORDER_MATCHER
49-
new MethodArgMatcher("java.util.Collection", "contains(java.lang.Object)", 0, 0),
50-
new MethodArgMatcher("java.util.Collection", "remove(java.lang.Object)", 0, 0),
51-
new MethodArgMatcher("java.util.Deque", "removeFirstOccurrence(java.lang.Object)", 0, 0),
52-
new MethodArgMatcher("java.util.Deque", "removeLastOccurrence(java.lang.Object)", 0, 0),
53-
new MethodArgMatcher("java.util.Dictionary", "get(java.lang.Object)", 0, 0),
54-
new MethodArgMatcher("java.util.Dictionary", "remove(java.lang.Object)", 0, 0),
55-
new MethodArgMatcher("java.util.List", "indexOf(java.lang.Object)", 0, 0),
56-
new MethodArgMatcher("java.util.List", "lastIndexOf(java.lang.Object)", 0, 0),
57-
new MethodArgMatcher("java.util.Map", "containsKey(java.lang.Object)", 0, 0),
58-
new MethodArgMatcher("java.util.Map", "containsValue(java.lang.Object)", 1, 0),
59-
new MethodArgMatcher("java.util.Map", "get(java.lang.Object)", 0, 0),
60-
new MethodArgMatcher("java.util.Map", "getOrDefault(java.lang.Object,V)", 0, 0),
61-
new MethodArgMatcher("java.util.Map", "remove(java.lang.Object)", 0, 0),
62-
new MethodArgMatcher("java.util.Stack", "search(java.lang.Object)", 0, 0),
63-
new MethodArgMatcher("java.util.Vector", "indexOf(java.lang.Object,int)", 0, 0),
64-
new MethodArgMatcher("java.util.Vector", "lastIndexOf(java.lang.Object,int)", 0, 0),
65-
new MethodArgMatcher("java.util.Vector", "removeElement(java.lang.Object)", 0, 0));
49+
new MethodArgMatcher("java.util.Collection", 0, 0, "contains", "java.lang.Object"),
50+
new MethodArgMatcher("java.util.Collection", 0, 0, "remove", "java.lang.Object"),
51+
new MethodArgMatcher(
52+
"java.util.Deque", 0, 0, "removeFirstOccurrence", "java.lang.Object"),
53+
new MethodArgMatcher("java.util.Deque", 0, 0, "removeLastOccurrence", "java.lang.Object"),
54+
new MethodArgMatcher("java.util.Dictionary", 0, 0, "get", "java.lang.Object"),
55+
new MethodArgMatcher("java.util.Dictionary", 0, 0, "remove", "java.lang.Object"),
56+
new MethodArgMatcher("java.util.List", 0, 0, "indexOf", "java.lang.Object"),
57+
new MethodArgMatcher("java.util.List", 0, 0, "lastIndexOf", "java.lang.Object"),
58+
new MethodArgMatcher("java.util.Map", 0, 0, "containsKey", "java.lang.Object"),
59+
new MethodArgMatcher("java.util.Map", 1, 0, "containsValue", "java.lang.Object"),
60+
new MethodArgMatcher("java.util.Map", 0, 0, "get", "java.lang.Object"),
61+
new MethodArgMatcher(
62+
"java.util.Map", 0, 0, "getOrDefault", "java.lang.Object", "java.lang.Object"),
63+
new MethodArgMatcher("java.util.Map", 0, 0, "remove", "java.lang.Object"),
64+
new MethodArgMatcher("java.util.Stack", 0, 0, "search", "java.lang.Object"),
65+
new MethodArgMatcher("java.util.Vector", 0, 0, "indexOf", "java.lang.Object", "int"),
66+
new MethodArgMatcher("java.util.Vector", 0, 0, "lastIndexOf", "java.lang.Object", "int"),
67+
new MethodArgMatcher("java.util.Vector", 0, 0, "removeElement", "java.lang.Object"));
6668

6769
/**
6870
* Cases where we need to extract the type argument from a method argument, e.g.
@@ -74,25 +76,28 @@ public final class ContainmentMatchers {
7476
// FIRST_ORDER_MATCHER
7577
new TypeArgOfMethodArgMatcher(
7678
"java.util.Collection", // class that defines the method
77-
"containsAll(java.util.Collection<?>)", // method signature
7879
0, // index of the owning class's type argument to extract
7980
0, // index of the method argument whose type argument to extract
8081
"java.util.Collection", // type of the method argument
81-
0), // index of the method argument's type argument to extract
82+
0, // index of the method argument's type argument to extract
83+
"containsAll", // method name
84+
"java.util.Collection"), // method parameter
8285
new TypeArgOfMethodArgMatcher(
8386
"java.util.Collection", // class that defines the method
84-
"removeAll(java.util.Collection<?>)", // method signature
8587
0, // index of the owning class's type argument to extract
8688
0, // index of the method argument whose type argument to extract
8789
"java.util.Collection", // type of the method argument
88-
0), // index of the method argument's type argument to extract
90+
0, // index of the method argument's type argument to extract
91+
"removeAll", // method name
92+
"java.util.Collection"), // method parameter
8993
new TypeArgOfMethodArgMatcher(
9094
"java.util.Collection", // class that defines the method
91-
"retainAll(java.util.Collection<?>)", // method signature
9295
0, // index of the owning class's type argument to extract
9396
0, // index of the method argument whose type argument to extract
9497
"java.util.Collection", // type of the method argument
95-
0)); // index of the method argument's type argument to extract
98+
0, // index of the method argument's type argument to extract
99+
"retainAll", // method name
100+
"java.util.Collection")); // method parameter
96101

97102
private static final ImmutableList<BinopMatcher> STATIC_MATCHERS =
98103
ImmutableList.of(

core/src/main/java/com/google/errorprone/bugpatterns/collectionincompatibletype/MethodArgMatcher.java

+15-3
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,24 @@ final class MethodArgMatcher extends AbstractCollectionIncompatibleTypeMatcher {
4646

4747
/**
4848
* @param typeName The fully-qualified name of the type whose descendants to match on
49-
* @param signature The signature of the method to match on
5049
* @param typeArgIndex The index of the type argument that should match the method argument
5150
* @param methodArgIndex The index of the method argument that should match the type argument
51+
* @param name The name of the method to match on
52+
* @param firstParam The type of the first parameter of the method
53+
* @param otherParams The types of any additional parameters of the method
5254
*/
53-
MethodArgMatcher(String typeName, String signature, int typeArgIndex, int methodArgIndex) {
54-
this.methodMatcher = instanceMethod().onDescendantOf(typeName).withSignature(signature);
55+
MethodArgMatcher(
56+
String typeName,
57+
int typeArgIndex,
58+
int methodArgIndex,
59+
String name,
60+
String firstParam,
61+
String... otherParams) {
62+
this.methodMatcher =
63+
instanceMethod()
64+
.onDescendantOf(typeName)
65+
.named(name)
66+
.withParameters(firstParam, otherParams);
5567
this.typeName = typeName;
5668
this.typeArgIndex = typeArgIndex;
5769
this.methodArgIndex = methodArgIndex;

core/src/main/java/com/google/errorprone/bugpatterns/collectionincompatibletype/TypeArgOfMethodArgMatcher.java

+12-4
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,30 @@ class TypeArgOfMethodArgMatcher extends AbstractCollectionIncompatibleTypeMatche
5151
/**
5252
* @param receiverTypeName The fully-qualified name of the type of the method receiver whose
5353
* descendants to match on
54-
* @param signature The signature of the method to match on
5554
* @param receiverTypeArgIndex The index of the type argument that should match the method
5655
* argument
5756
* @param methodArgIndex The index of the method argument whose type argument we should extract
5857
* @param methodArgTypeName The fully-qualified name of the type of the method argument whose type
5958
* argument we should extract
6059
* @param methodArgTypeArgIndex The index of the type argument to extract from the method argument
60+
* @param name The name of the method to match on
61+
* @param firstParam The type of the first parameter of the method
62+
* @param otherParams The types of any additional parameters of the method
6163
*/
6264
public TypeArgOfMethodArgMatcher(
6365
String receiverTypeName,
64-
String signature,
6566
int receiverTypeArgIndex,
6667
int methodArgIndex,
6768
String methodArgTypeName,
68-
int methodArgTypeArgIndex) {
69-
this.methodMatcher = instanceMethod().onDescendantOf(receiverTypeName).withSignature(signature);
69+
int methodArgTypeArgIndex,
70+
String name,
71+
String firstParam,
72+
String... otherParams) {
73+
this.methodMatcher =
74+
instanceMethod()
75+
.onDescendantOf(receiverTypeName)
76+
.named(name)
77+
.withParameters(firstParam, otherParams);
7078
this.receiverTypeName = receiverTypeName;
7179
this.receiverTypeArgIndex = receiverTypeArgIndex;
7280
this.methodArgIndex = methodArgIndex;

0 commit comments

Comments
 (0)