Skip to content

Commit

Permalink
One more
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan202 committed Aug 6, 2023
1 parent 38af13f commit 8c6a0ac
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package tech.picnic.errorprone.refaster.matchers;

import static com.google.common.base.Verify.verify;
import static com.google.errorprone.matchers.FieldMatchers.staticField;
import static com.google.errorprone.matchers.Matchers.allOf;
import static com.google.errorprone.matchers.Matchers.anyOf;
Expand Down Expand Up @@ -47,6 +48,7 @@ public final class IsEmpty implements Matcher<ExpressionTree> {
private static final long serialVersionUID = 1L;
private static final Pattern EMPTY_INSTANCE_FACTORY_METHOD_PATTERN = Pattern.compile("empty.*");
private static final Matcher<Tree> PRIMITIVE_TYPE = isPrimitiveType();
// XXX: Extend this list to include additional JDK collection types with a public constructor.
private static final Matcher<ExpressionTree> MUTABLE_COLLECTION_TYPE =
anyOf(
isSameType(ArrayList.class),
Expand Down Expand Up @@ -117,7 +119,8 @@ private boolean isEmptyCollectionConstructor(ExpressionTree tree, VisitorState s
* This looks like a copy constructor, in which case the resultant collection is empty if its
* argument is.
*/
return arguments.size() == 1 && matches(arguments.get(0), state);
verify(arguments.size() == 1, "Unexpected %s-ary constructor", arguments.size());
return matches(arguments.get(0), state);
}

private static boolean isEmptyArrayCreation(ExpressionTree tree) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ void matches() {
"import java.util.LinkedList;",
"import java.util.List;",
"import java.util.Map;",
"import java.util.Random;",
"import java.util.Set;",
"import java.util.Stack;",
"import java.util.Vector;",
Expand All @@ -49,47 +50,51 @@ void matches() {
" return new int[][] {{0}};",
" }",
"",
" List<Integer> negative5() {",
" Random negative5() {",
" return new Random();",
" }",
"",
" List<Integer> negative6() {",
" return new ArrayList<>(ImmutableList.of(1));",
" }",
"",
" Map<Integer, Integer> negative6() {",
" Map<Integer, Integer> negative7() {",
" return new HashMap<>(ImmutableMap.of(1, 2));",
" }",
"",
" Map<Integer, Integer> negative7() {",
" Map<Integer, Integer> negative8() {",
" return new LinkedHashMap<>(ImmutableMap.of(1, 2));",
" }",
"",
" ImmutableList<Integer> negative8() {",
" ImmutableList<Integer> negative9() {",
" return ImmutableList.of(1);",
" }",
"",
" ImmutableSet<Integer> negative9() {",
" ImmutableSet<Integer> negative10() {",
" return ImmutableSet.of(1);",
" }",
"",
" ImmutableMap<Integer, Integer> negative10() {",
" ImmutableMap<Integer, Integer> negative11() {",
" return ImmutableMap.of(1, 2);",
" }",
"",
" ImmutableSetMultimap<Integer, Integer> negative11() {",
" ImmutableSetMultimap<Integer, Integer> negative12() {",
" return ImmutableSetMultimap.of(1, 2);",
" }",
"",
" List<Integer> negative12() {",
" List<Integer> negative13() {",
" return List.of(1);",
" }",
"",
" Map<Integer, Integer> negative13() {",
" Map<Integer, Integer> negative14() {",
" return Map.of(1, 2);",
" }",
"",
" Set<Integer> negative14() {",
" Set<Integer> negative15() {",
" return Set.of(1);",
" }",
"",
" Stream<Integer> negative15() {",
" Stream<Integer> negative16() {",
" return Stream.of(1);",
" }",
"",
Expand Down

0 comments on commit 8c6a0ac

Please sign in to comment.