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.core | |
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.core')
9 files changed, 32 insertions, 38 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 08d3ee377..a83ab5be2 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 @@ -250,11 +250,11 @@ public class AjdeCoreBuildManager { args = new String[l.size() + xmlfiles.size() + 1]; // TODO speedup int p = 0; - for (int i = 0; i < l.size(); i++) { - args[p++] = l.get(i); + for (String s : l) { + args[p++] = s; } - for (int i = 0; i < xmlfiles.size(); i++) { - args[p++] = xmlfiles.get(i); + for (String xmlfile : xmlfiles) { + args[p++] = xmlfile; } args[p++] = "-xmlConfigured"; } else { diff --git a/ajde.core/src/test/java/org/aspectj/ajde/core/AjdeCoreTestCase.java b/ajde.core/src/test/java/org/aspectj/ajde/core/AjdeCoreTestCase.java index 052d547c6..eafa22f04 100644 --- a/ajde.core/src/test/java/org/aspectj/ajde/core/AjdeCoreTestCase.java +++ b/ajde.core/src/test/java/org/aspectj/ajde/core/AjdeCoreTestCase.java @@ -85,8 +85,7 @@ public abstract class AjdeCoreTestCase 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); @@ -141,8 +140,8 @@ public abstract class AjdeCoreTestCase extends TestCase { public List<String> getSourceFileList(String[] files) { List<String> sourceFiles = new ArrayList<String>(); - for (int i = 0; i < files.length; i++) { - sourceFiles.add(getAbsoluteProjectDir() + File.separator + files[i]); + for (String file : files) { + sourceFiles.add(getAbsoluteProjectDir() + File.separator + file); } return sourceFiles; } diff --git a/ajde.core/src/test/java/org/aspectj/ajde/core/TestCompilerConfiguration.java b/ajde.core/src/test/java/org/aspectj/ajde/core/TestCompilerConfiguration.java index 57d1ce73a..e8432c8cf 100644 --- a/ajde.core/src/test/java/org/aspectj/ajde/core/TestCompilerConfiguration.java +++ b/ajde.core/src/test/java/org/aspectj/ajde/core/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); } } diff --git a/ajde.core/src/test/java/org/aspectj/ajde/core/tests/AjConfigTest.java b/ajde.core/src/test/java/org/aspectj/ajde/core/tests/AjConfigTest.java index eb7d67b9c..15d2ff696 100644 --- a/ajde.core/src/test/java/org/aspectj/ajde/core/tests/AjConfigTest.java +++ b/ajde.core/src/test/java/org/aspectj/ajde/core/tests/AjConfigTest.java @@ -135,8 +135,7 @@ public class AjConfigTest extends AjdeCoreTestCase { compilerConfig.setSourcePathResources(m); AjBuildConfig buildConfig = genAjBuildConfig(); Map<String, File> found = buildConfig.getSourcePathResources(); - for (Iterator<String> i = found.keySet().iterator(); i.hasNext();) { - String resource = i.next(); + for (String resource : found.keySet()) { assertEquals("expected to find resource with name newFile.txt but " + "found " + resource, "newFile.txt", resource); File from = buildConfig.getSourcePathResources().get(resource); assertEquals("expected to find resource with file " + getWorkingDir() + "but found " + from, getWorkingDir(), from); diff --git a/ajde.core/src/test/java/org/aspectj/ajde/core/tests/InpathTest.java b/ajde.core/src/test/java/org/aspectj/ajde/core/tests/InpathTest.java index af1040e5f..0696aa908 100644 --- a/ajde.core/src/test/java/org/aspectj/ajde/core/tests/InpathTest.java +++ b/ajde.core/src/test/java/org/aspectj/ajde/core/tests/InpathTest.java @@ -294,8 +294,7 @@ public class InpathTest extends AjdeCoreTestCase { File binBase = openFile(outdirName); String[] toResources = FileUtil.listFiles(binBase); - for (int i = 0; i < toResources.length; i++) { - String fileName = toResources[i]; + for (String fileName : toResources) { if (fileName.indexOf("CVS") == -1) { boolean b = expectedOutdirContents.remove(fileName); assertTrue("Extraneous resources: " + fileName, b); @@ -308,8 +307,8 @@ public class InpathTest extends AjdeCoreTestCase { private void listSourceResources(String indirName, Set<String> resources) { File srcBase = openFile(indirName); File[] fromResources = FileUtil.listFiles(srcBase, aspectjResourceFileFilter); - for (int i = 0; i < fromResources.length; i++) { - String name = FileUtil.normalizedPath(fromResources[i], srcBase); + for (File fromResource : fromResources) { + String name = FileUtil.normalizedPath(fromResource, srcBase); // System.err.println("Checking "+name); if (!name.startsWith("CVS/") && (-1 == name.indexOf("/CVS/")) && !name.endsWith("/CVS")) { resources.add(name); diff --git a/ajde.core/src/test/java/org/aspectj/ajde/core/tests/ResourceCopyTest.java b/ajde.core/src/test/java/org/aspectj/ajde/core/tests/ResourceCopyTest.java index c75da5b04..b6f44ae7d 100644 --- a/ajde.core/src/test/java/org/aspectj/ajde/core/tests/ResourceCopyTest.java +++ b/ajde.core/src/test/java/org/aspectj/ajde/core/tests/ResourceCopyTest.java @@ -155,8 +155,8 @@ public class ResourceCopyTest extends AjdeCoreTestCase { HashSet<String> resources = new HashSet<>(); listSourceResources(indirName, resources); - for (int i = 0; i < toResources.length; i++) { - String fileName = FileUtil.normalizedPath(toResources[i], binBase); + for (File toResource : toResources) { + String fileName = FileUtil.normalizedPath(toResource, binBase); boolean b = resources.remove(fileName); assertTrue("Extraneous resources: " + fileName, b); } @@ -167,8 +167,8 @@ public class ResourceCopyTest extends AjdeCoreTestCase { private void listSourceResources(String indirName, Set<String> resources) { File srcBase = openFile(indirName); File[] fromResources = FileUtil.listFiles(srcBase, aspectjResourceFileFilter); - for (int i = 0; i < fromResources.length; i++) { - String name = FileUtil.normalizedPath(fromResources[i], srcBase); + for (File fromResource : fromResources) { + String name = FileUtil.normalizedPath(fromResource, srcBase); if (!name.startsWith("CVS/") && (-1 == name.indexOf("/CVS/")) && !name.endsWith("/CVS")) { resources.add(name); } @@ -263,12 +263,12 @@ public class ResourceCopyTest extends AjdeCoreTestCase { File binBase = openFile(outdirName); File[] toResources = FileUtil.listFiles(binBase, aspectjResourceFileFilter); - for (int i = 0; i < toResources.length; i++) { - String fileName = FileUtil.normalizedPath(toResources[i], binBase); + for (File toResource : toResources) { + String fileName = FileUtil.normalizedPath(toResource, binBase); /* Ensure we copied the right JAR manifest */ if (fileName.equalsIgnoreCase("meta-inf/Manifest.mf")) { - byte[] outManifest = FileUtil.readAsByteArray(toResources[i]); + byte[] outManifest = FileUtil.readAsByteArray(toResource); assertTrue("Wrong manifest has been copied", Arrays.equals(inManifest, outManifest)); } boolean b = resources.remove(fileName); diff --git a/ajde.core/src/test/java/org/aspectj/ajde/core/tests/ShowWeaveMessagesTest.java b/ajde.core/src/test/java/org/aspectj/ajde/core/tests/ShowWeaveMessagesTest.java index c13462620..bc4263f4e 100644 --- a/ajde.core/src/test/java/org/aspectj/ajde/core/tests/ShowWeaveMessagesTest.java +++ b/ajde.core/src/test/java/org/aspectj/ajde/core/tests/ShowWeaveMessagesTest.java @@ -376,8 +376,8 @@ public class ShowWeaveMessagesTest extends AjdeCoreTestCase { // See if the messages match int msgCount = 0; List<TestMessageHandler.TestMessage> l = handler.getMessages(); - for (Iterator<TestMessageHandler.TestMessage> iter = l.iterator(); iter.hasNext();) { - IMessage msg = iter.next().getContainedMessage(); + for (TestMessageHandler.TestMessage testMessage : l) { + IMessage msg = testMessage.getContainedMessage(); if (debugTests) System.out.println("Looking at [" + msg + "]"); if (msg.getKind().equals(IMessage.WEAVEINFO)) { @@ -416,8 +416,8 @@ public class ShowWeaveMessagesTest extends AjdeCoreTestCase { try { fw = new FileWriter(f); List<TestMessageHandler.TestMessage> l = handler.getMessages(); - for (Iterator<TestMessageHandler.TestMessage> iter = l.iterator(); iter.hasNext();) { - IMessage msg = iter.next().getContainedMessage(); + for (TestMessageHandler.TestMessage testMessage : l) { + IMessage msg = testMessage.getContainedMessage(); if (msg.getKind().equals(IMessage.WEAVEINFO)) { fw.write(msg.getMessage() + "\n"); } diff --git a/ajde.core/src/test/java/org/aspectj/ajde/core/tests/model/AsmRelationshipsTest.java b/ajde.core/src/test/java/org/aspectj/ajde/core/tests/model/AsmRelationshipsTest.java index 20b6e346e..4feefedcb 100644 --- a/ajde.core/src/test/java/org/aspectj/ajde/core/tests/model/AsmRelationshipsTest.java +++ b/ajde.core/src/test/java/org/aspectj/ajde/core/tests/model/AsmRelationshipsTest.java @@ -139,8 +139,7 @@ public class AsmRelationshipsTest extends AjdeCoreTestCase { .findElementForLabel(aspect, IProgramElement.Kind.ADVICE, beforeExec); assertNotNull(beforeExecNode); IRelationship rel = manager.getRelationshipMap().get(beforeExecNode, IRelationship.Kind.ADVICE, relName); - for (Iterator<String> it = rel.getTargets().iterator(); it.hasNext();) { - String currHandle = it.next(); + for (String currHandle : rel.getTargets()) { if (manager.getHierarchy().findElementForHandle(currHandle).toLabelString().equals(to)) return; } @@ -186,8 +185,7 @@ public class AsmRelationshipsTest extends AjdeCoreTestCase { // String set = to; IRelationship rel2 = manager.getRelationshipMap().get(clazz, IRelationship.Kind.DECLARE_INTER_TYPE, backRelName); // String handle2 = (String)rel2.getTargets().get(0); - for (Iterator<String> it = rel2.getTargets().iterator(); it.hasNext();) { - String currHandle = it.next(); + for (String currHandle : rel2.getTargets()) { if (manager.getHierarchy().findElementForHandle(currHandle).toLabelString().equals(from)) return; } diff --git a/ajde.core/src/test/java/org/aspectj/ajde/core/tests/model/StructureModelTest.java b/ajde.core/src/test/java/org/aspectj/ajde/core/tests/model/StructureModelTest.java index 6755ca57e..739daee32 100644 --- a/ajde.core/src/test/java/org/aspectj/ajde/core/tests/model/StructureModelTest.java +++ b/ajde.core/src/test/java/org/aspectj/ajde/core/tests/model/StructureModelTest.java @@ -116,8 +116,7 @@ public class StructureModelTest extends AjdeCoreTestCase { } private void testModelIntegrityHelper(IProgramElement node) throws Exception { - for (Iterator<IProgramElement> it = node.getChildren().iterator(); it.hasNext();) { - IProgramElement child = (IProgramElement) it.next(); + for (IProgramElement child : node.getChildren()) { if (node == child.getParent()) { testModelIntegrityHelper(child); } else { @@ -131,8 +130,8 @@ public class StructureModelTest extends AjdeCoreTestCase { public void preProcess(IProgramElement node) { if (node.getChildren() == null) return; - for (Iterator<IProgramElement> it = node.getChildren().iterator(); it.hasNext();) { - if (it.next() == null) + for (IProgramElement iProgramElement : node.getChildren()) { + if (iProgramElement == null) throw new NullPointerException("null child on node: " + node.getName()); } } |