From 2409bcbc7c9606b055e23f52d688eecda84351d6 Mon Sep 17 00:00:00 2001 From: Lars Grefer Date: Sat, 15 Aug 2020 16:33:00 +0200 Subject: 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 --- weaver/src/main/java/org/aspectj/weaver/bcel/BcelClassWeaver.java | 6 ++---- weaver/src/test/java/org/aspectj/weaver/ReferenceTypeTestCase.java | 3 +-- .../src/test/java/org/aspectj/weaver/bcel/AroundWeaveTestCase.java | 6 ++---- .../java/org/aspectj/weaver/tools/Java15PointcutExpressionTest.java | 6 ++---- 4 files changed, 7 insertions(+), 14 deletions(-) (limited to 'weaver/src') 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 06735b523..edf7a0c48 100644 --- a/weaver/src/main/java/org/aspectj/weaver/bcel/BcelClassWeaver.java +++ b/weaver/src/main/java/org/aspectj/weaver/bcel/BcelClassWeaver.java @@ -923,8 +923,7 @@ class BcelClassWeaver implements IClassWeaver { return false; // nothing to do } - Set unusedDecams = new HashSet<>(); - unusedDecams.addAll(decaMs); + Set 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 fields = clazz.getFieldGens(); if (fields != null) { - Set unusedDecafs = new HashSet<>(); - unusedDecafs.addAll(decafs); + Set unusedDecafs = new HashSet<>(decafs); for (BcelField field : fields) { if (!field.getName().startsWith(NameMangler.PREFIX)) { // Single first pass diff --git a/weaver/src/test/java/org/aspectj/weaver/ReferenceTypeTestCase.java b/weaver/src/test/java/org/aspectj/weaver/ReferenceTypeTestCase.java index 2c99ee29f..f9b020272 100644 --- a/weaver/src/test/java/org/aspectj/weaver/ReferenceTypeTestCase.java +++ b/weaver/src/test/java/org/aspectj/weaver/ReferenceTypeTestCase.java @@ -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(); diff --git a/weaver/src/test/java/org/aspectj/weaver/bcel/AroundWeaveTestCase.java b/weaver/src/test/java/org/aspectj/weaver/bcel/AroundWeaveTestCase.java index a9d1fe9b4..ea5037e2c 100644 --- a/weaver/src/test/java/org/aspectj/weaver/bcel/AroundWeaveTestCase.java +++ b/weaver/src/test/java/org/aspectj/weaver/bcel/AroundWeaveTestCase.java @@ -80,12 +80,10 @@ public class AroundWeaveTestCase extends WeaveTestCase { private void aroundTestAndOthers(String outName, final boolean matchOnlyPrintln) throws IOException { - - List 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 l = new ArrayList<>(makeAdviceAll("before", matchOnlyPrintln)); //l.addAll(makeAdviceAll("afterReturning", matchOnlyPrintln)); l.add(makeAroundMunger(matchOnlyPrintln)); diff --git a/weaver/src/test/java/org/aspectj/weaver/tools/Java15PointcutExpressionTest.java b/weaver/src/test/java/org/aspectj/weaver/tools/Java15PointcutExpressionTest.java index 5181efcf6..ab15c2bd3 100644 --- a/weaver/src/test/java/org/aspectj/weaver/tools/Java15PointcutExpressionTest.java +++ b/weaver/src/test/java/org/aspectj/weaver/tools/Java15PointcutExpressionTest.java @@ -286,8 +286,7 @@ public class Java15PointcutExpressionTest extends TestCase { tps[parameterNumber].getAnnotationPattern().toString(); // parameter type annotation checking - Set expected = new HashSet<>(); - expected.addAll(mpnv.getParameterTypeAnnotations()); + Set 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()) { -- cgit v1.2.3