Reports while loops which iterate over collections, and can be replaced with an enhanced for loop (i.e. foreach iteration syntax).
Signed-off-by: Lars Grefer <eclipse@larsgrefer.de>
}
StringBuffer formattedOptions = new StringBuffer();
- Iterator<?> it = options.iterator();
- while (it.hasNext()) {
- String o = it.next().toString();
+ for (Object option : options) {
+ String o = option.toString();
if (formattedOptions.length() > 0) {
formattedOptions.append(", ");
}
}
public boolean exists(String entry, String configFile, String rootPath) {
- Iterator it = readConfigFile(configFile).iterator();
- while (it.hasNext()) {
- if ((entry).equals(rootPath + "/" + (String) it.next())) {
+ for (String s : readConfigFile(configFile)) {
+ if ((entry).equals(rootPath + "/" + s)) {
return true;
}
}
public void writeConfigFile(String filePath, List<String> fileContents) {
Set<String> contentsSet = new TreeSet<>(fileContents);
StringBuffer fileContentsSB = new StringBuffer();
- Iterator<String> it = contentsSet.iterator();
- while (it.hasNext()) {
- fileContentsSB.append(it.next().toString());
+ for (String s : contentsSet) {
+ fileContentsSB.append(s.toString());
fileContentsSB.append("\n");
}
writeFile(fileContentsSB.toString(), filePath);
Set<InstructionTargeter> targeters = ih.getTargeters();
boolean isOK = false;
- Iterator<InstructionTargeter> tIter = targeters.iterator();
- while (tIter.hasNext()) {
- InstructionTargeter instructionTargeter = tIter.next();
+ for (InstructionTargeter instructionTargeter : targeters) {
if (instructionTargeter.getClass().getName().endsWith("ShadowRange")
|| instructionTargeter.getClass().getName().endsWith("ExceptionRange")
|| instructionTargeter.getClass().getName().endsWith("LineNumberTag")) {
if (this.resolveBindings) {
recordNodes(docComment, javadoc);
// resolve member and method references binding
- Iterator tags = docComment.tags().listIterator();
- while (tags.hasNext()) {
- recordNodes(javadoc, (TagElement) tags.next());
+ for (Object o : docComment.tags()) {
+ recordNodes(javadoc, (TagElement) o);
}
}
bodyDeclaration.setJavadoc(docComment);
if (this.resolveBindings) {
recordNodes(docComment, javadoc);
// resolve member and method references binding
- Iterator tags = docComment.tags().listIterator();
- while (tags.hasNext()) {
- recordNodes(javadoc, (TagElement) tags.next());
+ for (Object o : docComment.tags()) {
+ recordNodes(javadoc, (TagElement) o);
}
}
packageDeclaration.setJavadoc(docComment);
}
protected void recordNodes(org.aspectj.org.eclipse.jdt.internal.compiler.ast.Javadoc javadoc, TagElement tagElement) {
- Iterator fragments = tagElement.fragments().listIterator();
- while (fragments.hasNext()) {
- ASTNode node = (ASTNode) fragments.next();
+ for (Object value : tagElement.fragments()) {
+ ASTNode node = (ASTNode) value;
if (node.getNodeType() == ASTNode.MEMBER_REF) {
MemberRef memberRef = (MemberRef) node;
Name name = memberRef.getName();
}
// Replace qualifier to have all nodes recorded
if (memberRef.getQualifier() != null) {
- org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeReference typeRef = null;
+ TypeReference typeRef = null;
if (compilerNode instanceof JavadocFieldReference) {
org.aspectj.org.eclipse.jdt.internal.compiler.ast.Expression expression = ((JavadocFieldReference) compilerNode).receiver;
- if (expression instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeReference) {
- typeRef = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeReference) expression;
+ if (expression instanceof TypeReference) {
+ typeRef = (TypeReference) expression;
}
} else if (compilerNode instanceof JavadocMessageSend) {
org.aspectj.org.eclipse.jdt.internal.compiler.ast.Expression expression = ((JavadocMessageSend) compilerNode).receiver;
- if (expression instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeReference) {
- typeRef = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeReference) expression;
+ if (expression instanceof TypeReference) {
+ typeRef = (TypeReference) expression;
}
}
if (typeRef != null) {
if (compilerNode != null) {
recordNodes(methodRef, compilerNode);
// get type ref
- org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeReference typeRef = null;
+ TypeReference typeRef = null;
if (compilerNode instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.JavadocAllocationExpression) {
typeRef = ((org.aspectj.org.eclipse.jdt.internal.compiler.ast.JavadocAllocationExpression) compilerNode).type;
if (typeRef != null) {
recordNodes(name, compilerNode);
}
- } else if (compilerNode instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.JavadocMessageSend) {
- org.aspectj.org.eclipse.jdt.internal.compiler.ast.Expression expression = ((org.aspectj.org.eclipse.jdt.internal.compiler.ast.JavadocMessageSend) compilerNode).receiver;
- if (expression instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeReference) {
- typeRef = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeReference) expression;
+ } else if (compilerNode instanceof JavadocMessageSend) {
+ org.aspectj.org.eclipse.jdt.internal.compiler.ast.Expression expression = ((JavadocMessageSend) compilerNode).receiver;
+ if (expression instanceof TypeReference) {
+ typeRef = (TypeReference) expression;
}
// TODO (frederic) remove following line to fix bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=62650
recordNodes(name, compilerNode);
}
}
// Resolve parameters
- Iterator parameters = methodRef.parameters().listIterator();
- while (parameters.hasNext()) {
- MethodRefParameter param = (MethodRefParameter) parameters.next();
+ for (Object o : methodRef.parameters()) {
+ MethodRefParameter param = (MethodRefParameter) o;
org.aspectj.org.eclipse.jdt.internal.compiler.ast.Expression expression = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.Expression) javadoc
.getNodeStartingAt(param.getStartPosition());
if (expression != null) {
recordNodes(param, expression);
if (expression instanceof JavadocArgumentExpression) {
JavadocArgumentExpression argExpr = (JavadocArgumentExpression) expression;
- org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeReference typeRef = argExpr.argument.type;
+ TypeReference typeRef = argExpr.argument.type;
if (this.ast.apiLevel >= AST.JLS3) {
param.setVarargs(argExpr.argument.isVarArgs());
}
}
private void println(Properties props) {
- Iterator iter = props.keySet().iterator();
- while (iter.hasNext()) {
- String key = (String) iter.next();
+ for (Object o : props.keySet()) {
+ String key = (String) o;
String value = props.getProperty(key);
print.println(key + "=" + value);
}
List newIncludes = new ArrayList();
List newArguments = new ArrayList();
if (argfiles != null) {
- Iterator iter = argfiles.iterator();
- while (iter.hasNext()) {
- File argfile = ((Argfile)iter.next()).getFile();
- expandArgfile(argfile, newIncludes, newArguments);
- }
+ for (Object o : argfiles) {
+ File argfile = ((Argfile) o).getFile();
+ expandArgfile(argfile, newIncludes, newArguments);
+ }
}
// If there aren't any includes, but we've used an argfile then we should
}
// Add the new included files
- Iterator iter = newIncludes.iterator();
- while (iter.hasNext()) {
- newFiles.add((File)iter.next());
- }
+ for (Object newInclude : newIncludes) {
+ newFiles.add((File) newInclude);
+ }
// This is the same behavior found in Javac
int newFileSize = newFiles.size();
// copy over tags and range attributes
- Iterator<InstructionTargeter> tIter = src.getTargeters().iterator();
- while (tIter.hasNext()) {
- InstructionTargeter old = tIter.next();
+ for (InstructionTargeter old : src.getTargeters()) {
if (old instanceof Tag) {
Tag oldTag = (Tag) old;
Tag fresh = tagMap.get(oldTag);
if (startOfHandler.getInstruction().isStoreInstruction() && startOfHandler.getNext() != null) {
int slot = startOfHandler.getInstruction().getIndex();
// System.out.println("got store: " + startOfHandler.getInstruction() + ", " + index);
- Iterator<InstructionTargeter> tIter = startOfHandler.getNext().getTargeters().iterator();
- while (tIter.hasNext()) {
- InstructionTargeter targeter = tIter.next();
+ for (InstructionTargeter targeter : startOfHandler.getNext().getTargeters()) {
if (targeter instanceof LocalVariableTag) {
LocalVariableTag t = (LocalVariableTag) targeter;
if (t.getSlot() == slot) {
// boolean hasPendingTargeters = false;
int lcounter = 0;
for (InstructionHandle ih = body.getStart(); ih != null; ih = ih.getNext()) {
- Iterator<InstructionTargeter> tIter = ih.getTargeters().iterator();
- while (tIter.hasNext()) {
- InstructionTargeter t = tIter.next();// targeters
+ // targeters
+ for (InstructionTargeter t : ih.getTargeters()) {
// [
// i
// ]
// }
private static void assertTargetedBy(InstructionHandle target, InstructionTargeter targeter, String from) {
- Iterator tIter = target.getTargeters().iterator();
- while (tIter.hasNext()) {
- if (((InstructionTargeter) tIter.next()) == targeter) {
+ for (InstructionTargeter instructionTargeter : target.getTargeters()) {
+ if (instructionTargeter == targeter) {
return;
}
}
protected static final Range getRange(InstructionHandle ih) {
// assert isRangeHandle(ih)
Range ret = null;
- Iterator<InstructionTargeter> tIter = ih.getTargeters().iterator();
- while (tIter.hasNext()) {
- InstructionTargeter targeter = tIter.next();
+ for (InstructionTargeter targeter : ih.getTargeters()) {
if (targeter instanceof Range) {
Range r = (Range) targeter;
if (r.getStart() != ih && r.getEnd() != ih) {
// now go through again and update variable slots that have been altered as a result
// of remapping...
for (InstructionHandle newIh = freshBody.getStart(); newIh != freshBody.getEnd(); newIh = newIh.getNext()) {
- Iterator<InstructionTargeter> tIter = newIh.getTargeters().iterator();
- while (tIter.hasNext()) {
- InstructionTargeter source = tIter.next();
+ for (InstructionTargeter source : newIh.getTargeters()) {
if (source instanceof LocalVariableTag) {
LocalVariableTag lvt = (LocalVariableTag) source;
if (!lvt.isRemapped() && remap.hasKey(lvt.getSlot())) {
if (ih == null) {
return -1;
}
- Iterator<InstructionTargeter> tIter = ih.getTargeters().iterator();
- while (tIter.hasNext()) {
- InstructionTargeter t = tIter.next();
+ for (InstructionTargeter t : ih.getTargeters()) {
if (t instanceof LineNumberTag) {
return ((LineNumberTag) t).getLineNumber();
}