aboutsummaryrefslogtreecommitdiffstats
path: root/taskdefs
diff options
context:
space:
mode:
authorLars Grefer <eclipse@larsgrefer.de>2020-08-08 03:06:37 +0200
committerLars Grefer <eclipse@larsgrefer.de>2020-08-08 03:06:37 +0200
commit72194b7982ddfa8e9864d0a9934905bb76b90f33 (patch)
treeebed806c358c1a3960c5d6be4c13b26ca41809df /taskdefs
parentc3289ab86bfb2c97cf34147239b3dde46de92a7c (diff)
downloadaspectj-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')
-rw-r--r--taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/Ajc10.java50
-rw-r--r--taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/Ajc2.java16
-rw-r--r--taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/AjcCompilerAdapter.java6
-rw-r--r--taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/AjcTask.java23
-rw-r--r--taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/Ajdoc.java83
-rw-r--r--taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/compilers/Ajc.java36
-rw-r--r--taskdefs/src/test/java/org/aspectj/tools/ant/taskdefs/Ajc11CompilerAdapterTest.java10
-rw-r--r--taskdefs/src/test/java/org/aspectj/tools/ant/taskdefs/AjcTaskTest.java86
8 files changed, 154 insertions, 156 deletions
diff --git a/taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/Ajc10.java b/taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/Ajc10.java
index 065f44e71..354702f5a 100644
--- a/taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/Ajc10.java
+++ b/taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/Ajc10.java
@@ -439,32 +439,32 @@ public class Ajc10 extends MatchingTask {
int numargfiles = 0;
if (argfiles != null) {
- for (Iterator i = argfiles.iterator(); i.hasNext();) {
- String name = i.next()+"";
- File argfile = project.resolveFile(name);
- if (check(argfile, name, false, location)) {
- cmd.createArgument().setValue("-argfile");
- cmd.createArgument().setFile(argfile);
- numargfiles++;
- }
- }
+ for (Object o : argfiles) {
+ String name = o + "";
+ File argfile = project.resolveFile(name);
+ if (check(argfile, name, false, location)) {
+ cmd.createArgument().setValue("-argfile");
+ cmd.createArgument().setFile(argfile);
+ numargfiles++;
+ }
+ }
}
int numfiles = 0;
if (srcdir != null) {
// todo: ignore any srcdir if any argfiles and no explicit includes
String[] dirs = srcdir.list();
- for (int i = 0; i < dirs.length; i++) {
- File dir = project.resolveFile(dirs[i]);
- check(dir, dirs[i], true, location);
- String[] files = getDirectoryScanner(dir).getIncludedFiles();
- for (int j = 0; j < files.length; j++) {
- File file = new File(dir, files[j]);
- if (FileUtil.hasSourceSuffix(file)) {
- cmd.createArgument().setFile(file);
- numfiles++;
- }
- }
- }
+ for (String value : dirs) {
+ File dir = project.resolveFile(value);
+ check(dir, value, true, location);
+ String[] files = getDirectoryScanner(dir).getIncludedFiles();
+ for (String s : files) {
+ File file = new File(dir, s);
+ if (FileUtil.hasSourceSuffix(file)) {
+ cmd.createArgument().setFile(file);
+ numfiles++;
+ }
+ }
+ }
}
if ((null != ignoredOptions) && (ignoredOptions.size() > 0)) {
log("The following attributes were ignored " + ignoredOptions,
@@ -568,10 +568,10 @@ public class Ajc10 extends MatchingTask {
public static String render(String[] args) {
if (null == args) return "";
StringBuffer sb = new StringBuffer();
- for (int i = 0; i < args.length; i++) {
- sb.append(args[i]);
- sb.append(" ");
- }
+ for (String arg : args) {
+ sb.append(arg);
+ sb.append(" ");
+ }
return sb.toString();
}
diff --git a/taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/Ajc2.java b/taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/Ajc2.java
index f31c7558f..a089f00b9 100644
--- a/taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/Ajc2.java
+++ b/taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/Ajc2.java
@@ -434,14 +434,14 @@ public class Ajc2 extends Javac {
// Otherwise we want to add all .java files to the compileList
else {
- for (int i = 0; i < files.length; i++) {
- File newFile = new File(srcDir, files[i]);
- if (newFile != null &&
- newFile.exists() &&
- newFile.getName().endsWith(".java")) {
- newFiles.add(newFile);
- }
- }
+ for (String file : files) {
+ File newFile = new File(srcDir, file);
+ if (newFile != null &&
+ newFile.exists() &&
+ newFile.getName().endsWith(".java")) {
+ newFiles.add(newFile);
+ }
+ }
}
// Add the new included files
diff --git a/taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/AjcCompilerAdapter.java b/taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/AjcCompilerAdapter.java
index 1542f6cb4..a0c84d2db 100644
--- a/taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/AjcCompilerAdapter.java
+++ b/taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/AjcCompilerAdapter.java
@@ -94,9 +94,9 @@ public class AjcCompilerAdapter implements CompilerAdapter {
tempAjc.setIncludeantruntime(javac.getIncludeantruntime()); // XXX unsupported
File[] files = javac.getFileList();
if (null != files) {
- for (int i = 0; i < files.length; i++) {
- tempAjc.backdoorSetFile(files[i]);
- }
+ for (File file : files) {
+ tempAjc.backdoorSetFile(file);
+ }
}
ajc = tempAjc;
}
diff --git a/taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/AjcTask.java b/taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/AjcTask.java
index 4f40526c7..c68a1eb59 100644
--- a/taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/AjcTask.java
+++ b/taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/AjcTask.java
@@ -1161,9 +1161,9 @@ public class AjcTask extends MatchingTask {
String[] makeCommand() {
ArrayList result = new ArrayList();
if (0 < ignored.size()) {
- for (Iterator iter = ignored.iterator(); iter.hasNext();) {
- logVerbose("ignored: " + iter.next());
- }
+ for (Object o : ignored) {
+ logVerbose("ignored: " + o);
+ }
}
// when copying resources, use temp jar for class output
// then copy temp jar contents and resources to output jar
@@ -1576,14 +1576,15 @@ public class AjcTask extends MatchingTask {
}
}
if (0 < adapterFiles.size()) {
- for (Iterator iter = adapterFiles.iterator(); iter.hasNext();) {
- File file = (File) iter.next();
- if (file.canRead() && FileUtil.hasSourceSuffix(file)) {
- list.add(file.getAbsolutePath());
- } else {
- this.logger.warning("skipping file: " + file);
- }
- }
+ for (Object adapterFile : adapterFiles) {
+ File file = (File) adapterFile;
+ if (file.canRead() && FileUtil.hasSourceSuffix(file)) {
+ list.add(file.getAbsolutePath());
+ }
+ else {
+ this.logger.warning("skipping file: " + file);
+ }
+ }
}
}
diff --git a/taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/Ajdoc.java b/taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/Ajdoc.java
index b787a2f89..194efaf22 100644
--- a/taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/Ajdoc.java
+++ b/taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/Ajdoc.java
@@ -178,9 +178,9 @@ public class Ajdoc extends MatchingTask {
File baseDir = fs.getDir(getProject());
DirectoryScanner ds = fs.getDirectoryScanner(getProject());
String[] files = ds.getIncludedFiles();
- for (int i = 0; i < files.length; i++) {
- sourcefiles.add((new File(baseDir, files[i])).getAbsolutePath());
- }
+ for (String file : files) {
+ sourcefiles.add((new File(baseDir, file)).getAbsolutePath());
+ }
}
}
@@ -606,17 +606,16 @@ public class Ajdoc extends MatchingTask {
cmd.createArgument().setValue("-docletpath");
cmd.createArgument().setPath(doclet.path);
}
- for (Iterator i = doclet.params.iterator(); i.hasNext();) {
- Param param = (Param)i.next();
- if (param.name == null) {
- throw new BuildException("Doclet params cannot be null!",
- getLocation());
- }
- cmd.createArgument().setValue(param.name);
- if (param.value == null) {
- cmd.createArgument().setValue(param.value);
- }
- }
+ for (Param param : doclet.params) {
+ if (param.name == null) {
+ throw new BuildException("Doclet params cannot be null!",
+ getLocation());
+ }
+ cmd.createArgument().setValue(param.name);
+ if (param.value == null) {
+ cmd.createArgument().setValue(param.value);
+ }
+ }
}
Map<String,List<String>> groupMap = new HashMap<String,List<String>>();
for (Group group: groups) {
@@ -647,48 +646,48 @@ public class Ajdoc extends MatchingTask {
cmd.createArgument().setValue(pkgstr);
}
if (argfiles != null) {
- for (Iterator i = argfiles.iterator(); i.hasNext();) {
- String name = i.next()+"";
- File argfile = getProject().resolveFile(name);
- if (check(argfile, name, false, getLocation())) {
- cmd.createArgument().setValue("-argfile");
- cmd.createArgument().setFile(argfile);
- }
- }
+ for (File file : argfiles) {
+ String name = file + "";
+ File argfile = getProject().resolveFile(name);
+ if (check(argfile, name, false, getLocation())) {
+ cmd.createArgument().setValue("-argfile");
+ cmd.createArgument().setFile(argfile);
+ }
+ }
}
if (packageList != null) {
cmd.createArgument().setValue("@" + packageList);
}
if (null != packagenames) {
- for (Iterator<String> i = packagenames.iterator(); i.hasNext();) {
- cmd.createArgument().setValue((String)i.next());
- }
+ for (String packagename : packagenames) {
+ cmd.createArgument().setValue(packagename);
+ }
}
// support for include parameter as a MatchingTask
int numfiles = 0;
if (sourcepath != null) {
String[] dirs = sourcepath.list();
- for (int i = 0; i < dirs.length; i++) {
- File dir = getProject().resolveFile(dirs[i]);
- check(dir, dirs[i], true, getLocation());
- String[] files = getDirectoryScanner(dir).getIncludedFiles();
- for (int j = 0; j < files.length; j++) {
- File file = new File(dir, files[j]);
- if (file.getName().endsWith(".java")
- || file.getName().endsWith(".aj")) {
- cmd.createArgument().setFile(file);
- numfiles++;
- }
- }
- }
+ for (String value : dirs) {
+ File dir = getProject().resolveFile(value);
+ check(dir, value, true, getLocation());
+ String[] files = getDirectoryScanner(dir).getIncludedFiles();
+ for (String s : files) {
+ File file = new File(dir, s);
+ if (file.getName().endsWith(".java")
+ || file.getName().endsWith(".aj")) {
+ cmd.createArgument().setFile(file);
+ numfiles++;
+ }
+ }
+ }
}
addFileSets();
if (sourcefiles != null) {
- for (Iterator<String> i = sourcefiles.iterator(); i.hasNext();) {
- // let ajdoc resolve sourcefiles relative to sourcepath,
- cmd.createArgument().setValue(i.next());
- }
+ for (String sourcefile : sourcefiles) {
+ // let ajdoc resolve sourcefiles relative to sourcepath,
+ cmd.createArgument().setValue(sourcefile);
+ }
}
// XXX PR682 weak way to report errors - need to refactor
int result = compile();
diff --git a/taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/compilers/Ajc.java b/taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/compilers/Ajc.java
index 690cccf22..0242b4d58 100644
--- a/taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/compilers/Ajc.java
+++ b/taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/compilers/Ajc.java
@@ -198,25 +198,23 @@ public class Ajc extends DefaultCompilerAdapter {
niceSourceList.append(" to be compiled:");
niceSourceList.append(lSep);
- for (int i=0; i < compileList.length; i++) {
-
- // DefaultCompilerAdapter only expects .java files but we must deal
- // with .lst files also
- File file = compileList[i];
-
- if (file == null) continue;
-
- String arg = file.getAbsolutePath();
- String rest = "";
- String name = file.getName();
-
- // For .java files take the default behavior and add that
- // file to the command line
- if (name.endsWith(".java")) {
- cmd.createArgument().setValue(arg);
- }
- niceSourceList.append(" " + arg + rest + lSep);
- }
+ for (File file : compileList) {
+
+ // DefaultCompilerAdapter only expects .java files but we must deal
+ // with .lst files also
+ if (file == null) continue;
+
+ String arg = file.getAbsolutePath();
+ String rest = "";
+ String name = file.getName();
+
+ // For .java files take the default behavior and add that
+ // file to the command line
+ if (name.endsWith(".java")) {
+ cmd.createArgument().setValue(arg);
+ }
+ niceSourceList.append(" " + arg + rest + lSep);
+ }
attributes.log(niceSourceList.toString(), Project.MSG_VERBOSE);
}
}
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;
}
}