]> source.dussan.org Git - aspectj.git/commitdiff
Manual array to collection copy
authorLars Grefer <eclipse@larsgrefer.de>
Sat, 15 Aug 2020 14:06:32 +0000 (16:06 +0200)
committerLars Grefer <eclipse@larsgrefer.de>
Sat, 15 Aug 2020 14:06:32 +0000 (16:06 +0200)
Reports the copying of array contents to a collection where each element is added individually using a for loop. Such constructs may be replaced by a call to Collection.addAll(Arrays.asList()) or Collections.addAll().

Signed-off-by: Lars Grefer <eclipse@larsgrefer.de>
ajdoc/src/main/java/org/aspectj/tools/ajdoc/Main.java
bcel-builder/src/main/java/org/aspectj/apache/bcel/classfile/JavaClass.java
org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/lookup/AjLookupEnvironment.java
org.aspectj.ajdt.core/src/test/java/org/aspectj/ajdt/internal/compiler/batch/CommandTestCase.java
org.aspectj.ajdt.core/src/test/java/org/aspectj/tools/ajc/Ajc.java
org.aspectj.ajdt.core/src/test/java/org/aspectj/tools/ajc/AjcTestCase.java
org.aspectj.matcher/src/main/java/org/aspectj/weaver/AbstractReferenceTypeDelegate.java
testing/src/test/java/org/aspectj/internal/tools/ant/taskdefs/Ajctest.java
testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCase.java
testing/src/test/java/org/aspectj/testing/util/options/Values.java
weaver/src/main/java/org/aspectj/weaver/bcel/BcelObjectType.java

index 26857b41c00f08ed7f7396841f5f5979dcd7d2c6..57b7bce6ed64c6a2807ccf9918b899a879123a89 100644 (file)
@@ -22,14 +22,7 @@ import java.io.FileOutputStream;
 import java.io.FileReader;
 import java.io.FilenameFilter;
 import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.StringTokenizer;
-import java.util.Vector;
+import java.util.*;
 
 import org.aspectj.asm.AsmManager;
 import org.aspectj.bridge.IMessage;
@@ -262,9 +255,7 @@ public class Main implements Config {
                                javadocargs[numExtraArgs + options.size() + packageList.size() + k] = fileList.elementAt(k);
                        }
                        options = new Vector<>();
-                       for (String a: javadocargs) {
-                               options.add(a);
-                       }
+                       Collections.addAll(options, javadocargs);
                } else {
                        javadocargs = new String[options.size() + signatureFiles.length];
                        for (int k = 0; k < options.size(); k++) {
index dd1097ff04853560a4a7f4ea65e51a80c450549d..bb42a07ee444bede102382efedf1261f66bae229 100644 (file)
@@ -60,12 +60,7 @@ import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Queue;
-import java.util.StringTokenizer;
+import java.util.*;
 
 import org.aspectj.apache.bcel.Constants;
 import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen;
@@ -791,9 +786,7 @@ public class JavaClass extends Modifiers implements Cloneable, Node {
                                }
                        }
 
-                       for (JavaClass anInterface : interfaces) {
-                               queue.add(anInterface);
-                       }
+                       Collections.addAll(queue, interfaces);
                }
 
                return interfaceList;
index d79755dde9f1ece4ea88c51cf6323fd35480e82c..809a73af82ce0496edd294fa86167d1a8b37fe0b 100644 (file)
 package org.aspectj.ajdt.internal.compiler.lookup;
 
 import java.lang.reflect.Modifier;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
 
 import org.aspectj.ajdt.internal.compiler.CommonPrinter;
 import org.aspectj.ajdt.internal.compiler.ast.AspectDeclaration;
@@ -254,9 +247,7 @@ public class AjLookupEnvironment extends LookupEnvironment implements AnonymousC
                        for (int i = lastCompletedUnitIndex + 1; i <= lastUnitIndex; i++) {
                                CompilationUnitScope cus = units[i].scope;
                                SourceTypeBinding[] stbs = cus.topLevelTypes;
-                               for (SourceTypeBinding stb : stbs) {
-                                       typesToProcess.add(stb);
-                               }
+                               Collections.addAll(typesToProcess, stbs);
                        }
 
                        List<SourceTypeBinding> stb2 = new ArrayList<>();
index 1a3cc12b2622ecf990236e2bca6602dcdbc01b04..6e163efc067f6272fe16a801385aef46d0137923 100644 (file)
@@ -14,10 +14,7 @@ package org.aspectj.ajdt.internal.compiler.batch;
 
 import java.io.File;
 import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
+import java.util.*;
 
 import junit.framework.TestCase;
 
@@ -74,9 +71,7 @@ public abstract class CommandTestCase extends TestCase {
 
                args.add("-g"); // XXX need this to get sourcefile and line numbers, shouldn't
 
-               for (String extraArg : extraArgs) {
-                       args.add(extraArg);
-               }
+               Collections.addAll(args, extraArgs);
 
                args.add(Constants.TESTDATA_PATH + "/" + source);
 
index 15fdf0d9fed328e3f4a513f8fbcac67a3e4be992..138e6538cec004ca4a6f337b8e73f11cb122f676 100644 (file)
@@ -17,6 +17,7 @@ import java.io.FilenameFilter;
 import java.io.IOException;
 import java.io.PrintStream;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.StringTokenizer;
 
@@ -310,9 +311,7 @@ public class Ajc {
        }
 
        private void addMessagesTo(List<IMessage> aList, IMessage[] messages) {
-               for (IMessage message : messages) {
-                       aList.add(message);
-               }
+               Collections.addAll(aList, messages);
        }
 
        private boolean isIncremental(String[] args) {
index d5238b477f0ab3429548508002180e83fe29efc8..518f944c8c013adf87a4d7271b1d86a7032fdd41 100644 (file)
@@ -523,9 +523,7 @@ public abstract class AjcTestCase extends TestCase {
         */
        protected List newMessageList(Message[] messages) {
                List ret = new ArrayList();
-               for (Message message : messages) {
-                       ret.add(message);
-               }
+               Collections.addAll(ret, messages);
                return ret;
        }
 
index 2d969c2f83c7e51bb1c72320b599767d0a3c2034..763f78f0b8f187ecd6bb4f954b71ea69fbfd1d9d 100644 (file)
@@ -13,6 +13,7 @@
 package org.aspectj.weaver;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
 import org.aspectj.bridge.ISourceLocation;
@@ -135,15 +136,11 @@ public abstract class AbstractReferenceTypeDelegate implements ReferenceTypeDele
                AbstractReferenceTypeDelegate outerObjectType = (AbstractReferenceTypeDelegate) outerDelegate;
                if (outerObjectType.isNested()) {
                        GenericSignature.FormalTypeParameter[] parentParams = outerObjectType.getFormalTypeParametersFromOuterClass();
-                       for (GenericSignature.FormalTypeParameter parentParam : parentParams) {
-                               typeParameters.add(parentParam);
-                       }
+                       Collections.addAll(typeParameters, parentParams);
                }
                GenericSignature.ClassSignature outerSig = outerObjectType.getGenericClassTypeSignature();
                if (outerSig != null) {
-                       for (FormalTypeParameter formalTypeParameter : outerSig.formalTypeParameters) {
-                               typeParameters.add(formalTypeParameter);
-                       }
+                       Collections.addAll(typeParameters, outerSig.formalTypeParameters);
                }
 
                GenericSignature.FormalTypeParameter[] ret = new GenericSignature.FormalTypeParameter[typeParameters.size()];
index 546eadba357c5bccdb76f3fdb0282d19dd4b5af7..98878dcbc7754c989c6059b126e6971a0666ddbe 100644 (file)
@@ -36,13 +36,7 @@ import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.text.DateFormat;
 //import java.util.Collection;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.StringTokenizer;
-import java.util.Vector;
+import java.util.*;
 
 import javax.swing.BorderFactory;
 import javax.swing.BoxLayout;
@@ -1426,9 +1420,7 @@ public class Ajctest extends Task implements PropertyChangeListener {
         public AjdocWrapper(Testset testset, List args) {
             super(testset, ajdocArgs(args), true);
             String[] cmds = testset.getAjdoc().getCommandline().getCommandline();
-                       for (String cmd : cmds) {
-                               this.args.add(cmd);
-                       }
+                       Collections.addAll(this.args, cmds);
         }
         String getMainClassName() {
             return "org.aspectj.tools.ajdoc.Main";
index e5e2fcdb9166d5492d0ca44be5ab41294dd3b96b..81e2616ea3c9fd9e3d9c8830beefe8c60a608e1a 100644 (file)
@@ -415,9 +415,7 @@ public abstract class XMLBasedAjcTestCase extends AjcTestCase {
        public List<LocalVariable> sortedLocalVariables(LocalVariableTable lvt) {
                List<LocalVariable> l = new ArrayList<>();
                LocalVariable lv[] = lvt.getLocalVariableTable();
-               for (LocalVariable lvEntry : lv) {
-                       l.add(lvEntry);
-               }
+               Collections.addAll(l, lv);
                Collections.sort(l, new MyComparator());
                return l;
        }
index 7a04fbed0f41c5b613a34ceeb0c240c2e7a7cfc1..608d4a610a04e6751e25bdb94b4978ba4aed7e57 100644 (file)
@@ -398,9 +398,7 @@ public class Values {
                                String s = value.prefix.render(output[0]);
                                if (null != s) { // this means the prefix is set
                                        list.add(s);
-                                       for (int j = 1; j < output.length; j++) {
-                                               list.add(output[j]);
-                                       }
+                                       list.addAll(Arrays.asList(output).subList(1, output.length));
                                }
                        }
                }
index 3e9ac1b756023f9c214ef999cb67d3f1d2c34faa..47984dfdffe1bcfd27acf1f23ca58bb29e37574c 100644 (file)
@@ -771,12 +771,8 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate {
                                GenericSignature.FormalTypeParameter[] extraFormals = getFormalTypeParametersFromOuterClass();
                                if (extraFormals.length > 0) {
                                        List<FormalTypeParameter> allFormals = new ArrayList<>();
-                                       for (FormalTypeParameter formalTypeParameter : formalsForResolution) {
-                                               allFormals.add(formalTypeParameter);
-                                       }
-                                       for (FormalTypeParameter extraFormal : extraFormals) {
-                                               allFormals.add(extraFormal);
-                                       }
+                                       Collections.addAll(allFormals, formalsForResolution);
+                                       Collections.addAll(allFormals, extraFormals);
                                        formalsForResolution = new GenericSignature.FormalTypeParameter[allFormals.size()];
                                        allFormals.toArray(formalsForResolution);
                                }