From ed3ab52e436f933b976ae4abc8d86d95cbb598f3 Mon Sep 17 00:00:00 2001 From: Dave Brosius Date: Sun, 3 Dec 2023 11:58:06 -0500 Subject: [PATCH] .of(), .singletonXX() and emptyXX() as collection factories --- .../fbcontrib/detect/WriteOnlyCollection.java | 186 ++++++++++++++++++ .../mebigfatguy/fbcontrib/utils/Values.java | 1 + 2 files changed, 187 insertions(+) diff --git a/src/main/java/com/mebigfatguy/fbcontrib/detect/WriteOnlyCollection.java b/src/main/java/com/mebigfatguy/fbcontrib/detect/WriteOnlyCollection.java index c3743337..57a93f57 100755 --- a/src/main/java/com/mebigfatguy/fbcontrib/detect/WriteOnlyCollection.java +++ b/src/main/java/com/mebigfatguy/fbcontrib/detect/WriteOnlyCollection.java @@ -182,6 +182,192 @@ public class WriteOnlyCollection extends MissingMethodsDetector { .withParamTypes(Values.SLASHED_JAVA_UTIL_COMPARATOR).withReturnType(TreeMap.class).toString())); cfm.add(new FQMethod("com/google/common/collect/Maps", "newIdentityHashMap", noParamsReturnType(IdentityHashMap.class))); + cfm.add(new FQMethod("java/util/List", "of", new SignatureBuilder().withReturnType(List.class).build())); + cfm.add(new FQMethod("java/util/List", "of", + new SignatureBuilder().withParamTypes(Values.SIG_OBJECT_ARRAY).withReturnType(List.class).build())); + cfm.add(new FQMethod("java/util/List", "of", new SignatureBuilder() + .withParamTypes(Values.SLASHED_JAVA_LANG_OBJECT).withReturnType(List.class).build())); + cfm.add(new FQMethod("java/util/List", "of", + new SignatureBuilder().withParamTypes(Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT) + .withReturnType(List.class).build())); + cfm.add(new FQMethod("java/util/List", "of", + new SignatureBuilder().withParamTypes(Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT).withReturnType(List.class).build())); + cfm.add(new FQMethod("java/util/List", "of", + new SignatureBuilder() + .withParamTypes(Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT) + .withReturnType(List.class).build())); + cfm.add(new FQMethod("java/util/List", "of", + new SignatureBuilder().withParamTypes(Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT).withReturnType(List.class).build())); + cfm.add(new FQMethod("java/util/List", "of", + new SignatureBuilder() + .withParamTypes(Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT) + .withReturnType(List.class).build())); + cfm.add(new FQMethod("java/util/List", "of", + new SignatureBuilder().withParamTypes(Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT).withReturnType(List.class).build())); + cfm.add(new FQMethod("java/util/List", "of", + new SignatureBuilder() + .withParamTypes(Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT) + .withReturnType(List.class).build())); + cfm.add(new FQMethod("java/util/List", "of", + new SignatureBuilder() + .withParamTypes(Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT) + .withReturnType(List.class).build())); + cfm.add(new FQMethod("java/util/List", "of", + new SignatureBuilder() + .withParamTypes(Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT) + .withReturnType(List.class).build())); + cfm.add(new FQMethod("java/util/Set", "of", new SignatureBuilder().withReturnType(Set.class).build())); + cfm.add(new FQMethod("java/util/Set", "of", + new SignatureBuilder().withParamTypes(Values.SIG_OBJECT_ARRAY).withReturnType(Set.class).build())); + cfm.add(new FQMethod("java/util/Set", "of", new SignatureBuilder() + .withParamTypes(Values.SLASHED_JAVA_LANG_OBJECT).withReturnType(Set.class).build())); + cfm.add(new FQMethod("java/util/Set", "of", + new SignatureBuilder().withParamTypes(Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT) + .withReturnType(Set.class).build())); + cfm.add(new FQMethod("java/util/Set", "of", + new SignatureBuilder().withParamTypes(Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT).withReturnType(Set.class).build())); + cfm.add(new FQMethod("java/util/Set", "of", + new SignatureBuilder() + .withParamTypes(Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT) + .withReturnType(Set.class).build())); + cfm.add(new FQMethod("java/util/Set", "of", + new SignatureBuilder().withParamTypes(Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT).withReturnType(Set.class).build())); + cfm.add(new FQMethod("java/util/Set", "of", + new SignatureBuilder() + .withParamTypes(Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT) + .withReturnType(Set.class).build())); + cfm.add(new FQMethod("java/util/Set", "of", + new SignatureBuilder().withParamTypes(Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT).withReturnType(Set.class).build())); + cfm.add(new FQMethod("java/util/Set", "of", + new SignatureBuilder() + .withParamTypes(Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT) + .withReturnType(Set.class).build())); + cfm.add(new FQMethod("java/util/Set", "of", + new SignatureBuilder().withParamTypes(Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT).withReturnType(Set.class).build())); + cfm.add(new FQMethod("java/util/Set", "of", + new SignatureBuilder() + .withParamTypes(Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT) + .withReturnType(Set.class).build())); + cfm.add(new FQMethod("java/util/Map", "of", new SignatureBuilder().withReturnType(Map.class).build())); + cfm.add(new FQMethod("java/util/Map", "of", + new SignatureBuilder().withParamTypes(Values.SIG_OBJECT_ARRAY).withReturnType(Map.class).build())); + cfm.add(new FQMethod("java/util/Map", "of", + new SignatureBuilder().withParamTypes(Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT) + .withReturnType(Map.class).build())); + cfm.add(new FQMethod("java/util/Map", "of", + new SignatureBuilder() + .withParamTypes(Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT) + .withReturnType(Map.class).build())); + cfm.add(new FQMethod("java/util/Map", "of", + new SignatureBuilder() + .withParamTypes(Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT) + .withReturnType(Map.class).build())); + cfm.add(new FQMethod("java/util/Map", "of", + new SignatureBuilder() + .withParamTypes(Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT) + .withReturnType(Map.class).build())); + cfm.add(new FQMethod("java/util/Map", "of", + new SignatureBuilder() + .withParamTypes(Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT) + .withReturnType(Map.class).build())); + cfm.add(new FQMethod("java/util/Map", "of", + new SignatureBuilder() + .withParamTypes(Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT) + .withReturnType(Map.class).build())); + cfm.add(new FQMethod("java/util/Map", "of", new SignatureBuilder().withParamTypes( + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT).withReturnType(Map.class).build())); + cfm.add(new FQMethod("java/util/Map", "of", new SignatureBuilder().withParamTypes( + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT).withReturnType(Map.class).build())); + cfm.add(new FQMethod("java/util/Map", "of", new SignatureBuilder().withParamTypes( + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT) + .withReturnType(Map.class).build())); + cfm.add(new FQMethod("java/util/Map", "of", new SignatureBuilder().withParamTypes( + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT, + Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT).withReturnType(Map.class).build())); + cfm.add(new FQMethod("java/util/Collections", "emptyList", + new SignatureBuilder().withReturnType(List.class).build())); + cfm.add(new FQMethod("java/util/Collections", "emptySet", + new SignatureBuilder().withReturnType(Set.class).build())); + cfm.add(new FQMethod("java/util/Collections", "emptyMap", + new SignatureBuilder().withReturnType(Map.class).build())); + cfm.add(new FQMethod("java/util/Collections", "singletonList", new SignatureBuilder() + .withParamTypes(Values.SLASHED_JAVA_LANG_OBJECT).withReturnType(List.class).build())); + cfm.add(new FQMethod("java/util/Collections", "singleton", new SignatureBuilder() + .withParamTypes(Values.SLASHED_JAVA_LANG_OBJECT).withReturnType(Set.class).build())); + cfm.add(new FQMethod("java/util/Collections", "singletonMap", + new SignatureBuilder().withParamTypes(Values.SLASHED_JAVA_LANG_OBJECT, Values.SLASHED_JAVA_LANG_OBJECT) + .withReturnType(Map.class).build())); collectionFactoryMethods = Collections.unmodifiableSet(cfm); } diff --git a/src/main/java/com/mebigfatguy/fbcontrib/utils/Values.java b/src/main/java/com/mebigfatguy/fbcontrib/utils/Values.java index 4030abd6..6c91e991 100644 --- a/src/main/java/com/mebigfatguy/fbcontrib/utils/Values.java +++ b/src/main/java/com/mebigfatguy/fbcontrib/utils/Values.java @@ -67,6 +67,7 @@ public final class Values { public static final char SIG_QUALIFIED_CLASS_SUFFIX_CHAR = ';'; public static final String SIG_ARRAY_PREFIX = "["; public static final String SIG_ARRAY_OF_ARRAYS_PREFIX = "[["; + public static final String SIG_OBJECT_ARRAY = "[Ljava/lang/Object;"; @DottedClassName public static final String DOTTED_JAVA_LANG_OBJECT = "java.lang.Object";