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>
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;
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++) {
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;
}
}
- for (JavaClass anInterface : interfaces) {
- queue.add(anInterface);
- }
+ Collections.addAll(queue, interfaces);
}
return interfaceList;
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;
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<>();
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;
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);
import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.StringTokenizer;
}
private void addMessagesTo(List<IMessage> aList, IMessage[] messages) {
- for (IMessage message : messages) {
- aList.add(message);
- }
+ Collections.addAll(aList, messages);
}
private boolean isIncremental(String[] args) {
*/
protected List newMessageList(Message[] messages) {
List ret = new ArrayList();
- for (Message message : messages) {
- ret.add(message);
- }
+ Collections.addAll(ret, messages);
return ret;
}
package org.aspectj.weaver;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import org.aspectj.bridge.ISourceLocation;
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()];
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;
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";
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;
}
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));
}
}
}
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);
}