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 /ajde/src/test | |
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 'ajde/src/test')
5 files changed, 17 insertions, 20 deletions
diff --git a/ajde/src/test/java/org/aspectj/ajde/AjdeTestCase.java b/ajde/src/test/java/org/aspectj/ajde/AjdeTestCase.java index 0c5c5c306..f1d979181 100644 --- a/ajde/src/test/java/org/aspectj/ajde/AjdeTestCase.java +++ b/ajde/src/test/java/org/aspectj/ajde/AjdeTestCase.java @@ -91,8 +91,7 @@ public abstract class AjdeTestCase extends TestCase { 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/ajde/src/test/java/org/aspectj/ajde/ExtensionTest.java b/ajde/src/test/java/org/aspectj/ajde/ExtensionTest.java index 43d75f8d4..a8ce3d922 100644 --- a/ajde/src/test/java/org/aspectj/ajde/ExtensionTest.java +++ b/ajde/src/test/java/org/aspectj/ajde/ExtensionTest.java @@ -78,8 +78,7 @@ public class ExtensionTest extends AjcTestCase { private IProgramElement getChild(IProgramElement parent, String s) { List<IProgramElement> kids = parent.getChildren(); - for (Iterator<IProgramElement> iter = kids.iterator(); iter.hasNext();) { - IProgramElement element = (IProgramElement) iter.next(); + for (IProgramElement element : kids) { if (element.getName().indexOf(s) != -1) return element; } @@ -97,8 +96,8 @@ public class ExtensionTest extends AjcTestCase { } if (ipe.getChildren() != null) { List kids = ipe.getChildren(); - for (Iterator iter = kids.iterator(); iter.hasNext();) { - IProgramElement element = (IProgramElement) iter.next(); + for (Object kid : kids) { + IProgramElement element = (IProgramElement) kid; findChild(s, element); } } @@ -113,8 +112,8 @@ public class ExtensionTest extends AjcTestCase { System.out.println(ipe.toLabelString());// getName()); if (ipe.getChildren() != null) { List kids = ipe.getChildren(); - for (Iterator iter = kids.iterator(); iter.hasNext();) { - IProgramElement element = (IProgramElement) iter.next(); + for (Object kid : kids) { + IProgramElement element = (IProgramElement) kid; walkit(element, indent + 2); } } diff --git a/ajde/src/test/java/org/aspectj/ajde/ui/StructureViewManagerTest.java b/ajde/src/test/java/org/aspectj/ajde/ui/StructureViewManagerTest.java index 0c1aa53ef..eca56feec 100644 --- a/ajde/src/test/java/org/aspectj/ajde/ui/StructureViewManagerTest.java +++ b/ajde/src/test/java/org/aspectj/ajde/ui/StructureViewManagerTest.java @@ -98,8 +98,7 @@ public class StructureViewManagerTest extends AjdeTestCase { } private void testModelIntegrityHelper(IProgramElement node) throws Exception { - for (Iterator it = node.getChildren().iterator(); it.hasNext();) { - IProgramElement child = (IProgramElement) it.next(); + for (IProgramElement child : node.getChildren()) { if (node == child.getParent()) { testModelIntegrityHelper(child); } else { diff --git a/ajde/src/test/java/org/aspectj/ajde/ui/utils/TestBuildProgressMonitor.java b/ajde/src/test/java/org/aspectj/ajde/ui/utils/TestBuildProgressMonitor.java index 935dcc363..6ccddefc0 100644 --- a/ajde/src/test/java/org/aspectj/ajde/ui/utils/TestBuildProgressMonitor.java +++ b/ajde/src/test/java/org/aspectj/ajde/ui/utils/TestBuildProgressMonitor.java @@ -77,18 +77,18 @@ public class TestBuildProgressMonitor implements IBuildProgressMonitor { } public boolean containsMessage(String prefix,String distinguishingMarks) { - for (Iterator iter = messagesReceived.iterator(); iter.hasNext();) { - String element = (String) iter.next(); + for (Object o : messagesReceived) { + String element = (String) o; if (element.startsWith(prefix) && - element.indexOf(distinguishingMarks)!=-1) return true; + element.indexOf(distinguishingMarks) != -1) return true; } return false; } public void dumpMessages() { System.out.println("ProgressMonitorMessages"); - for (Iterator iter = messagesReceived.iterator(); iter.hasNext();) { - String element = (String) iter.next(); + for (Object o : messagesReceived) { + String element = (String) o; System.out.println(element); } } diff --git a/ajde/src/test/java/org/aspectj/ajde/ui/utils/TestCompilerConfiguration.java b/ajde/src/test/java/org/aspectj/ajde/ui/utils/TestCompilerConfiguration.java index 04a73d2f4..a6fec514d 100644 --- a/ajde/src/test/java/org/aspectj/ajde/ui/utils/TestCompilerConfiguration.java +++ b/ajde/src/test/java/org/aspectj/ajde/ui/utils/TestCompilerConfiguration.java @@ -116,17 +116,17 @@ public class TestCompilerConfiguration implements ICompilerConfiguration { /* Allow the user to override the testProjectPath by using sourceRoots */ File[] srcBase = new File[] { new File(projectPath + File.separator + srcDirName) }; - for (int j = 0; j < srcBase.length; j++) { - File[] fromResources = FileUtil.listFiles(srcBase[j], new FileFilter() { + for (File file : srcBase) { + File[] fromResources = FileUtil.listFiles(file, new FileFilter() { public boolean accept(File pathname) { String name = pathname.getName().toLowerCase(); return !name.endsWith(".class") && !name.endsWith(".java") && !name.endsWith(".aj") && !name.endsWith(".lst") && !name.endsWith(".jar"); } }); - for (int i = 0; i < fromResources.length; i++) { - String normPath = FileUtil.normalizedPath(fromResources[i], srcBase[j]); - sourcePathResources.put(normPath, fromResources[i]); + for (File fromResource : fromResources) { + String normPath = FileUtil.normalizedPath(fromResource, file); + sourcePathResources.put(normPath, fromResource); } } |