diff options
author | Lars Grefer <eclipse@larsgrefer.de> | 2020-08-08 03:06:37 +0200 |
---|---|---|
committer | Lars Grefer <eclipse@larsgrefer.de> | 2020-08-08 03:06:37 +0200 |
commit | 72194b7982ddfa8e9864d0a9934905bb76b90f33 (patch) | |
tree | ebed806c358c1a3960c5d6be4c13b26ca41809df /tests/src | |
parent | c3289ab86bfb2c97cf34147239b3dde46de92a7c (diff) | |
download | aspectj-72194b7982ddfa8e9864d0a9934905bb76b90f33.tar.gz aspectj-72194b7982ddfa8e9864d0a9934905bb76b90f33.zip |
'for' loop replaceable with enhanced 'for' loop
Reports for loops which iterate over collections or arrays, and can be replaced with an enhanced for loop (i.e. the foreach iteration syntax).
Signed-off-by: Lars Grefer <eclipse@larsgrefer.de>
Diffstat (limited to 'tests/src')
23 files changed, 95 insertions, 133 deletions
diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc150/Ajc150Tests.java b/tests/src/test/java/org/aspectj/systemtest/ajc150/Ajc150Tests.java index cde62fe51..c105e881d 100644 --- a/tests/src/test/java/org/aspectj/systemtest/ajc150/Ajc150Tests.java +++ b/tests/src/test/java/org/aspectj/systemtest/ajc150/Ajc150Tests.java @@ -358,8 +358,7 @@ public class Ajc150Tests extends org.aspectj.testing.XMLBasedAjcTestCase { boolean f = false; JavaClass jc = getClassFrom(ajc.getSandboxDirectory(), "PR82570_1"); Method[] meths = jc.getMethods(); - for (int i = 0; i < meths.length; i++) { - Method method = meths[i]; + for (Method method : meths) { if (f) System.err.println("Line number table for " + method.getName() + method.getSignature() + " = " + method.getLineNumberTable()); diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc150/Annotations.java b/tests/src/test/java/org/aspectj/systemtest/ajc150/Annotations.java index 0c44996cb..04797eb9f 100644 --- a/tests/src/test/java/org/aspectj/systemtest/ajc150/Annotations.java +++ b/tests/src/test/java/org/aspectj/systemtest/ajc150/Annotations.java @@ -49,10 +49,9 @@ public class Annotations extends XMLBasedAjcTestCase { JavaClass jc = getClassFrom(ajc.getSandboxDirectory(),"Program"); Method[] meths = jc.getMethods(); - for (int i = 0; i < meths.length; i++) { - Method method = meths[i]; + for (Method method : meths) { if (method.getName().equals("m1")) { - assertTrue("Didn't have annotations - were they lost? method="+method.getName(),method.getAnnotations().length==1); + assertTrue("Didn't have annotations - were they lost? method=" + method.getName(), method.getAnnotations().length == 1); } } } diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc150/GenericITDsDesign.java b/tests/src/test/java/org/aspectj/systemtest/ajc150/GenericITDsDesign.java index d6e4b7112..210f5f44d 100644 --- a/tests/src/test/java/org/aspectj/systemtest/ajc150/GenericITDsDesign.java +++ b/tests/src/test/java/org/aspectj/systemtest/ajc150/GenericITDsDesign.java @@ -59,8 +59,7 @@ public class GenericITDsDesign extends XMLBasedAjcTestCase { JavaClass clazz = getClassFromDisk(ajc, classname); Signature sigAttr = null; Attribute[] attrs = clazz.getAttributes(); - for (int i = 0; i < attrs.length; i++) { - Attribute attribute = attrs[i]; + for (Attribute attribute : attrs) { if (attribute.getName().equals("Signature")) { sigAttr = (Signature) attribute; } @@ -87,14 +86,14 @@ public class GenericITDsDesign extends XMLBasedAjcTestCase { private BcelTypeMunger getMungerFromLine(String classname, int linenumber) { List allMungers = getTypeMunger(classname); - for (Iterator iter = allMungers.iterator(); iter.hasNext();) { - BcelTypeMunger element = (BcelTypeMunger) iter.next(); + for (Object munger : allMungers) { + BcelTypeMunger element = (BcelTypeMunger) munger; if (element.getMunger().getSourceLocation().getLine() == linenumber) { return element; } } - for (Iterator iter = allMungers.iterator(); iter.hasNext();) { - BcelTypeMunger element = (BcelTypeMunger) iter.next(); + for (Object allMunger : allMungers) { + BcelTypeMunger element = (BcelTypeMunger) allMunger; System.err.println("Line: " + element.getMunger().getSourceLocation().getLine() + " > " + element); } fail("Couldn't find a type munger from line " + linenumber + " in class " + classname); @@ -105,8 +104,7 @@ public class GenericITDsDesign extends XMLBasedAjcTestCase { JavaClass theClass = getClassFromDisk(ajc, classname); Hashtable<String,Field> retval = new Hashtable<>(); org.aspectj.apache.bcel.classfile.Field[] fs = theClass.getFields(); - for (int i = 0; i < fs.length; i++) { - Field field = fs[i]; + for (Field field : fs) { retval.put(field.getName(), field); } return retval; diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc150/GenericsTests.java b/tests/src/test/java/org/aspectj/systemtest/ajc150/GenericsTests.java index 34bdd455c..847f67149 100644 --- a/tests/src/test/java/org/aspectj/systemtest/ajc150/GenericsTests.java +++ b/tests/src/test/java/org/aspectj/systemtest/ajc150/GenericsTests.java @@ -886,10 +886,10 @@ public class GenericsTests extends XMLBasedAjcTestCase { Class<?> clz = Class.forName(classname,false,cl); java.lang.reflect.Method[] ms = clz.getDeclaredMethods(); if (ms!=null) { - for (int i =0;i<ms.length;i++) { - String methodString = ms[i].getReturnType().getName()+" "+ms[i].getDeclaringClass().getName()+"."+ - ms[i].getName()+"("+stringify(ms[i].getParameterTypes())+")"+ - (isBridge(ms[i])?" [BridgeMethod]":""); + for (java.lang.reflect.Method m : ms) { + String methodString = m.getReturnType().getName() + " " + m.getDeclaringClass().getName() + "." + + m.getName() + "(" + stringify(m.getParameterTypes()) + ")" + + (isBridge(m) ? " [BridgeMethod]" : ""); methodsFound.add(methodString); debugString.append("\n[").append(methodString).append("]"); } @@ -901,10 +901,9 @@ public class GenericsTests extends XMLBasedAjcTestCase { } // check the methods specified do exist - for (int i = 0; i < methods.length; i++) { - String string = methods[i]; + for (String string : methods) { if (!methodsFound.remove(string)) { - fail("Couldn't find ["+string+"] in the set of methods in "+classname+" => "+debugString); + fail("Couldn't find [" + string + "] in the set of methods in " + classname + " => " + debugString); } } StringBuffer unexpectedMethods = new StringBuffer(); @@ -953,9 +952,8 @@ public class GenericsTests extends XMLBasedAjcTestCase { JavaClass clazz = getClass(ajc,classname); Signature sigAttr = null; Attribute[] attrs = clazz.getAttributes(); - for (int i = 0; i < attrs.length; i++) { - Attribute attribute = attrs[i]; - if (attribute.getName().equals("Signature")) sigAttr = (Signature)attribute; + for (Attribute attribute : attrs) { + if (attribute.getName().equals("Signature")) sigAttr = (Signature) attribute; } return sigAttr; } @@ -965,11 +963,10 @@ public class GenericsTests extends XMLBasedAjcTestCase { Attribute[] attrs = clazz.getAttributes(); int signatureCount = 0; StringBuffer sb = new StringBuffer(); - for (int i = 0; i < attrs.length; i++) { - Attribute attribute = attrs[i]; + for (Attribute attribute : attrs) { if (attribute.getName().equals("Signature")) { signatureCount++; - sb.append("\n"+((Signature)attribute).getSignature()); + sb.append("\n" + ((Signature) attribute).getSignature()); } } if (signatureCount>1) fail("Should be only one signature attribute but found "+signatureCount+sb.toString()); diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc152/SynchronizationTransformTests.java b/tests/src/test/java/org/aspectj/systemtest/ajc152/SynchronizationTransformTests.java index 92d2addfd..f03ebe3f0 100644 --- a/tests/src/test/java/org/aspectj/systemtest/ajc152/SynchronizationTransformTests.java +++ b/tests/src/test/java/org/aspectj/systemtest/ajc152/SynchronizationTransformTests.java @@ -209,8 +209,7 @@ public class SynchronizationTransformTests extends XMLBasedAjcTestCase { protected Method getMethod(JavaClass cl, String methodname) { Method[] methods = cl.getMethods(); - for (int i = 0; i < methods.length; i++) { - Method m = methods[i]; + for (Method m : methods) { if (m.getName().equals(methodname)) { return m; } @@ -258,8 +257,7 @@ public class SynchronizationTransformTests extends XMLBasedAjcTestCase { private String stringify(List<String> l) { StringBuffer result = new StringBuffer(); - for (Iterator<String> iter = l.iterator(); iter.hasNext();) { - String str = iter.next(); + for (String str : l) { result.append(str); result.append("\n"); } diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc153/JDTLikeHandleProviderTests.java b/tests/src/test/java/org/aspectj/systemtest/ajc153/JDTLikeHandleProviderTests.java index 2d398f86f..5e9e5b25e 100644 --- a/tests/src/test/java/org/aspectj/systemtest/ajc153/JDTLikeHandleProviderTests.java +++ b/tests/src/test/java/org/aspectj/systemtest/ajc153/JDTLikeHandleProviderTests.java @@ -159,8 +159,8 @@ public class JDTLikeHandleProviderTests extends XMLBasedAjcTestCase { List children = parent.getChildren(); String handle1 = null; String handle2 = null; - for (Iterator iter = children.iterator(); iter.hasNext();) { - IProgramElement element = (IProgramElement) iter.next(); + for (Object child : children) { + IProgramElement element = (IProgramElement) child; if (element.getKind().equals(IProgramElement.Kind.ADVICE)) { if (handle1 == null) { handle1 = element.getHandleIdentifier(); @@ -408,8 +408,8 @@ public class JDTLikeHandleProviderTests extends XMLBasedAjcTestCase { List children = parent.getChildren(); String handle1 = null; String handle2 = null; - for (Iterator iter = children.iterator(); iter.hasNext();) { - IProgramElement element = (IProgramElement) iter.next(); + for (Object child : children) { + IProgramElement element = (IProgramElement) child; if (element.getKind().equals(IProgramElement.Kind.INITIALIZER)) { if (handle1 == null) { handle1 = element.getHandleIdentifier(); diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc154/CustomMungerExtensionTest.java b/tests/src/test/java/org/aspectj/systemtest/ajc154/CustomMungerExtensionTest.java index 7c0d26d4c..6b1b8821c 100644 --- a/tests/src/test/java/org/aspectj/systemtest/ajc154/CustomMungerExtensionTest.java +++ b/tests/src/test/java/org/aspectj/systemtest/ajc154/CustomMungerExtensionTest.java @@ -58,13 +58,13 @@ public class CustomMungerExtensionTest extends AjdeInteractionTestbed { CustomMungerFactory factory = (CustomMungerFactory) compiler.getCustomMungerFactory(); assertTrue(factory.getAllCreatedCustomShadowMungers().size() > 0); - for (Iterator<ShadowMunger> i = factory.getAllCreatedCustomShadowMungers().iterator(); i.hasNext();) { - assertTrue(((DumbShadowMunger) i.next()).called); + for (ShadowMunger shadowMunger : factory.getAllCreatedCustomShadowMungers()) { + assertTrue(((DumbShadowMunger) shadowMunger).called); } assertTrue(factory.getAllCreatedCustomTypeMungers().size() > 0); - for (Iterator<ConcreteTypeMunger> i = factory.getAllCreatedCustomTypeMungers().iterator(); i.hasNext();) { - assertTrue(((DumbTypeMunger) i.next()).called); + for (ConcreteTypeMunger concreteTypeMunger : factory.getAllCreatedCustomTypeMungers()) { + assertTrue(((DumbTypeMunger) concreteTypeMunger).called); } } diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc160/SanityTests.java b/tests/src/test/java/org/aspectj/systemtest/ajc160/SanityTests.java index 9bdb68665..41fb83bf2 100644 --- a/tests/src/test/java/org/aspectj/systemtest/ajc160/SanityTests.java +++ b/tests/src/test/java/org/aspectj/systemtest/ajc160/SanityTests.java @@ -97,8 +97,7 @@ public class SanityTests extends org.aspectj.testing.XMLBasedAjcTestCase { toIgnore = "_" + (toIgnore == null ? "" : toIgnore) + "_"; JavaClass jc = getClassFrom(ajc.getSandboxDirectory(), classname); Method[] methods = jc.getMethods(); - for (int i = 0; i < methods.length; i++) { - Method method = methods[i]; + for (Method method : methods) { if (toIgnore.contains("_" + method.getName() + "_")) { continue; } @@ -113,8 +112,7 @@ public class SanityTests extends org.aspectj.testing.XMLBasedAjcTestCase { if (attrs == null) { return false; } - for (int i = 0; i < attrs.length; i++) { - Attribute attribute = attrs[i]; + for (Attribute attribute : attrs) { if (attribute.getName().equals(attributeName)) { return true; } @@ -122,8 +120,7 @@ public class SanityTests extends org.aspectj.testing.XMLBasedAjcTestCase { if (attribute.getName().equals("Code")) { Code c = (Code) attribute; Attribute[] codeAttributes = c.getAttributes(); - for (int j = 0; j < codeAttributes.length; j++) { - Attribute codeAttribute = codeAttributes[j]; + for (Attribute codeAttribute : codeAttributes) { if (codeAttribute.getName().equals(attributeName)) { return true; // System.out.println(codeAttribute.getName()); diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc161/Ajc161Tests.java b/tests/src/test/java/org/aspectj/systemtest/ajc161/Ajc161Tests.java index bcf640f3f..bba565a3a 100644 --- a/tests/src/test/java/org/aspectj/systemtest/ajc161/Ajc161Tests.java +++ b/tests/src/test/java/org/aspectj/systemtest/ajc161/Ajc161Tests.java @@ -141,8 +141,8 @@ public class Ajc161Tests extends org.aspectj.testing.XMLBasedAjcTestCase { Set entries = irm.getEntries(); boolean gotSomethingValid = false; String expected = "<recursivepackage{RecursiveCatcher.java'RecursiveCatcher~recursiveCall~I?method-call(void recursivepackage.RecursiveCatcher.recursiveCall(int))"; - for (Iterator iterator = entries.iterator(); iterator.hasNext();) { - String str = (String) iterator.next(); + for (Object entry : entries) { + String str = (String) entry; if (str.indexOf(expected) != -1) { gotSomethingValid = true; } diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc1610/NewFeatures.java b/tests/src/test/java/org/aspectj/systemtest/ajc1610/NewFeatures.java index 34b72996f..cfed5a765 100644 --- a/tests/src/test/java/org/aspectj/systemtest/ajc1610/NewFeatures.java +++ b/tests/src/test/java/org/aspectj/systemtest/ajc1610/NewFeatures.java @@ -127,9 +127,9 @@ public class NewFeatures extends org.aspectj.testing.XMLBasedAjcTestCase { private Method getPreClinitMethod(JavaClass myClass) { Method lm[] = myClass.getMethods(); - for (int i = 0; i < lm.length; i++) { - if (lm[i].getName().equals("ajc$preClinit")) { - return lm[i]; + for (Method method : lm) { + if (method.getName().equals("ajc$preClinit")) { + return method; } } return null; diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc1612/Ajc1612Tests.java b/tests/src/test/java/org/aspectj/systemtest/ajc1612/Ajc1612Tests.java index 9e857cb31..d9e52d2b1 100644 --- a/tests/src/test/java/org/aspectj/systemtest/ajc1612/Ajc1612Tests.java +++ b/tests/src/test/java/org/aspectj/systemtest/ajc1612/Ajc1612Tests.java @@ -256,8 +256,7 @@ public class Ajc1612Tests extends org.aspectj.testing.XMLBasedAjcTestCase { JavaClass jc = getClassFrom(ajc.getSandboxDirectory(), "X"); Method[] meths = jc.getMethods(); boolean checked = false; - for (int i = 0; i < meths.length; i++) { - Method method = meths[i]; + for (Method method : meths) { if (method.getName().equals("ajc$before$X$2$3444dde4")) { System.out.println(method.getName()); System.out.println(stringify(method.getLocalVariableTable())); diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc163/Ajc163Tests.java b/tests/src/test/java/org/aspectj/systemtest/ajc163/Ajc163Tests.java index c0bd95645..48d120761 100644 --- a/tests/src/test/java/org/aspectj/systemtest/ajc163/Ajc163Tests.java +++ b/tests/src/test/java/org/aspectj/systemtest/ajc163/Ajc163Tests.java @@ -246,9 +246,9 @@ public class Ajc163Tests extends org.aspectj.testing.XMLBasedAjcTestCase { JavaClass jc = Utils.getClassFrom(ajc.getSandboxDirectory().getAbsolutePath(), "Test"); Method[] ms = jc.getMethods(); Method m = null; - for (int i = 0; i < ms.length; i++) { - if (ms[i].getName().equals("sayHello")) { - m = ms[i]; + for (Method method : ms) { + if (method.getName().equals("sayHello")) { + m = method; } } if (m.getLocalVariableTable() == null) { @@ -310,8 +310,7 @@ public class Ajc163Tests extends org.aspectj.testing.XMLBasedAjcTestCase { private void print(LocalVariableTable localVariableTable) { LocalVariable[] lvs = localVariableTable.getLocalVariableTable(); - for (int i = 0; i < lvs.length; i++) { - LocalVariable localVariable = lvs[i]; + for (LocalVariable localVariable : lvs) { System.out.println(localVariable); } } diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc164/Ajc164Tests.java b/tests/src/test/java/org/aspectj/systemtest/ajc164/Ajc164Tests.java index f474af49c..1b1181535 100644 --- a/tests/src/test/java/org/aspectj/systemtest/ajc164/Ajc164Tests.java +++ b/tests/src/test/java/org/aspectj/systemtest/ajc164/Ajc164Tests.java @@ -427,8 +427,7 @@ public class Ajc164Tests extends org.aspectj.testing.XMLBasedAjcTestCase { return whereToLook; } List<IProgramElement> kids = whereToLook.getChildren(); - for (Iterator<IProgramElement> iterator = kids.iterator(); iterator.hasNext();) { - IProgramElement object = iterator.next(); + for (IProgramElement object : kids) { if (object.getSourceLocation() != null && object.getSourceLocation().getLine() == line) { return object; } diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc165/Ajc165Tests.java b/tests/src/test/java/org/aspectj/systemtest/ajc165/Ajc165Tests.java index 6b8923e2a..762865c57 100644 --- a/tests/src/test/java/org/aspectj/systemtest/ajc165/Ajc165Tests.java +++ b/tests/src/test/java/org/aspectj/systemtest/ajc165/Ajc165Tests.java @@ -85,8 +85,8 @@ public class Ajc165Tests extends org.aspectj.testing.XMLBasedAjcTestCase { List<IMessage> ms = ajc.getLastCompilationResult().getWarningMessages(); boolean checked = true; // Look for the message relating to 'List' and check the offsets - for (int i = 0; i < ms.size(); i++) { - LintMessage m = (LintMessage) ms.get(i); + for (IMessage iMessage : ms) { + LintMessage m = (LintMessage) iMessage; if (m.toString().indexOf("List") != -1) { // 225/228 on windows - 237/240 on linux if (!(m.getSourceStart() == 225 || m.getSourceStart() == 237)) { diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc173/Ajc173Tests.java b/tests/src/test/java/org/aspectj/systemtest/ajc173/Ajc173Tests.java index 98d16daae..12fdfd8be 100644 --- a/tests/src/test/java/org/aspectj/systemtest/ajc173/Ajc173Tests.java +++ b/tests/src/test/java/org/aspectj/systemtest/ajc173/Ajc173Tests.java @@ -61,8 +61,8 @@ public class Ajc173Tests extends org.aspectj.testing.XMLBasedAjcTestCase { Method m = getMethodStartsWith(jc, "getName"); assertNotNull(m); AnnotationGen[] ags = m.getAnnotations(); - for (int i=0;i<ags.length;i++) { - System.out.println(ags[i]); + for (AnnotationGen ag : ags) { + System.out.println(ag); } assertEquals(1,ags.length); assertEquals("LFoo;",ags[0].getTypeSignature()); diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc190/Annotations.java b/tests/src/test/java/org/aspectj/systemtest/ajc190/Annotations.java index 971e53435..557dd0743 100644 --- a/tests/src/test/java/org/aspectj/systemtest/ajc190/Annotations.java +++ b/tests/src/test/java/org/aspectj/systemtest/ajc190/Annotations.java @@ -53,8 +53,7 @@ public class Annotations extends XMLBasedAjcTestCase { JavaClass jc = getClassFrom(ajc.getSandboxDirectory(), "Program"); Method[] meths = jc.getMethods(); - for (int i = 0; i < meths.length; i++) { - Method method = meths[i]; + for (Method method : meths) { if (method.getName().equals("m1")) { assertTrue("Didn't have annotations - were they lost? method=" + method.getName(), method.getAnnotations().length == 1); diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc190/EfficientTJPTests.java b/tests/src/test/java/org/aspectj/systemtest/ajc190/EfficientTJPTests.java index 0bef8e7db..2f01d0d97 100644 --- a/tests/src/test/java/org/aspectj/systemtest/ajc190/EfficientTJPTests.java +++ b/tests/src/test/java/org/aspectj/systemtest/ajc190/EfficientTJPTests.java @@ -107,11 +107,10 @@ public class EfficientTJPTests extends XMLBasedAjcTestCase { try { JavaClass jc = getClassFrom(ajc.getSandboxDirectory(), classname); Method[] meths = jc.getMethods(); - for (int i = 0; i < meths.length; i++) { - Method method = meths[i]; + for (Method method : meths) { if (method.getName().equals("ajc$preClinit")) { String code = method.getCode().getCodeString(); - assertTrue("Expected to contain '"+text+"':\n"+code,code.contains(text)); + assertTrue("Expected to contain '" + text + "':\n" + code, code.contains(text)); return; } } diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc190/ModuleTests.java b/tests/src/test/java/org/aspectj/systemtest/ajc190/ModuleTests.java index ac5eb14e4..5937c4423 100644 --- a/tests/src/test/java/org/aspectj/systemtest/ajc190/ModuleTests.java +++ b/tests/src/test/java/org/aspectj/systemtest/ajc190/ModuleTests.java @@ -112,8 +112,7 @@ public class ModuleTests extends XMLBasedAjcTestCaseForJava9OrLater { toIgnore = "_" + (toIgnore == null ? "" : toIgnore) + "_"; JavaClass jc = getClassFrom(ajc.getSandboxDirectory(), classname); Method[] methods = jc.getMethods(); - for (int i = 0; i < methods.length; i++) { - Method method = methods[i]; + for (Method method : methods) { if (toIgnore.contains("_" + method.getName() + "_")) { continue; } @@ -128,8 +127,7 @@ public class ModuleTests extends XMLBasedAjcTestCaseForJava9OrLater { if (attrs == null) { return false; } - for (int i = 0; i < attrs.length; i++) { - Attribute attribute = attrs[i]; + for (Attribute attribute : attrs) { if (attribute.getName().equals(attributeName)) { return true; } @@ -137,8 +135,7 @@ public class ModuleTests extends XMLBasedAjcTestCaseForJava9OrLater { if (attribute.getName().equals("Code")) { Code c = (Code) attribute; Attribute[] codeAttributes = c.getAttributes(); - for (int j = 0; j < codeAttributes.length; j++) { - Attribute codeAttribute = codeAttributes[j]; + for (Attribute codeAttribute : codeAttributes) { if (codeAttribute.getName().equals(attributeName)) { return true; // System.out.println(codeAttribute.getName()); diff --git a/tests/src/test/java/org/aspectj/systemtest/incremental/tools/AbstractMultiProjectIncrementalAjdeInteractionTestbed.java b/tests/src/test/java/org/aspectj/systemtest/incremental/tools/AbstractMultiProjectIncrementalAjdeInteractionTestbed.java index 229a22a5d..916801690 100644 --- a/tests/src/test/java/org/aspectj/systemtest/incremental/tools/AbstractMultiProjectIncrementalAjdeInteractionTestbed.java +++ b/tests/src/test/java/org/aspectj/systemtest/incremental/tools/AbstractMultiProjectIncrementalAjdeInteractionTestbed.java @@ -65,8 +65,8 @@ public class AbstractMultiProjectIncrementalAjdeInteractionTestbed extends AjdeI // System.out.println("kvp: " + object + " = " + m.get(object)); // } // } - for (Iterator<IProgramElement> i = node.getChildren().iterator(); i.hasNext();) { - dumptree( i.next(), indent + 2); + for (IProgramElement iProgramElement : node.getChildren()) { + dumptree(iProgramElement, indent + 2); } } } @@ -113,11 +113,10 @@ public class AbstractMultiProjectIncrementalAjdeInteractionTestbed extends AjdeI IRelationshipMap relmap = getModelFor(project).getRelationshipMap(); int ctr = 0; Set<String> entries = relmap.getEntries(); - for (Iterator<String> iter = entries.iterator(); iter.hasNext();) { - String hid = (String) iter.next(); + for (String hid : entries) { List<IRelationship> rels = relmap.get(hid); - for (Iterator<IRelationship> iterator = rels.iterator(); iterator.hasNext();) { - ctr+=iterator.next().getTargets().size(); + for (IRelationship rel : rels) { + ctr += rel.getTargets().size(); } } return ctr; @@ -152,8 +151,7 @@ public class AbstractMultiProjectIncrementalAjdeInteractionTestbed extends AjdeI String contents[] = location.list(); if (contents == null) return; - for (int i = 0; i < contents.length; i++) { - String string = contents[i]; + for (String string : contents) { File f = new File(location, string); if (f.isDirectory()) { collectUpFiles(f, base, collectionPoint); @@ -206,8 +204,7 @@ public class AbstractMultiProjectIncrementalAjdeInteractionTestbed extends AjdeI String contents[] = from.list(); if (contents == null) return; - for (int i = 0; i < contents.length; i++) { - String string = contents[i]; + for (String string : contents) { File f = new File(from, string); File t = new File(to, string); diff --git a/tests/src/test/java/org/aspectj/systemtest/incremental/tools/AjdeInteractionTestbed.java b/tests/src/test/java/org/aspectj/systemtest/incremental/tools/AjdeInteractionTestbed.java index 0fe276f46..9c5770ef8 100644 --- a/tests/src/test/java/org/aspectj/systemtest/incremental/tools/AjdeInteractionTestbed.java +++ b/tests/src/test/java/org/aspectj/systemtest/incremental/tools/AjdeInteractionTestbed.java @@ -244,13 +244,13 @@ public class AjdeInteractionTestbed extends TestCase { List<String> filesForCompilation = new ArrayList<String>(); collectUpFiles(projectBase, projectBase, filesForCompilation); boolean changed = false; - for (int i = 0; i < filesForCompilation.size(); i++) { - if (!currentFiles.contains(filesForCompilation.get(i))) { + for (String s : filesForCompilation) { + if (!currentFiles.contains(s)) { changed = true; } } - for (int i = 0; i < currentFiles.size(); i++) { - if (!filesForCompilation.contains(currentFiles.get(i))) { + for (String currentFile : currentFiles) { + if (!filesForCompilation.contains(currentFile)) { changed = true; } } @@ -266,13 +266,13 @@ public class AjdeInteractionTestbed extends TestCase { List<String> collector = new ArrayList<String>(); collectUpXmlFiles(projectBase, projectBase, collector); boolean changed = false; - for (int i = 0; i < collector.size(); i++) { - if (!currentXmlFiles.contains(collector.get(i))) { + for (String s : collector) { + if (!currentXmlFiles.contains(s)) { changed = true; } } - for (int i = 0; i < currentXmlFiles.size(); i++) { - if (!collector.contains(currentXmlFiles.get(i))) { + for (String currentXmlFile : currentXmlFiles) { + if (!collector.contains(currentXmlFile)) { changed = true; } } @@ -286,8 +286,7 @@ public class AjdeInteractionTestbed extends TestCase { if (contents == null) { return; } - for (int i = 0; i < contents.length; i++) { - String string = contents[i]; + for (String string : contents) { File f = new File(location, string); if (f.isDirectory()) { collectUpFiles(f, base, collectionPoint); @@ -311,8 +310,7 @@ public class AjdeInteractionTestbed extends TestCase { if (contents == null) { return; } - for (int i = 0; i < contents.length; i++) { - String string = contents[i]; + for (String string : contents) { File f = new File(location, string); if (f.isDirectory()) { collectUpXmlFiles(f, base, collectionPoint); @@ -365,8 +363,7 @@ public class AjdeInteractionTestbed extends TestCase { public void checkForError(String projectName, String anError) { AjCompiler compiler = CompilerFactory.getCompilerForProjectWithDir(sandboxDir + File.separator + projectName); List<IMessage> messages = ((MultiProjTestMessageHandler) compiler.getMessageHandler()).getErrorMessages(); - for (Iterator<IMessage> iter = messages.iterator(); iter.hasNext();) { - IMessage element = iter.next(); + for (IMessage element : messages) { if (element.getMessage().indexOf(anError) != -1) { return; } @@ -409,13 +406,13 @@ public class AjdeInteractionTestbed extends TestCase { System.out.println("Build took: " + getTimeTakenForBuild(projectName) + "ms"); List<String> compiled = getCompiledFiles(projectName); System.out.println("Compiled: " + compiled.size() + " files"); - for (Iterator<String> iter = compiled.iterator(); iter.hasNext();) { - System.out.println(" :" + iter.next()); + for (String value : compiled) { + System.out.println(" :" + value); } List<String> woven = getWovenClasses(projectName); System.out.println("Wove: " + woven.size() + " files"); - for (Iterator<String> iter = woven.iterator(); iter.hasNext();) { - System.out.println(" :" + iter.next()); + for (String s : woven) { + System.out.println(" :" + s); } if (wasFullBuild()) { System.out.println("It was a batch (full) build"); diff --git a/tests/src/test/java/org/aspectj/systemtest/incremental/tools/MoreOutputLocationManagerTests.java b/tests/src/test/java/org/aspectj/systemtest/incremental/tools/MoreOutputLocationManagerTests.java index c35b88610..538d2dcbd 100644 --- a/tests/src/test/java/org/aspectj/systemtest/incremental/tools/MoreOutputLocationManagerTests.java +++ b/tests/src/test/java/org/aspectj/systemtest/incremental/tools/MoreOutputLocationManagerTests.java @@ -68,8 +68,7 @@ public class MoreOutputLocationManagerTests extends AbstractMultiProjectIncremen Map<String,File> classNameToFileMap = state.getClassNameToFileMap(); assertFalse("expected there to be classes ", classNameToFileMap.isEmpty()); Set<Map.Entry<String,File>> entrySet = classNameToFileMap.entrySet(); - for (Iterator<Map.Entry<String,File>> iterator = entrySet.iterator(); iterator.hasNext();) { - Map.Entry<String,File> entry = iterator.next(); + for (Map.Entry<String, File> entry : entrySet) { String className = entry.getKey(); String fullClassName = expectedOutputDir + File.separator + className.replace('.', File.separatorChar) + ".class"; File file = entry.getValue(); diff --git a/tests/src/test/java/org/aspectj/systemtest/incremental/tools/MultiProjectIncrementalTests.java b/tests/src/test/java/org/aspectj/systemtest/incremental/tools/MultiProjectIncrementalTests.java index 0d01d9634..75600dded 100644 --- a/tests/src/test/java/org/aspectj/systemtest/incremental/tools/MultiProjectIncrementalTests.java +++ b/tests/src/test/java/org/aspectj/systemtest/incremental/tools/MultiProjectIncrementalTests.java @@ -921,8 +921,7 @@ public class MultiProjectIncrementalTests extends AbstractMultiProjectIncrementa checkWasFullBuild(); List<IMessage> weaveMessages = getWeavingMessages(p); if (weaveMessages.size() != 1) { - for (Iterator<IMessage> iterator = weaveMessages.iterator(); iterator.hasNext();) { - Object object = iterator.next(); + for (Object object : weaveMessages) { System.out.println(object); } fail("Expected just one weave message. The aop.xml should have limited the weaving"); @@ -939,8 +938,7 @@ public class MultiProjectIncrementalTests extends AbstractMultiProjectIncrementa assertNotNull(ps); assertEquals(2, ps.size()); int count = 0; - for (Iterator<String> iterator = ps.iterator(); iterator.hasNext();) { - String type = iterator.next(); + for (String type : ps) { if (type.equals("java.io.Serializable")) { count++; } @@ -997,14 +995,13 @@ public class MultiProjectIncrementalTests extends AbstractMultiProjectIncrementa IRelationshipMap asmRelMap = getModelFor("P4").getRelationshipMap(); assertEquals("There should be two relationships in the relationship map", 2, asmRelMap.getEntries().size()); - for (Iterator<String> iter = asmRelMap.getEntries().iterator(); iter.hasNext();) { - String sourceOfRelationship = (String) iter.next(); + for (String sourceOfRelationship : asmRelMap.getEntries()) { IProgramElement ipe = getModelFor("P4").getHierarchy().findElementForHandle(sourceOfRelationship); assertNotNull("expected to find IProgramElement with handle " + sourceOfRelationship + " but didn't", ipe); - if (ipe.getKind().equals(IProgramElement.Kind.ADVICE)) { + if (ipe.getKind().equals(Kind.ADVICE)) { assertEquals("expected source of relationship to be " + advice.toString() + " but found " + ipe.toString(), advice, ipe); - } else if (ipe.getKind().equals(IProgramElement.Kind.CODE)) { + } else if (ipe.getKind().equals(Kind.CODE)) { assertEquals( "expected source of relationship to be " + codeElement.toString() + " but found " + ipe.toString(), codeElement, ipe); @@ -1014,17 +1011,16 @@ public class MultiProjectIncrementalTests extends AbstractMultiProjectIncrementa } List<IRelationship> relationships = asmRelMap.get(ipe); assertNotNull("expected " + ipe.getName() + " to have some " + "relationships", relationships); - for (Iterator<IRelationship> iterator = relationships.iterator(); iterator.hasNext();) { - Relationship rel = (Relationship) iterator.next(); + for (IRelationship relationship : relationships) { + Relationship rel = (Relationship) relationship; List<String> targets = rel.getTargets(); - for (Iterator<String> iterator2 = targets.iterator(); iterator2.hasNext();) { - String t = (String) iterator2.next(); + for (String t : targets) { IProgramElement link = getModelFor("P4").getHierarchy().findElementForHandle(t); - if (ipe.getKind().equals(IProgramElement.Kind.ADVICE)) { + if (ipe.getKind().equals(Kind.ADVICE)) { assertEquals( "expected target of relationship to be " + codeElement.toString() + " but found " + link.toString(), codeElement, link); - } else if (ipe.getKind().equals(IProgramElement.Kind.CODE)) { + } else if (ipe.getKind().equals(Kind.CODE)) { assertEquals( "expected target of relationship to be " + advice.toString() + " but found " + link.toString(), advice, link); @@ -1102,21 +1098,18 @@ public class MultiProjectIncrementalTests extends AbstractMultiProjectIncrementa IProgramElement root = model.getHierarchy().getRoot(); ProgramElement theITD = (ProgramElement) findElementAtLine(root, 7); Map<String, Object> m = theITD.kvpairs; - for (Iterator<String> iterator = m.keySet().iterator(); iterator.hasNext();) { - String type = iterator.next(); + for (String type : m.keySet()) { System.out.println(type + " = " + m.get(type)); } // return type of the ITD assertEquals("a.b.c.B", theITD.getCorrespondingType(true)); List<char[]> ptypes = theITD.getParameterTypes(); - for (Iterator<char[]> iterator = ptypes.iterator(); iterator.hasNext();) { - char[] object = iterator.next(); + for (char[] object : ptypes) { System.out.println("p = " + new String(object)); } ProgramElement decp = (ProgramElement) findElementAtLine(root, 8); m = decp.kvpairs; - for (Iterator<String> iterator = m.keySet().iterator(); iterator.hasNext();) { - String type = iterator.next(); + for (String type : m.keySet()) { System.out.println(type + " = " + m.get(type)); } List<String> l = decp.getParentTypes(); @@ -1723,8 +1716,8 @@ public class MultiProjectIncrementalTests extends AbstractMultiProjectIncrementa } List<IProgramElement> kids = start.getChildren(); if (kids != null) { - for (int i = 0; i < kids.size(); i++) { - IProgramElement found = getChild((IProgramElement) kids.get(i), name); + for (IProgramElement kid : kids) { + IProgramElement found = getChild((IProgramElement) kid, name); if (found != null) { return found; } @@ -3939,8 +3932,7 @@ public class MultiProjectIncrementalTests extends AbstractMultiProjectIncrementa if (rels == null) { fail("Did not find any related elements!"); } - for (Iterator<IRelationship> iter = rels.iterator(); iter.hasNext();) { - IRelationship element = iter.next(); + for (IRelationship element : rels) { List<String> targets = element.getTargets(); if (output == null) { output = new ArrayList<String>(); diff --git a/tests/src/test/java/org/aspectj/systemtest/model/ModelTestCase.java b/tests/src/test/java/org/aspectj/systemtest/model/ModelTestCase.java index 0e443c3d3..b2c3ca6c9 100644 --- a/tests/src/test/java/org/aspectj/systemtest/model/ModelTestCase.java +++ b/tests/src/test/java/org/aspectj/systemtest/model/ModelTestCase.java @@ -168,8 +168,7 @@ public abstract class ModelTestCase extends XMLBasedAjcTestCase { } // iterate over what we found - for (Iterator<String> iter = foundFileContents.iterator(); iter.hasNext();) { - String line = (String) iter.next(); + for (String line : foundFileContents) { if (debugTest) System.err.println("looking at model entry: " + line); if (!fileContents.contains(line)) { @@ -177,8 +176,7 @@ public abstract class ModelTestCase extends XMLBasedAjcTestCase { if (debugTest) { System.err.println("couldn't find: " + line); - for (Iterator<String> iterator = fileContents.iterator(); iterator.hasNext();) { - String element = (String) iterator.next(); + for (String element : fileContents) { System.err.println("compared with: " + element); } } @@ -192,8 +190,7 @@ public abstract class ModelTestCase extends XMLBasedAjcTestCase { } if (debugTest && !fileContents.isEmpty()) { - for (Iterator<String> iter = fileContents.iterator(); iter.hasNext();) { - String element = (String) iter.next(); + for (String element : fileContents) { System.err.println("remaining: " + element); } } |