diff options
author | Lars Grefer <eclipse@larsgrefer.de> | 2020-08-15 16:33:00 +0200 |
---|---|---|
committer | Lars Grefer <eclipse@larsgrefer.de> | 2020-08-15 16:36:00 +0200 |
commit | 2409bcbc7c9606b055e23f52d688eecda84351d6 (patch) | |
tree | e775e9d0e033ec563236c31623f66d023c40aac5 /testing/src | |
parent | 3641f1626df6b9b1c11dd3f16b01a01495f4662d (diff) | |
download | aspectj-2409bcbc7c9606b055e23f52d688eecda84351d6.tar.gz aspectj-2409bcbc7c9606b055e23f52d688eecda84351d6.zip |
Redundant Collection.addAll() call
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>
Diffstat (limited to 'testing/src')
7 files changed, 17 insertions, 30 deletions
diff --git a/testing/src/test/java/org/aspectj/testing/OutputSpec.java b/testing/src/test/java/org/aspectj/testing/OutputSpec.java index ca7d0f232..8e1fd2612 100644 --- a/testing/src/test/java/org/aspectj/testing/OutputSpec.java +++ b/testing/src/test/java/org/aspectj/testing/OutputSpec.java @@ -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)) { diff --git a/testing/src/test/java/org/aspectj/testing/harness/bridge/JavaRun.java b/testing/src/test/java/org/aspectj/testing/harness/bridge/JavaRun.java index ea88c49f1..acc3245ca 100644 --- a/testing/src/test/java/org/aspectj/testing/harness/bridge/JavaRun.java +++ b/testing/src/test/java/org/aspectj/testing/harness/bridge/JavaRun.java @@ -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)); diff --git a/testing/src/test/java/org/aspectj/testing/util/FileUtil.java b/testing/src/test/java/org/aspectj/testing/util/FileUtil.java index ab780cd29..71dfb7f2e 100644 --- a/testing/src/test/java/org/aspectj/testing/util/FileUtil.java +++ b/testing/src/test/java/org/aspectj/testing/util/FileUtil.java @@ -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); 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 23385db3a..ad9331dd3 100644 --- a/testing/src/test/java/org/aspectj/testing/util/LangUtil.java +++ b/testing/src/test/java/org/aspectj/testing/util/LangUtil.java @@ -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; diff --git a/testing/src/test/java/org/aspectj/testing/util/LangUtilTest.java b/testing/src/test/java/org/aspectj/testing/util/LangUtilTest.java index 30f2a0b06..6eede56a6 100644 --- a/testing/src/test/java/org/aspectj/testing/util/LangUtilTest.java +++ b/testing/src/test/java/org/aspectj/testing/util/LangUtilTest.java @@ -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); diff --git a/testing/src/test/java/org/aspectj/testing/util/MessageUtilTest.java b/testing/src/test/java/org/aspectj/testing/util/MessageUtilTest.java index 954ab38c0..abfff1ee6 100644 --- a/testing/src/test/java/org/aspectj/testing/util/MessageUtilTest.java +++ b/testing/src/test/java/org/aspectj/testing/util/MessageUtilTest.java @@ -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; diff --git a/testing/src/test/java/org/aspectj/testing/util/TestDiffs.java b/testing/src/test/java/org/aspectj/testing/util/TestDiffs.java index dbb0c1bb1..11dd15587 100644 --- a/testing/src/test/java/org/aspectj/testing/util/TestDiffs.java +++ b/testing/src/test/java/org/aspectj/testing/util/TestDiffs.java @@ -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); |