Skip to content

Commit

Permalink
suggest addAll only for more than 3 repeated add and fix the marked…
Browse files Browse the repository at this point in the history
… position
  • Loading branch information
Luro02 committed Apr 6, 2024
1 parent 6e603b3 commit 49e6adb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
ProblemType.COMMON_REIMPLEMENTATION_ADD_ALL
})
public class CollectionAddAll extends IntegratedCheck {
private static final int MIN_ADD_ALL_SIZE = 4;

private record AddInvocation(
CtVariableReference<?> collection,
CtExecutableReference<?> executableReference,
Expand Down Expand Up @@ -117,9 +119,13 @@ private void reportProblem(CtVariable<?> ctVariable, List<? extends CtExpression
return;
}

if (addedValues.size() < MIN_ADD_ALL_SIZE) {
return;
}


addLocalProblem(
ctVariable,
addedValues.get(0).getParent(CtStatement.class),
new LocalizedMessage(
"common-reimplementation",
Map.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@ public void foo(List<String> list) {
list.add(" ");
list.add("a");
list.add("b");
list.add("c");
}
}
"""
), PROBLEM_TYPES);

assertEqualsReimplementation(problems.next(), "list.addAll(List.of(\" \", \"a\", \"b\"))");
assertEqualsReimplementation(problems.next(), "list.addAll(List.of(\" \", \"a\", \"b\", \"c\"))");

problems.assertExhausted();
}
Expand Down

0 comments on commit 49e6adb

Please sign in to comment.