]> source.dussan.org Git - aspectj.git/commitdiff
Redundant Collection.addAll() call
authorLars Grefer <eclipse@larsgrefer.de>
Sat, 15 Aug 2020 14:33:00 +0000 (16:33 +0200)
committerLars Grefer <eclipse@larsgrefer.de>
Sat, 15 Aug 2020 14:36:00 +0000 (16:36 +0200)
Reports Collection.addAll() and Map.putAll() calls after instantiation of a collection using a constructor call without arguments. Such constructs can be replaced with a single call to a parametrized constructor which simplifies code. Also for some collections the replacement might be more performant.

Signed-off-by: Lars Grefer <eclipse@larsgrefer.de>
28 files changed:
ajde.core/src/main/java/org/aspectj/ajde/core/internal/AjdeCoreBuildManager.java
ajde.core/src/test/java/org/aspectj/ajde/core/tests/ShowWeaveMessagesTest.java
bcel-builder/src/main/java/org/aspectj/apache/bcel/generic/InstructionHandle.java
build/src/main/java/org/aspectj/internal/tools/ant/taskdefs/Checklics.java
build/src/main/java/org/aspectj/internal/tools/build/SampleGatherer.java
org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/ajc/BuildArgParser.java
org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/lookup/AjLookupEnvironment.java
org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/core/builder/AjBuildConfig.java
org.aspectj.ajdt.core/src/test/java/org/aspectj/ajdt/internal/compiler/batch/IncrementalCase.java
org.aspectj.matcher/src/main/java/org/aspectj/weaver/CrosscuttingMembers.java
org.aspectj.matcher/src/test/java/org/aspectj/weaver/patterns/ParserTestCase.java
taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/AjcTask.java
taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/compilers/Ajc.java
testing-drivers/src/test/java/org/aspectj/testing/drivers/Harness.java
testing/src/test/java/org/aspectj/testing/OutputSpec.java
testing/src/test/java/org/aspectj/testing/harness/bridge/JavaRun.java
testing/src/test/java/org/aspectj/testing/util/FileUtil.java
testing/src/test/java/org/aspectj/testing/util/LangUtil.java
testing/src/test/java/org/aspectj/testing/util/LangUtilTest.java
testing/src/test/java/org/aspectj/testing/util/MessageUtilTest.java
testing/src/test/java/org/aspectj/testing/util/TestDiffs.java
tests/src/test/java/org/aspectj/systemtest/model/ModelTestCase.java
util/src/main/java/org/aspectj/util/LangUtil.java
util/src/test/java/org/aspectj/util/FileUtilTest.java
weaver/src/main/java/org/aspectj/weaver/bcel/BcelClassWeaver.java
weaver/src/test/java/org/aspectj/weaver/ReferenceTypeTestCase.java
weaver/src/test/java/org/aspectj/weaver/bcel/AroundWeaveTestCase.java
weaver/src/test/java/org/aspectj/weaver/tools/Java15PointcutExpressionTest.java

index a8b82ce7f2067a1dddf17f3189f923762bd785a6..7aec208092963a8d954ef95b7ef82c5286ec48ef 100644 (file)
@@ -225,8 +225,7 @@ public class AjdeCoreBuildManager {
                        if (projectSourceFiles == null) {
                                return null;
                        }
-                       List<String> l = new ArrayList<>();
-                       l.addAll(projectSourceFiles);
+                       List<String> l = new ArrayList<>(projectSourceFiles);
                        // If the processor options are specified build the command line options for the JDT compiler to see
                        String processor = compilerConfig.getProcessor();
                        if (processor != null && processor.length() != 0) {
index c5fa43e16ca89b20d7f75386b83f3fffac637840..13597f14f03c528fc4f48f63a9b6683d9cde892c 100644 (file)
@@ -367,8 +367,7 @@ public class ShowWeaveMessagesTest extends AjdeCoreTestCase {
                        String line = null;
                        while ((line = fr.readLine()) != null)
                                fileContents.add(line);
-                       List<String> originalFileContents = new ArrayList<>();
-                       originalFileContents.addAll(fileContents);
+                       List<String> originalFileContents = new ArrayList<>(fileContents);
 
                        // See if the messages match
                        int msgCount = 0;
index c5c2448695dc80c06afcbe1945a142bbd473bc09..8c9c65ab7e4e3be0fecedfc8b3ef084414187236 100644 (file)
@@ -170,8 +170,7 @@ public class InstructionHandle implements java.io.Serializable {
        }
 
        public Set<InstructionTargeter> getTargetersCopy() {
-               Set<InstructionTargeter> copy = new HashSet<>();
-               copy.addAll(targeters);
+               Set<InstructionTargeter> copy = new HashSet<>(targeters);
                return copy;
        }
 
index ed64e74e01f914ac3ef15c9216673208cc0ef716..5d592243ce5ee6f9f9618fe71557d1b06ca0bd7f 100644 (file)
@@ -469,8 +469,7 @@ class HeaderInfo {
                this.lastLine = lastLine;
                this.file = file;
                this.hasLicense = hasLicense;
-               List<String> newYears = new ArrayList<>();
-               newYears.addAll(years);
+               List<String> newYears = new ArrayList<>(years);
                Collections.sort(newYears);
                this.years = Collections.unmodifiableList(newYears);
                if ((null == file) || !file.canWrite()) {
index 86782563f8466bab4dd0407a54823273452bb42a..bf9b9aab90b4dfe49eb23b93d4b14db33c8cfe25 100644 (file)
@@ -419,8 +419,7 @@ class Samples {
     }
 
     List<Sample> getSortedSamples(Comparator<Sample> comparer) {
-        ArrayList<Sample> result = new ArrayList<>();
-        result.addAll(samples);
+               ArrayList<Sample> result = new ArrayList<>(samples);
         result.sort(comparer);
         return result;
     }
index a68698697599d05f46ba119b35e165c2762c7ab7..c309a3a5aa6422e3e06cb159c7af44366072d440 100644 (file)
@@ -152,8 +152,7 @@ public class BuildArgParser extends Main {
 
                        boolean incrementalMode = buildConfig.isIncrementalMode() || buildConfig.isIncrementalFileMode();
 
-                       List<File> xmlfileList = new ArrayList<>();
-                       xmlfileList.addAll(parser.getXmlFiles());
+                       List<File> xmlfileList = new ArrayList<>(parser.getXmlFiles());
 
                        List<File> fileList = new ArrayList<>();
                        List<File> files = parser.getFiles();
index 809a73af82ce0496edd294fa86167d1a8b37fe0b..beea71dc9b0e537bfa1a82baf69793bd4ff7ea1d 100644 (file)
@@ -250,8 +250,7 @@ public class AjLookupEnvironment extends LookupEnvironment implements AnonymousC
                                Collections.addAll(typesToProcess, stbs);
                        }
 
-                       List<SourceTypeBinding> stb2 = new ArrayList<>();
-                       stb2.addAll(typesToProcess);
+                       List<SourceTypeBinding> stb2 = new ArrayList<>(typesToProcess);
 
                        while (typesToProcess.size() > 0) {
                                // A side effect of weaveIntertypes() is that the processed type is removed from the collection
index cfda723570a5e977508de59a4ba8e2cf12e4eb20..4fb176e881658bd917409bfbe7967505b221202d 100644 (file)
@@ -377,8 +377,7 @@ public class AjBuildConfig implements CompilerConfigurationChangeFlags {
         *         classpath), and output dir or jar
         */
        public List<String> getFullClasspath() {
-               List<String> full = new ArrayList<>();
-               full.addAll(getBootclasspath()); // XXX Is it OK that boot classpath overrides inpath/injars/aspectpath?
+               List<String> full = new ArrayList<>(getBootclasspath()); // XXX Is it OK that boot classpath overrides inpath/injars/aspectpath?
                for (File file: inJars) {
                        full.add(file.getAbsolutePath());
                }
index 355267b0fbf9c2bf139d3ccce6868dce21c422df..09ecdb34b3e61b79c2dfd79d4a3048536825a53b 100644 (file)
@@ -121,8 +121,7 @@ public class IncrementalCase { // XXX NOT bound to junit - bridge tests?
                        List safeFiles = Collections.unmodifiableList(files);
                        log("Compiling ", safeFiles, handler);
                        if (1 == i) {
-                               ArrayList<String> argList = new ArrayList<>();
-                               argList.addAll(getBaseArgs(targetSrc, targetClasses));
+                               ArrayList<String> argList = new ArrayList<>(getBaseArgs(targetSrc, targetClasses));
                                File[] fra = (File[]) safeFiles.toArray(new File[0]);
                                // sigh
                                argList.addAll(
index c3f22b0b14dd1e7308aa3c7cd3b5ce2520142274..d380e988e6663f816a3faa18413eb099de4aef2f 100644 (file)
@@ -293,8 +293,7 @@ public class CrosscuttingMembers {
                                        theseShadowMungers.add(munger);
                                }
                        }
-                       Set<ShadowMunger> tempSet = new HashSet<>();
-                       tempSet.addAll(other.shadowMungers);
+                       Set<ShadowMunger> tempSet = new HashSet<>(other.shadowMungers);
                        Set<ShadowMunger> otherShadowMungers = new HashSet<>();
                        Set<ShadowMunger> otherInlinedAroundMungers = new HashSet<>();
                        for (ShadowMunger munger : tempSet) {
index 9f524d83613eb35f2bd6f12f65327b879a12d846..f3609b7d74b420ad240300957ace9972f341c5a0 100644 (file)
@@ -700,8 +700,7 @@ public class ParserTestCase extends PatternsTestCase {
                WildAnnotationTypePattern watp = (WildAnnotationTypePattern) atp;
                Map<String,String> m = watp.annotationValues;
                Set<String> keys = m.keySet();
-               List<String> orderedKeys = new ArrayList<>();
-               orderedKeys.addAll(keys);
+               List<String> orderedKeys = new ArrayList<>(keys);
                Collections.sort(orderedKeys);
                StringBuffer sb = new StringBuffer();
                for (Iterator<String> iterator = orderedKeys.iterator(); iterator.hasNext();) {
index 83dcd9911ca2f11c36c9c6a93129ebfeddaa9bf4..c6ebb14b39d2ca032d0c1dc1aea4d46152d8bd92 100644 (file)
@@ -1159,7 +1159,6 @@ public class AjcTask extends MatchingTask {
 
        // package-private for testing
        String[] makeCommand() {
-               ArrayList result = new ArrayList();
                if (0 < ignored.size()) {
             for (Object o : ignored) {
                 logVerbose("ignored: " + o);
@@ -1182,7 +1181,7 @@ public class AjcTask extends MatchingTask {
                        outjarFixedup = true;
                }
 
-               result.addAll(cmd.extractArguments());
+               ArrayList result = new ArrayList(cmd.extractArguments());
                addListArgs(result);
 
                String[] command = (String[]) result.toArray(new String[0]);
index 25128bb61c228152b7b0236e9d6907765bcddb91..43125a862790edbdd39d63e9a8499b88afd0591c 100644 (file)
@@ -53,8 +53,7 @@ public class Ajc extends DefaultCompilerAdapter {
         "-encoding", "-target" });
 
     private static List<String> finalList(String[] args) {
-        List<String> result = new ArrayList<>();
-        result.addAll(Arrays.asList(args));
+        List<String> result = new ArrayList<>(Arrays.asList(args));
         return Collections.unmodifiableList(result);
     }
 
index 55295568ac0f13448d1155d51a3f7bc3b16cb4bf..42f4c4451dbb985fd958fdc3a6050b4d44c58900 100644 (file)
@@ -213,8 +213,7 @@ public class Harness {
                // read arguments
                final ArrayList<String> globals = new ArrayList<>();
                final ArrayList<String> files = new ArrayList<>();
-               final LinkedList<String> argList = new LinkedList<>();
-               argList.addAll(Arrays.asList(args));
+               final LinkedList<String> argList = new LinkedList<>(Arrays.asList(args));
                for (int i = 0; i < argList.size(); i++) {
                        String arg = argList.get(i);
                        List<String> aliases = aliasOptions(arg);
index ca7d0f23284d29c96450635c87f681f3d113d290..8e1fd261234c57cfd8b5f0821a642dd36905c11e 100644 (file)
@@ -87,10 +87,8 @@ public class OutputSpec {
                        createFailureMessage(output, -1, outputFound.size());
                        return;
                }
-               List<String> expected = new ArrayList<>();
-               expected.addAll(expectedOutputLines);
-               List<String> found = new ArrayList<>();
-               found.addAll(outputFound);
+               List<String> expected = new ArrayList<>(expectedOutputLines);
+               List<String> found = new ArrayList<>(outputFound);
                for (String lineFound : outputFound) {
                        for (String lineExpected : expectedOutputLines) {
                                if (lineFound.contains(lineExpected)) {
index ea88c49f1bc0589f8785b5e01c4729c1088333e4..acc3245caa0680c17160f1738cfd4fe5a413a6cd 100644 (file)
@@ -167,8 +167,7 @@ public class JavaRun implements IAjcRun {
                                        File[] files = sandbox.findFiles(spec.aspectpath);
                                        aspectURLs = FileUtil.getFileURLs(files);
                                }
-                               ArrayList classpath = new ArrayList();
-                               classpath.addAll(Arrays.asList(aspectURLs));
+                               ArrayList classpath = new ArrayList(Arrays.asList(aspectURLs));
                                final URL[] classURLs;
                                {
                                        classpath.addAll(Arrays.asList(clAndLibs));
index ab780cd29e52dc174ba1f7eed4d3a6e294bfaaec..71dfb7f2e5604b0ba1ec3948f86485cd00367407 100644 (file)
@@ -185,9 +185,8 @@ public class FileUtil {
                 // skip if not file or not right time
                 return false;
             }
-        };      
-        ArrayList unexp = new ArrayList();
-        unexp.addAll(Arrays.asList(dir.listFiles(touchedCollector)));
+        };
+               ArrayList unexp = new ArrayList(Arrays.asList(dir.listFiles(touchedCollector)));
         
         // report any unexpected changes
         return Diffs.makeDiffs(label, expected, unexp, String.CASE_INSENSITIVE_ORDER);
index 23385db3a8a246e4bfbb3cd769b43eacc6b49a03..ad9331dd359819bae8bcf37d1bbd08d17d18be08 100644 (file)
@@ -402,8 +402,7 @@ public class LangUtil {
      * @see Util#combine(Object[], Object[])
      */
     public static String[] combine(String[] one, String[] two) {
-        ArrayList twoList = new ArrayList();
-        twoList.addAll(org.aspectj.util.LangUtil.arrayAsList(two));
+               ArrayList twoList = new ArrayList(org.aspectj.util.LangUtil.arrayAsList(two));
         ArrayList result = new ArrayList();
         if (null != one) {
                        for (String s : one) {
@@ -938,13 +937,11 @@ public class LangUtil {
         if ((0 == actualListIn.size()) && (0 == expectedListIn.size()) ) {
             return;
         }
-        
-        ArrayList expected = new ArrayList();
-        expected.addAll(expectedListIn);
+
+               ArrayList expected = new ArrayList(expectedListIn);
         expected.sort(comparator);
-        
-        ArrayList actual = new ArrayList();
-        actual.addAll(actualListIn);
+
+               ArrayList actual = new ArrayList(actualListIn);
         actual.sort(comparator);
         Iterator actualIter = actual.iterator();        
         Object act = null;
index 30f2a0b063fd6a6898b49a4426a3aba584f9352c..6eede56a6d352fa70f532f74529ee6a8169f0b86 100644 (file)
@@ -269,8 +269,7 @@ public class LangUtilTest extends TestCase {
         if (unmodifiable) {
             return Collections.unmodifiableList(Arrays.asList(ra));
         } else {
-            ArrayList list = new ArrayList();
-            list.addAll(Arrays.asList(ra));
+                       ArrayList list = new ArrayList(Arrays.asList(ra));
             return list;
         }
     }
@@ -317,8 +316,7 @@ public class LangUtilTest extends TestCase {
         String label = one + "?=" + two;
         assertTrue(label, (null == one) == (null == two));
         if (null != one) {
-            ArrayList aone = new ArrayList();
-            aone.addAll(one);
+                       ArrayList aone = new ArrayList(one);
             ArrayList atwo = new ArrayList();
             aone.addAll(two);
             Collections.sort(aone);
index 954ab38c0acc48f36288be1706be8ff25bfa8f58..abfff1ee6d6c9bc302b21783fba7ba58c1c2e456 100644 (file)
@@ -71,9 +71,8 @@ public class MessageUtilTest extends TestCase {
 
     List getSampleMessageTexts() {
         if (null == messageTexts) {
-            ArrayList result = new ArrayList();
-            result.addAll(Arrays.asList(new String[]
-                { "one", "two", "now is the time for all good men..." }));
+                       ArrayList result = new ArrayList(Arrays.asList(new String[]
+                                       {"one", "two", "now is the time for all good men..."}));
             messageTexts = result;
         }
         return messageTexts;
index dbb0c1bb1a4bbc14337b5c52f801d100eca5b57e..11dd155874423a18d75c7b552e2709fd011d4a01 100644 (file)
@@ -141,8 +141,7 @@ public class TestDiffs { // XXX pretty dumb implementation
         * @return ArrayList with all input except those in trim (by name)
         */
        private static ArrayList trimByName(List input, List trim) {
-               ArrayList result = new ArrayList();
-        result.addAll(input);
+               ArrayList result = new ArrayList(input);
         if (!LangUtil.isEmpty(input) && !LangUtil.isEmpty(trim)) {
             for (ListIterator iter = result.listIterator(); iter.hasNext();) {
                                TestResult inputItem = (TestResult) iter.next();
@@ -281,8 +280,7 @@ public class TestDiffs { // XXX pretty dumb implementation
         actualFailed = safeList(failed);
 
         // stillPassing: expected.passed w/o broken, missingPasses
-        passed = new ArrayList();
-        passed.addAll(expectedPassed);
+               passed = new ArrayList(expectedPassed);
         passed = trimByName(passed, this.broken);
         ArrayList missingPasses = new ArrayList();
         ArrayList missingFails = new ArrayList();
@@ -291,8 +289,7 @@ public class TestDiffs { // XXX pretty dumb implementation
         stillPassing = safeList(passed);
 
         // stillFailing: expected.failed w/o fixed, missingFails
-        failed = new ArrayList();
-        failed.addAll(expectedFailed);
+               failed = new ArrayList(expectedFailed);
         failed = trimByName(failed, this.fixed);
         failed = trimByName(failed, missingFails); 
         stillFailing = safeList(failed);
index b18d9a5f74f1c7f01c5158939889bc0e277e39b6..550ff759a74d5bf5b37e15fb34b022c1b3b9b05a 100644 (file)
@@ -143,8 +143,7 @@ public abstract class ModelTestCase extends XMLBasedAjcTestCase {
                        while ((expectedLine = expect.readLine()) != null) {
                                fileContents.add(expectedLine);
                        }
-                       List<String> expectedFileContents = new ArrayList<>();
-                       expectedFileContents.addAll(fileContents);
+                       List<String> expectedFileContents = new ArrayList<>(fileContents);
 
                        // Load the file with the output from this test run
                        BufferedReader found = new BufferedReader(new FileReader(new File(modelOutput)));
index 98f53e3c859f1fe61ba5388475e11593687a23b5..e97438b0e07b9784d973affe2e6642a1222c189e 100644 (file)
@@ -1000,8 +1000,7 @@ public class LangUtil {
                if ((null == array) || (1 > array.length)) {
                        return Collections.emptyList();
                }
-               ArrayList<T> list = new ArrayList<>();
-               list.addAll(Arrays.asList(array));
+               ArrayList<T> list = new ArrayList<>(Arrays.asList(array));
                return list;
        }
 
index 7936914fb622349a0bb53eaf45227bac9e667a4c..f5466e2cff66dffdae09657c82500237e39b2827 100644 (file)
@@ -508,8 +508,7 @@ public class FileUtilTest extends TestCase {
                                errors.add(error);
                        }
                };
-               List<String> sourceList = new ArrayList<>();
-               sourceList.addAll(Arrays.asList(sources));
+               List<String> sourceList = new ArrayList<>(Arrays.asList(sources));
                sourceList = Collections.unmodifiableList(sourceList);
                for (int k = 0; k < sources.length; k++) {
                        List<String> result = FileUtil.lineSeek("" + k, sourceList, true, errorSink);
index 06735b523dd5e19ab18ba6f54c4a310d7f19edee..edf7a0c4859680e86dec4bee7850b321e84ec13e 100644 (file)
@@ -923,8 +923,7 @@ class BcelClassWeaver implements IClassWeaver {
                        return false; // nothing to do
                }
 
-               Set<DeclareAnnotation> unusedDecams = new HashSet<>();
-               unusedDecams.addAll(decaMs);
+               Set<DeclareAnnotation> unusedDecams = new HashSet<>(decaMs);
 
                // These methods may have been targeted with declare annotation.  Example: ITD on an interface
                // where the top most implementor gets a real method.  The top most implementor method
@@ -1413,8 +1412,7 @@ class BcelClassWeaver implements IClassWeaver {
 
                List<BcelField> fields = clazz.getFieldGens();
                if (fields != null) {
-                       Set<DeclareAnnotation> unusedDecafs = new HashSet<>();
-                       unusedDecafs.addAll(decafs);
+                       Set<DeclareAnnotation> unusedDecafs = new HashSet<>(decafs);
                        for (BcelField field : fields) {
                                if (!field.getName().startsWith(NameMangler.PREFIX)) {
                                        // Single first pass
index 2c99ee29f33225dcaa1fc642f07751490aa7614e..f9b020272ddcfefd2be6869af177fba0c91a1c37 100644 (file)
@@ -599,8 +599,7 @@ public class ReferenceTypeTestCase extends TestCase {
                        // ReferenceType.r = 0;
                        long stime = System.nanoTime();
                        for (int j = 0; j < 10; j++) {
-                               List objects2 = new ArrayList();
-                               objects2.addAll(objects);
+                               List objects2 = new ArrayList(objects);
                                PartialOrder.sort(objects2);
                        }
                        long etime = System.nanoTime();
index a9d1fe9b422bbf118205acaf564436f0883ff380..ea5037e2c020d50aa9908d11d69ae23c4665053a 100644 (file)
@@ -80,12 +80,10 @@ public class AroundWeaveTestCase extends WeaveTestCase {
     private void aroundTestAndOthers(String outName, final boolean matchOnlyPrintln)
             throws IOException 
     {
-                
-        List<ShadowMunger> l = new ArrayList<>();
 
-               // the afterReturning was taken out to avoid circular advice dependency        
+               // the afterReturning was taken out to avoid circular advice dependency
 
-        l.addAll(makeAdviceAll("before", matchOnlyPrintln));
+               List<ShadowMunger> l = new ArrayList<>(makeAdviceAll("before", matchOnlyPrintln));
         //l.addAll(makeAdviceAll("afterReturning", matchOnlyPrintln));
 
         l.add(makeAroundMunger(matchOnlyPrintln));
index 5181efcf67711869fb3612fb463429a1dc61ab52..ab15c2bd3f6270c98e205e4d8b653685283957de 100644 (file)
@@ -286,8 +286,7 @@ public class Java15PointcutExpressionTest extends TestCase {
          tps[parameterNumber].getAnnotationPattern().toString();
          
          // parameter type annotation checking
-         Set<String> expected = new HashSet<>();
-         expected.addAll(mpnv.getParameterTypeAnnotations());
+               Set<String> expected = new HashSet<>(mpnv.getParameterTypeAnnotations());
          
          StringTokenizer st = new StringTokenizer(expectedParameterTypeAnnotations==null?"":expectedParameterTypeAnnotations);
          while (st.hasMoreTokens()) {
@@ -305,8 +304,7 @@ public class Java15PointcutExpressionTest extends TestCase {
          }
          
          // parameter annotation checking
-         expected = new HashSet<>();
-         expected.addAll(mpnv.getParameterAnnotations());
+               expected = new HashSet<>(mpnv.getParameterAnnotations());
          
          st = new StringTokenizer(expectedParameterAnnotations==null?"":expectedParameterAnnotations);
          while (st.hasMoreTokens()) {