Skip to content

Commit

Permalink
.of(), .singletonXX() and emptyXX() as collection factories
Browse files Browse the repository at this point in the history
  • Loading branch information
mebigfatguy committed Dec 3, 2023
1 parent ae75fe1 commit ed3ab52
Show file tree
Hide file tree
Showing 2 changed files with 187 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.<FQMethod>unmodifiableSet(cfm);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/mebigfatguy/fbcontrib/utils/Values.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit ed3ab52

Please sign in to comment.