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 /taskdefs/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 'taskdefs/src/test')
-rw-r--r-- | taskdefs/src/test/java/org/aspectj/tools/ant/taskdefs/Ajc11CompilerAdapterTest.java | 10 | ||||
-rw-r--r-- | taskdefs/src/test/java/org/aspectj/tools/ant/taskdefs/AjcTaskTest.java | 86 |
2 files changed, 48 insertions, 48 deletions
diff --git a/taskdefs/src/test/java/org/aspectj/tools/ant/taskdefs/Ajc11CompilerAdapterTest.java b/taskdefs/src/test/java/org/aspectj/tools/ant/taskdefs/Ajc11CompilerAdapterTest.java index 3b95693e2..80e9ed4a0 100644 --- a/taskdefs/src/test/java/org/aspectj/tools/ant/taskdefs/Ajc11CompilerAdapterTest.java +++ b/taskdefs/src/test/java/org/aspectj/tools/ant/taskdefs/Ajc11CompilerAdapterTest.java @@ -35,11 +35,11 @@ public class Ajc11CompilerAdapterTest extends TestCase { } public void tearDown() { - for (Iterator iter = tempFiles.iterator(); iter.hasNext();) { - File file = (File) iter.next(); - FileUtil.deleteContents(file); - file.delete(); - } + for (Object tempFile : tempFiles) { + File file = (File) tempFile; + FileUtil.deleteContents(file); + file.delete(); + } } // public void testCompilerAdapterWithJavac() { // XXX requires tools.jar diff --git a/taskdefs/src/test/java/org/aspectj/tools/ant/taskdefs/AjcTaskTest.java b/taskdefs/src/test/java/org/aspectj/tools/ant/taskdefs/AjcTaskTest.java index c149ad79b..b1f7c7b4f 100644 --- a/taskdefs/src/test/java/org/aspectj/tools/ant/taskdefs/AjcTaskTest.java +++ b/taskdefs/src/test/java/org/aspectj/tools/ant/taskdefs/AjcTaskTest.java @@ -187,17 +187,17 @@ public class AjcTaskTest extends TestCase { } private void checkContains(String[] cmd, String option, boolean contains) { - for (int i = 0; i < cmd.length; i++) { - if (option.equals(cmd[i])) { - if (contains) { - return; - } else { - assertTrue( - "not expecting " + option + " in " + Arrays.asList(cmd), - false); - } - } - } + for (String s : cmd) { + if (option.equals(s)) { + if (contains) { + return; + } else { + assertTrue( + "not expecting " + option + " in " + Arrays.asList(cmd), + false); + } + } + } if (contains) { assertTrue( "expecting " + option + " in " + Arrays.asList(cmd), @@ -279,8 +279,8 @@ public class AjcTaskTest extends TestCase { AjcTask task = getTask(NOFILE, null); String[] cmd = task.makeCommand(); - for (int i = 0; i < cmd.length; i++) { - assertTrue(!"-d".equals(cmd[i])); + for (String s : cmd) { + assertTrue(!"-d".equals(s)); } } @@ -398,14 +398,14 @@ public class AjcTaskTest extends TestCase { String[] expected = {"copyMe.htm", "pack/includeme", "pack/Pack.class", "Default.class"}; String[] unexpected = {"doNotCopy", "skipTxtFiles.txt", "pack/something.txt"}; - for (int i = 0; i < expected.length; i++) { - JarEntry entry = jarFile.getJarEntry(expected[i]); - assertTrue(expected[i] + " not found", null != entry); - } - for (int i = 0; i < unexpected.length; i++) { - JarEntry entry = jarFile.getJarEntry(unexpected[i]); - assertTrue(unexpected[i] + " found", null == entry); - } + for (String value : expected) { + JarEntry entry = jarFile.getJarEntry(value); + assertTrue(value + " not found", null != entry); + } + for (String s : unexpected) { + JarEntry entry = jarFile.getJarEntry(s); + assertTrue(s + " found", null == entry); + } } public void testInpathDirCopyFilterError() { @@ -656,30 +656,30 @@ public class AjcTaskTest extends TestCase { public void testVersions() { String[] inputs = AjcTask.TARGET_INPUTS; - for (int i = 0; i < inputs.length; i++) { + for (String value : inputs) { AjcTask task = getTask(NOFILE); - task.setTarget(inputs[i]); + task.setTarget(value); String[] cmd = task.makeCommand(); - checkContains(cmd, "-target", true); - checkContains(cmd, inputs[i], true); + checkContains(cmd, "-target", true); + checkContains(cmd, value, true); } inputs = AjcTask.SOURCE_INPUTS; - for (int i = 0; i < inputs.length; i++) { - AjcTask task = getTask(NOFILE); - task.setSource(inputs[i]); - String[] cmd = task.makeCommand(); - checkContains(cmd, "-source", true); - checkContains(cmd, inputs[i], true); - } + for (String s : inputs) { + AjcTask task = getTask(NOFILE); + task.setSource(s); + String[] cmd = task.makeCommand(); + checkContains(cmd, "-source", true); + checkContains(cmd, s, true); + } inputs = AjcTask.COMPLIANCE_INPUTS; - for (int i = 0; i < inputs.length; i++) { - AjcTask task = getTask(NOFILE); - task.setCompliance(inputs[i]); - String[] cmd = task.makeCommand(); - checkContains(cmd, inputs[i], true); - } + for (String input : inputs) { + AjcTask task = getTask(NOFILE); + task.setCompliance(input); + String[] cmd = task.makeCommand(); + checkContains(cmd, input, true); + } } public void testClasspath() { @@ -807,11 +807,11 @@ public class AjcTaskTest extends TestCase { "reweavable:compress", "noInline" }; - for (int i = 0; i < xopts.length; i++) { + for (String xopt : xopts) { AjcTask task = getTask(NOFILE); - task.setX(xopts[i]); + task.setX(xopt); String[] cmd = task.makeCommand(); - checkContains(cmd,"-X" + xopts[i],true); + checkContains(cmd, "-X" + xopt, true); } } @@ -1080,8 +1080,8 @@ class VerboseCommandEditor implements ICommandEditor { public static final String VERBOSE = "-verbose"; @Override public String[] editCommand(String[] command) { - for (int i = 0; i < command.length; i++) { - if (VERBOSE.equals(command[i])) { + for (String s : command) { + if (VERBOSE.equals(s)) { return command; } } |