diff options
author | Lars Grefer <eclipse@larsgrefer.de> | 2020-08-08 03:09:01 +0200 |
---|---|---|
committer | Lars Grefer <eclipse@larsgrefer.de> | 2020-08-08 03:09:01 +0200 |
commit | a508fd5315c6330f2057c219aebc35b15d0ea497 (patch) | |
tree | c0ec3cef4e3411f22e5124ae36eba542a35a495a /weaver/src/main | |
parent | 72194b7982ddfa8e9864d0a9934905bb76b90f33 (diff) | |
download | aspectj-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>
Diffstat (limited to 'weaver/src/main')
6 files changed, 9 insertions, 21 deletions
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(); } |