Merge branch 'use_addAll' into master

Refs #2733
This commit is contained in:
Clément Fournier
2020-08-25 14:50:58 +02:00
7 changed files with 8 additions and 17 deletions

View File

@ -188,6 +188,7 @@ are deprecated as internal API.
* [#2730](https://github.com/pmd/pmd/pull/2730): Cleanup: StringBuilder issues - [XenoAmess](https://github.com/XenoAmess)
* [#2731](https://github.com/pmd/pmd/pull/2731): Cleanup: avoid compiling Patterns repeatedly - [XenoAmess](https://github.com/XenoAmess)
* [#2732](https://github.com/pmd/pmd/pull/2732): Cleanup: use StandardCharsets instead of Charset.forName - [XenoAmess](https://github.com/XenoAmess)
* [#2733](https://github.com/pmd/pmd/pull/2733): Cleanup: Collection::addAll issues - [XenoAmess](https://github.com/XenoAmess)
* [#2734](https://github.com/pmd/pmd/pull/2734): Cleanup: use try with resources - [XenoAmess](https://github.com/XenoAmess)

View File

@ -563,11 +563,7 @@ interface ImmutableList<E> extends List<E> {
@Override
public List<E> toList() {
List<E> result = new ArrayList<>(size());
for (E item : this) {
result.add(item);
}
return result;
return new ArrayList<>(this);
}

View File

@ -58,8 +58,7 @@ public class JUnitUseExpectedRule extends AbstractJUnitRule {
if (child instanceof ASTMethodDeclaration) {
boolean isJUnitMethod = isJUnitMethod((ASTMethodDeclaration) child, data);
if (inAnnotation || isJUnitMethod) {
List<Node> found = new ArrayList<>();
found.addAll((List<Node>) visit((ASTMethodDeclaration) child, data));
List<Node> found = new ArrayList<>((List<Node>) visit((ASTMethodDeclaration) child, data));
for (Node name : found) {
addViolation(data, name);
}

View File

@ -32,8 +32,7 @@ public class UnusedPrivateFieldRule extends AbstractLombokAwareRule {
@Override
protected Collection<String> defaultSuppressionAnnotations() {
Collection<String> defaultValues = new ArrayList<>();
defaultValues.addAll(super.defaultSuppressionAnnotations());
Collection<String> defaultValues = new ArrayList<>(super.defaultSuppressionAnnotations());
defaultValues.add("java.lang.Deprecated");
defaultValues.add("javafx.fxml.FXML");
defaultValues.add("lombok.experimental.Delegate");

View File

@ -61,8 +61,7 @@ public class SingularFieldRule extends AbstractLombokAwareRule {
@Override
protected Collection<String> defaultSuppressionAnnotations() {
Collection<String> defaultValues = new ArrayList<>();
defaultValues.addAll(super.defaultSuppressionAnnotations());
Collection<String> defaultValues = new ArrayList<>(super.defaultSuppressionAnnotations());
defaultValues.add("lombok.experimental.Delegate");
defaultValues.add("lombok.EqualsAndHashCode");
return defaultValues;

View File

@ -19,8 +19,7 @@ public class MethodFirstPhase {
Exception b = vararg((Number) null);
Set<String> set = new HashSet<>();
set.addAll(Arrays.asList("a", "b")); // TODO: return type of method call Arrays.asList is missing
Set<String> set = new HashSet<>(Arrays.asList("a", "b")); // TODO: return type of method call Arrays.asList is missing
List<String> myList = new ArrayList<>();
Collections.sort(myList); // TODO: generic type variables on methods

View File

@ -784,8 +784,7 @@ public class JspDocStyleTest extends AbstractJspNodesTst {
* @return
*/
private List<ASTElement> sortNodesByName(Collection<ASTElement> elements) {
List<ASTElement> list = new ArrayList<>();
list.addAll(elements);
List<ASTElement> list = new ArrayList<>(elements);
Collections.sort(list, new Comparator<ASTElement>() {
public int compare(ASTElement o1, ASTElement o2) {
if (o1.getName() == null) {
@ -812,8 +811,7 @@ public class JspDocStyleTest extends AbstractJspNodesTst {
* @return
*/
private <T extends Node> List<T> sortByImage(Collection<T> elements) {
List<T> list = new ArrayList<>();
list.addAll(elements);
List<T> list = new ArrayList<>(elements);
Collections.sort(list, new Comparator<Node>() {
public int compare(Node o1, Node o2) {
if (o1.getImage() == null) {