]> source.dussan.org Git - aspectj.git/commitdiff
Collections.sort() can be replaced with List.sort()
authorLars Grefer <eclipse@larsgrefer.de>
Sat, 15 Aug 2020 14:13:00 +0000 (16:13 +0200)
committerLars Grefer <eclipse@larsgrefer.de>
Sat, 15 Aug 2020 14:13:00 +0000 (16:13 +0200)
Reports calls to Collections.sort(list, comparator) which could be replaced with list.sort(comparator).

Signed-off-by: Lars Grefer <eclipse@larsgrefer.de>
12 files changed:
ajde/src/main/java/org/aspectj/ajde/internal/LstBuildConfigManager.java
ajde/src/main/java/org/aspectj/ajde/ui/internal/TreeStructureViewBuilder.java
bcel-builder/src/main/java/org/aspectj/apache/bcel/generic/ClassGen.java
build/src/main/java/org/aspectj/internal/tools/build/SampleGatherer.java
testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCase.java
testing/src/test/java/org/aspectj/testing/util/Diffs.java
testing/src/test/java/org/aspectj/testing/util/LangUtil.java
tests/src/test/java/org/aspectj/systemtest/incremental/tools/MultiProjectIncrementalTests.java
weaver/src/main/java/org/aspectj/weaver/bcel/AtAjAttributes.java
weaver/src/main/java/org/aspectj/weaver/bcel/BcelClassWeaver.java
weaver/src/main/java/org/aspectj/weaver/bcel/BcelWeaver.java
weaver/src/main/java/org/aspectj/weaver/bcel/LazyClassGen.java

index cde164cc1c800c9cc56e78097c1d337d19453934..20db175811fc5905c294ecb19d303b7bd100c24e 100644 (file)
@@ -291,7 +291,7 @@ public class LstBuildConfigManager implements BuildConfigManager {
        private void sortModel(BuildConfigNode node, Comparator<BuildConfigNode> 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);
index 23f999ac88d9035fc45cf44cc2137c3b924ba232..a8a07ee344dc193e84c29afb1bcf27537b376e44 100644 (file)
@@ -196,7 +196,7 @@ public class TreeStructureViewBuilder {
 
        private void sortView(IStructureViewNode node, Comparator<IStructureViewNode> 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);
index 943b77f6e6c20a49cfa06179788a955a632e57ce..371013997e2d2606d13a3a0f1e08625bdeb824a2 100644 (file)
@@ -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, <clinit>.
index ca041b33dcab15ee825e146c3cd35e203929c5bb..ce7f2ce27ba853be1331767c4a32487036ffde4e 100644 (file)
@@ -421,7 +421,7 @@ class Samples {
     List<Sample> getSortedSamples(Comparator<Sample> comparer) {
         ArrayList<Sample> result = new ArrayList<>();
         result.addAll(samples);
-        Collections.sort(result, comparer);
+        result.sort(comparer);
         return result;
     }
 }
index 81e2616ea3c9fd9e3d9c8830beefe8c60a608e1a..dbb5557cc11d652d1d45622bba083973ce021fd7 100644 (file)
@@ -416,7 +416,7 @@ public abstract class XMLBasedAjcTestCase extends AjcTestCase {
                List<LocalVariable> l = new ArrayList<>();
                LocalVariable lv[] = lvt.getLocalVariableTable();
                Collections.addAll(l, lv);
-               Collections.sort(l, new MyComparator());
+               l.sort(new MyComparator());
                return l;
        }
 
index c9a58e99f49838de2c2e76bebb6ad898fbb726ac..e95ab3184b6fdcc830fd52eaca12ef8c6584eb6d 100644 (file)
@@ -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;
        }
 
index ddf3a832a20090e22ac8ac0915193befd63db58b..23385db3a8a246e4bfbb3cd769b43eacc6b49a03 100644 (file)
@@ -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;
         
index 30793c396aea26b6de0507a962af2c0f8fab1682..49663211fe92ab1c517a7d09e63d4ce784b99291 100644 (file)
@@ -2170,8 +2170,8 @@ public class MultiProjectIncrementalTests extends AbstractMultiProjectIncrementa
                assertFalse(typeA.isMissing());
                List<ResolvedMember> viaIteratorList = getThemAll(typeA.getMethods(wantGenerics, true));
                List<ResolvedMember> 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));
        }
index b91496ea710f5403e4d4ce5a98f081e571baa2e3..96222fba2dc0ac863ce14451fd9df51270f4a1d0 100644 (file)
@@ -1785,7 +1785,7 @@ public class AtAjAttributes {
                }
 
                // sort by index
-               Collections.sort(arguments, new Comparator<MethodArgument>() {
+               arguments.sort(new Comparator<MethodArgument>() {
                        public int compare(MethodArgument mo, MethodArgument mo1) {
                                if (mo.indexOnStack == mo1.indexOnStack) {
                                        return 0;
index bbad8ed6a2feeeec760f01cb7cf1104972fef152..06735b523dd5e19ab18ba6f54c4a310d7f19edee 100644 (file)
@@ -2593,7 +2593,7 @@ class BcelClassWeaver implements IClassWeaver {
        }
 
        private void weaveInAddedMethods() {
-               Collections.sort(addedLazyMethodGens, new Comparator<LazyMethodGen>() {
+               addedLazyMethodGens.sort(new Comparator<LazyMethodGen>() {
                        public int compare(LazyMethodGen aa, LazyMethodGen bb) {
                                int i = aa.getName().compareTo(bb.getName());
                                if (i != 0) {
index a6809f26f821255e10adbbb3b298dbda5d2ae94e..b80080ec1d54e42660df7abc129616aeeb0fb666 100644 (file)
@@ -548,7 +548,7 @@ public class BcelWeaver {
                // this code may need
                // a bit of alteration...
 
-               Collections.sort(shadowMungerList, new Comparator<ShadowMunger>() {
+               shadowMungerList.sort(new Comparator<ShadowMunger>() {
                        public int compare(ShadowMunger sm1, ShadowMunger sm2) {
                                if (sm1.getSourceLocation() == null) {
                                        return (sm2.getSourceLocation() == null ? 0 : 1);
index 46f0958e691dc38b58557daa05cb8545fbff56b7..f2e61c56542f05e96ccb5628ddef236f63c05f9f 100644 (file)
@@ -1260,7 +1260,7 @@ public final class LazyClassGen {
                lists.add(list);
 
                List<Map.Entry<BcelShadow, Field>> entries = new ArrayList<>(tjpFields.entrySet());
-               Collections.sort(entries, new Comparator<Map.Entry<BcelShadow, Field>>() {
+               entries.sort(new Comparator<Map.Entry<BcelShadow, Field>>() {
                        @Override
                        public int compare(Map.Entry<BcelShadow, Field> a, Map.Entry<BcelShadow, Field> b) {
                                return (a.getValue()).getName().compareTo((b.getValue()).getName());