aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Grefer <eclipse@larsgrefer.de>2020-08-08 03:09:01 +0200
committerLars Grefer <eclipse@larsgrefer.de>2020-08-08 03:09:01 +0200
commita508fd5315c6330f2057c219aebc35b15d0ea497 (patch)
treec0ec3cef4e3411f22e5124ae36eba542a35a495a
parent72194b7982ddfa8e9864d0a9934905bb76b90f33 (diff)
downloadaspectj-a508fd5315c6330f2057c219aebc35b15d0ea497.tar.gz
aspectj-a508fd5315c6330f2057c219aebc35b15d0ea497.zip
'while' loop replaceable with enhanced 'for' loop
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>
-rw-r--r--ajde.core/src/main/java/org/aspectj/ajde/core/internal/AjdeCoreBuildManager.java5
-rw-r--r--ajde/src/main/java/org/aspectj/ajde/internal/LstBuildConfigFileUpdater.java10
-rw-r--r--bcel-builder/src/main/java/org/aspectj/apache/bcel/generic/InstructionList.java4
-rw-r--r--org.aspectj.ajdt.core/src/main/java/org/aspectj/org/eclipse/jdt/core/dom/AjASTConverter.java42
-rw-r--r--org.aspectj.matcher/src/main/java/org/aspectj/weaver/Dump.java5
-rw-r--r--taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/Ajc2.java16
-rw-r--r--weaver/src/main/java/org/aspectj/weaver/bcel/BcelClassWeaver.java4
-rw-r--r--weaver/src/main/java/org/aspectj/weaver/bcel/BcelShadow.java4
-rw-r--r--weaver/src/main/java/org/aspectj/weaver/bcel/LazyMethodGen.java10
-rw-r--r--weaver/src/main/java/org/aspectj/weaver/bcel/Range.java4
-rw-r--r--weaver/src/main/java/org/aspectj/weaver/bcel/ShadowRange.java4
-rw-r--r--weaver/src/main/java/org/aspectj/weaver/bcel/Utility.java4
12 files changed, 44 insertions, 68 deletions
diff --git a/ajde.core/src/main/java/org/aspectj/ajde/core/internal/AjdeCoreBuildManager.java b/ajde.core/src/main/java/org/aspectj/ajde/core/internal/AjdeCoreBuildManager.java
index a83ab5be2..b64588001 100644
--- a/ajde.core/src/main/java/org/aspectj/ajde/core/internal/AjdeCoreBuildManager.java
+++ b/ajde.core/src/main/java/org/aspectj/ajde/core/internal/AjdeCoreBuildManager.java
@@ -177,9 +177,8 @@ public class AjdeCoreBuildManager {
}
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(", ");
}
diff --git a/ajde/src/main/java/org/aspectj/ajde/internal/LstBuildConfigFileUpdater.java b/ajde/src/main/java/org/aspectj/ajde/internal/LstBuildConfigFileUpdater.java
index f3e2154cd..4e59e5d74 100644
--- a/ajde/src/main/java/org/aspectj/ajde/internal/LstBuildConfigFileUpdater.java
+++ b/ajde/src/main/java/org/aspectj/ajde/internal/LstBuildConfigFileUpdater.java
@@ -81,9 +81,8 @@ class LstBuildConfigFileUpdater {
}
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;
}
}
@@ -188,9 +187,8 @@ class LstBuildConfigFileUpdater {
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);
diff --git a/bcel-builder/src/main/java/org/aspectj/apache/bcel/generic/InstructionList.java b/bcel-builder/src/main/java/org/aspectj/apache/bcel/generic/InstructionList.java
index dbdfb7fdb..dd010b758 100644
--- a/bcel-builder/src/main/java/org/aspectj/apache/bcel/generic/InstructionList.java
+++ b/bcel-builder/src/main/java/org/aspectj/apache/bcel/generic/InstructionList.java
@@ -703,9 +703,7 @@ public class InstructionList implements Serializable {
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")) {
diff --git a/org.aspectj.ajdt.core/src/main/java/org/aspectj/org/eclipse/jdt/core/dom/AjASTConverter.java b/org.aspectj.ajdt.core/src/main/java/org/aspectj/org/eclipse/jdt/core/dom/AjASTConverter.java
index 57602a440..32794ef44 100644
--- a/org.aspectj.ajdt.core/src/main/java/org/aspectj/org/eclipse/jdt/core/dom/AjASTConverter.java
+++ b/org.aspectj.ajdt.core/src/main/java/org/aspectj/org/eclipse/jdt/core/dom/AjASTConverter.java
@@ -1993,9 +1993,8 @@ public class AjASTConverter extends ASTConverter {
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);
@@ -2016,9 +2015,8 @@ public class AjASTConverter extends ASTConverter {
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);
@@ -3389,9 +3387,8 @@ public class AjASTConverter extends ASTConverter {
}
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();
@@ -3404,16 +3401,16 @@ public class AjASTConverter extends ASTConverter {
}
// 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) {
@@ -3431,16 +3428,16 @@ public class AjASTConverter extends ASTConverter {
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);
@@ -3451,16 +3448,15 @@ public class AjASTConverter extends ASTConverter {
}
}
// 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());
}
diff --git a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/Dump.java b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/Dump.java
index 6e48de0d2..2e2f9e9df 100644
--- a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/Dump.java
+++ b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/Dump.java
@@ -424,9 +424,8 @@ public class Dump {
}
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);
}
diff --git a/taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/Ajc2.java b/taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/Ajc2.java
index a089f00b9..9aea9ae6d 100644
--- a/taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/Ajc2.java
+++ b/taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/Ajc2.java
@@ -416,11 +416,10 @@ public class Ajc2 extends Javac {
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
@@ -445,10 +444,9 @@ public class Ajc2 extends Javac {
}
// 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();
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 3c4f64aa2..36cd2686e 100644
--- a/weaver/src/main/java/org/aspectj/weaver/bcel/BcelClassWeaver.java
+++ b/weaver/src/main/java/org/aspectj/weaver/bcel/BcelClassWeaver.java
@@ -2324,9 +2324,7 @@ class BcelClassWeaver implements IClassWeaver {
// 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);
diff --git a/weaver/src/main/java/org/aspectj/weaver/bcel/BcelShadow.java b/weaver/src/main/java/org/aspectj/weaver/bcel/BcelShadow.java
index ca167e2ef..e92667b2e 100644
--- a/weaver/src/main/java/org/aspectj/weaver/bcel/BcelShadow.java
+++ b/weaver/src/main/java/org/aspectj/weaver/bcel/BcelShadow.java
@@ -555,9 +555,7 @@ public class BcelShadow extends Shadow {
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) {
diff --git a/weaver/src/main/java/org/aspectj/weaver/bcel/LazyMethodGen.java b/weaver/src/main/java/org/aspectj/weaver/bcel/LazyMethodGen.java
index ed9dd2c7a..049257d48 100644
--- a/weaver/src/main/java/org/aspectj/weaver/bcel/LazyMethodGen.java
+++ b/weaver/src/main/java/org/aspectj/weaver/bcel/LazyMethodGen.java
@@ -658,9 +658,8 @@ public final class LazyMethodGen implements Traceable {
// 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
// ]
@@ -1708,9 +1707,8 @@ public final class LazyMethodGen implements Traceable {
// }
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;
}
}
diff --git a/weaver/src/main/java/org/aspectj/weaver/bcel/Range.java b/weaver/src/main/java/org/aspectj/weaver/bcel/Range.java
index fa162c526..ebcb4251c 100644
--- a/weaver/src/main/java/org/aspectj/weaver/bcel/Range.java
+++ b/weaver/src/main/java/org/aspectj/weaver/bcel/Range.java
@@ -194,9 +194,7 @@ abstract class Range implements InstructionTargeter {
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) {
diff --git a/weaver/src/main/java/org/aspectj/weaver/bcel/ShadowRange.java b/weaver/src/main/java/org/aspectj/weaver/bcel/ShadowRange.java
index 47c8400c5..966699c04 100644
--- a/weaver/src/main/java/org/aspectj/weaver/bcel/ShadowRange.java
+++ b/weaver/src/main/java/org/aspectj/weaver/bcel/ShadowRange.java
@@ -190,9 +190,7 @@ final class ShadowRange extends Range {
// 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())) {
diff --git a/weaver/src/main/java/org/aspectj/weaver/bcel/Utility.java b/weaver/src/main/java/org/aspectj/weaver/bcel/Utility.java
index 7279070bc..bb4a38817 100644
--- a/weaver/src/main/java/org/aspectj/weaver/bcel/Utility.java
+++ b/weaver/src/main/java/org/aspectj/weaver/bcel/Utility.java
@@ -580,9 +580,7 @@ public class Utility {
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();
}