From efa2e5ce8c9cc2d20ab7479d1caa4a2ae1de6e8a Mon Sep 17 00:00:00 2001 From: Lars Grefer Date: Sat, 15 Aug 2020 16:13:00 +0200 Subject: [PATCH] Collections.sort() can be replaced with List.sort() Reports calls to Collections.sort(list, comparator) which could be replaced with list.sort(comparator). Signed-off-by: Lars Grefer --- .../org/aspectj/ajde/internal/LstBuildConfigManager.java | 2 +- .../aspectj/ajde/ui/internal/TreeStructureViewBuilder.java | 2 +- .../main/java/org/aspectj/apache/bcel/generic/ClassGen.java | 6 +++--- .../org/aspectj/internal/tools/build/SampleGatherer.java | 2 +- .../test/java/org/aspectj/testing/XMLBasedAjcTestCase.java | 2 +- testing/src/test/java/org/aspectj/testing/util/Diffs.java | 4 ++-- .../src/test/java/org/aspectj/testing/util/LangUtil.java | 4 ++-- .../incremental/tools/MultiProjectIncrementalTests.java | 4 ++-- .../main/java/org/aspectj/weaver/bcel/AtAjAttributes.java | 2 +- .../main/java/org/aspectj/weaver/bcel/BcelClassWeaver.java | 2 +- .../src/main/java/org/aspectj/weaver/bcel/BcelWeaver.java | 2 +- .../src/main/java/org/aspectj/weaver/bcel/LazyClassGen.java | 2 +- 12 files changed, 17 insertions(+), 17 deletions(-) diff --git a/ajde/src/main/java/org/aspectj/ajde/internal/LstBuildConfigManager.java b/ajde/src/main/java/org/aspectj/ajde/internal/LstBuildConfigManager.java index cde164cc1..20db17581 100644 --- a/ajde/src/main/java/org/aspectj/ajde/internal/LstBuildConfigManager.java +++ b/ajde/src/main/java/org/aspectj/ajde/internal/LstBuildConfigManager.java @@ -291,7 +291,7 @@ public class LstBuildConfigManager implements BuildConfigManager { private void sortModel(BuildConfigNode node, Comparator comparator) { if (node == null || node.getChildren() == null) return; - Collections.sort(node.getChildren(), comparator); + node.getChildren().sort(comparator); for (BuildConfigNode nextNode : node.getChildren()) { if (nextNode != null) sortModel(nextNode, comparator); diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/internal/TreeStructureViewBuilder.java b/ajde/src/main/java/org/aspectj/ajde/ui/internal/TreeStructureViewBuilder.java index 23f999ac8..a8a07ee34 100644 --- a/ajde/src/main/java/org/aspectj/ajde/ui/internal/TreeStructureViewBuilder.java +++ b/ajde/src/main/java/org/aspectj/ajde/ui/internal/TreeStructureViewBuilder.java @@ -196,7 +196,7 @@ public class TreeStructureViewBuilder { private void sortView(IStructureViewNode node, Comparator comparator) { if (node == null || node.getChildren() == null) return; - Collections.sort(node.getChildren(), comparator); + node.getChildren().sort(comparator); for (Object o : node.getChildren()) { IStructureViewNode nextNode = (IStructureViewNode) o; if (nextNode != null) sortView(nextNode, comparator); diff --git a/bcel-builder/src/main/java/org/aspectj/apache/bcel/generic/ClassGen.java b/bcel-builder/src/main/java/org/aspectj/apache/bcel/generic/ClassGen.java index 943b77f6e..371013997 100644 --- a/bcel-builder/src/main/java/org/aspectj/apache/bcel/generic/ClassGen.java +++ b/bcel-builder/src/main/java/org/aspectj/apache/bcel/generic/ClassGen.java @@ -509,7 +509,7 @@ public class ClassGen extends Modifiers implements Cloneable { relevantFields.add(field); } } - Collections.sort(relevantFields, new FieldComparator()); + relevantFields.sort(new FieldComparator()); int relevantFlags = Constants.ACC_PUBLIC | Constants.ACC_PRIVATE | Constants.ACC_PROTECTED | Constants.ACC_STATIC | Constants.ACC_FINAL | Constants.ACC_VOLATILE | Constants.ACC_TRANSIENT; for (Field f : relevantFields) { @@ -534,8 +534,8 @@ public class ClassGen extends Modifiers implements Cloneable { relevantMethods.add(m); } } - Collections.sort(relevantCtors, new ConstructorComparator()); - Collections.sort(relevantMethods, new MethodComparator()); + relevantCtors.sort(new ConstructorComparator()); + relevantMethods.sort(new MethodComparator()); // 5. If a class initializer exists, write out the following: // 1. The name of the method, . diff --git a/build/src/main/java/org/aspectj/internal/tools/build/SampleGatherer.java b/build/src/main/java/org/aspectj/internal/tools/build/SampleGatherer.java index ca041b33d..ce7f2ce27 100644 --- a/build/src/main/java/org/aspectj/internal/tools/build/SampleGatherer.java +++ b/build/src/main/java/org/aspectj/internal/tools/build/SampleGatherer.java @@ -421,7 +421,7 @@ class Samples { List getSortedSamples(Comparator comparer) { ArrayList result = new ArrayList<>(); result.addAll(samples); - Collections.sort(result, comparer); + result.sort(comparer); return result; } } diff --git a/testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCase.java b/testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCase.java index 81e2616ea..dbb5557cc 100644 --- a/testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCase.java +++ b/testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCase.java @@ -416,7 +416,7 @@ public abstract class XMLBasedAjcTestCase extends AjcTestCase { List l = new ArrayList<>(); LocalVariable lv[] = lvt.getLocalVariableTable(); Collections.addAll(l, lv); - Collections.sort(l, new MyComparator()); + l.sort(new MyComparator()); return l; } diff --git a/testing/src/test/java/org/aspectj/testing/util/Diffs.java b/testing/src/test/java/org/aspectj/testing/util/Diffs.java index c9a58e99f..e95ab3184 100644 --- a/testing/src/test/java/org/aspectj/testing/util/Diffs.java +++ b/testing/src/test/java/org/aspectj/testing/util/Diffs.java @@ -452,7 +452,7 @@ public class Diffs { if (LangUtil.isEmpty(skip)) { sink.addAll(Arrays.asList(source)); - Collections.sort(sink, MESSAGE_LINEKIND); + sink.sort(MESSAGE_LINEKIND); return sink; } for (IMessage message : source) { @@ -467,7 +467,7 @@ public class Diffs { sink.add(message); } } - Collections.sort(sink, MESSAGE_LINEKIND); + sink.sort(MESSAGE_LINEKIND); return sink; } diff --git a/testing/src/test/java/org/aspectj/testing/util/LangUtil.java b/testing/src/test/java/org/aspectj/testing/util/LangUtil.java index ddf3a832a..23385db3a 100644 --- a/testing/src/test/java/org/aspectj/testing/util/LangUtil.java +++ b/testing/src/test/java/org/aspectj/testing/util/LangUtil.java @@ -941,11 +941,11 @@ public class LangUtil { ArrayList expected = new ArrayList(); expected.addAll(expectedListIn); - Collections.sort(expected, comparator); + expected.sort(comparator); ArrayList actual = new ArrayList(); actual.addAll(actualListIn); - Collections.sort(actual, comparator); + actual.sort(comparator); Iterator actualIter = actual.iterator(); Object act = null; diff --git a/tests/src/test/java/org/aspectj/systemtest/incremental/tools/MultiProjectIncrementalTests.java b/tests/src/test/java/org/aspectj/systemtest/incremental/tools/MultiProjectIncrementalTests.java index 30793c396..49663211f 100644 --- a/tests/src/test/java/org/aspectj/systemtest/incremental/tools/MultiProjectIncrementalTests.java +++ b/tests/src/test/java/org/aspectj/systemtest/incremental/tools/MultiProjectIncrementalTests.java @@ -2170,8 +2170,8 @@ public class MultiProjectIncrementalTests extends AbstractMultiProjectIncrementa assertFalse(typeA.isMissing()); List viaIteratorList = getThemAll(typeA.getMethods(wantGenerics, true)); List directlyList = typeA.getMethodsWithoutIterator(true, true, wantGenerics); - Collections.sort(viaIteratorList, new ResolvedMemberComparator()); - Collections.sort(directlyList, new ResolvedMemberComparator()); + viaIteratorList.sort(new ResolvedMemberComparator()); + directlyList.sort(new ResolvedMemberComparator()); compare(viaIteratorList, directlyList, name); // System.out.println(toString(viaIteratorList, directlyList, genericsAware)); } diff --git a/weaver/src/main/java/org/aspectj/weaver/bcel/AtAjAttributes.java b/weaver/src/main/java/org/aspectj/weaver/bcel/AtAjAttributes.java index b91496ea7..96222fba2 100644 --- a/weaver/src/main/java/org/aspectj/weaver/bcel/AtAjAttributes.java +++ b/weaver/src/main/java/org/aspectj/weaver/bcel/AtAjAttributes.java @@ -1785,7 +1785,7 @@ public class AtAjAttributes { } // sort by index - Collections.sort(arguments, new Comparator() { + arguments.sort(new Comparator() { public int compare(MethodArgument mo, MethodArgument mo1) { if (mo.indexOnStack == mo1.indexOnStack) { return 0; diff --git a/weaver/src/main/java/org/aspectj/weaver/bcel/BcelClassWeaver.java b/weaver/src/main/java/org/aspectj/weaver/bcel/BcelClassWeaver.java index bbad8ed6a..06735b523 100644 --- a/weaver/src/main/java/org/aspectj/weaver/bcel/BcelClassWeaver.java +++ b/weaver/src/main/java/org/aspectj/weaver/bcel/BcelClassWeaver.java @@ -2593,7 +2593,7 @@ class BcelClassWeaver implements IClassWeaver { } private void weaveInAddedMethods() { - Collections.sort(addedLazyMethodGens, new Comparator() { + addedLazyMethodGens.sort(new Comparator() { public int compare(LazyMethodGen aa, LazyMethodGen bb) { int i = aa.getName().compareTo(bb.getName()); if (i != 0) { diff --git a/weaver/src/main/java/org/aspectj/weaver/bcel/BcelWeaver.java b/weaver/src/main/java/org/aspectj/weaver/bcel/BcelWeaver.java index a6809f26f..b80080ec1 100644 --- a/weaver/src/main/java/org/aspectj/weaver/bcel/BcelWeaver.java +++ b/weaver/src/main/java/org/aspectj/weaver/bcel/BcelWeaver.java @@ -548,7 +548,7 @@ public class BcelWeaver { // this code may need // a bit of alteration... - Collections.sort(shadowMungerList, new Comparator() { + shadowMungerList.sort(new Comparator() { public int compare(ShadowMunger sm1, ShadowMunger sm2) { if (sm1.getSourceLocation() == null) { return (sm2.getSourceLocation() == null ? 0 : 1); diff --git a/weaver/src/main/java/org/aspectj/weaver/bcel/LazyClassGen.java b/weaver/src/main/java/org/aspectj/weaver/bcel/LazyClassGen.java index 46f0958e6..f2e61c565 100644 --- a/weaver/src/main/java/org/aspectj/weaver/bcel/LazyClassGen.java +++ b/weaver/src/main/java/org/aspectj/weaver/bcel/LazyClassGen.java @@ -1260,7 +1260,7 @@ public final class LazyClassGen { lists.add(list); List> entries = new ArrayList<>(tjpFields.entrySet()); - Collections.sort(entries, new Comparator>() { + entries.sort(new Comparator>() { @Override public int compare(Map.Entry a, Map.Entry b) { return (a.getValue()).getName().compareTo((b.getValue()).getName()); -- 2.39.5