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 /build/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 'build/src')
13 files changed, 307 insertions, 329 deletions
diff --git a/build/src/main/java/$installer$/org/aspectj/Main.java b/build/src/main/java/$installer$/org/aspectj/Main.java index 6ecebae63..2ffc8b889 100644 --- a/build/src/main/java/$installer$/org/aspectj/Main.java +++ b/build/src/main/java/$installer$/org/aspectj/Main.java @@ -707,8 +707,8 @@ class InstallContext { public boolean isTextFile(File file) { String name = file.getName(); - for (int i = 0; i < TEXT_EXTENSIONS.length; i++) { - if (name.endsWith(TEXT_EXTENSIONS[i])) { + for (String textExtension : TEXT_EXTENSIONS) { + if (name.endsWith(textExtension)) { return true; } } @@ -1243,10 +1243,9 @@ class ConfigureLauncherPane extends WizardPane { paths = unixPaths; } - for (int suffixIndex = 0; suffixIndex < suffixes.length; suffixIndex++) { - String suffix = suffixes[suffixIndex]; - for (int prefixIndex = 0; prefixIndex < paths.length; prefixIndex++) { - String prefix = paths[prefixIndex]; + for (String suffix : suffixes) { + for (String path : paths) { + String prefix = path; prefix = applyProperties(prefix); File test = new File(prefix + suffix); if (isLegalJavaHome(test)) { diff --git a/build/src/main/java/org/aspectj/internal/tools/ant/taskdefs/AJInstaller.java b/build/src/main/java/org/aspectj/internal/tools/ant/taskdefs/AJInstaller.java index 2428e66d9..809ac1cbb 100644 --- a/build/src/main/java/org/aspectj/internal/tools/ant/taskdefs/AJInstaller.java +++ b/build/src/main/java/org/aspectj/internal/tools/ant/taskdefs/AJInstaller.java @@ -152,11 +152,10 @@ public class AJInstaller extends MatchingTask { StringBuffer buf = new StringBuffer(); buf.append(contentsBytes); buf.append(NEWLINE); - for (Iterator<String> i = contentsNames.iterator(); i.hasNext(); ) { - String name = i.next(); - buf.append(name); - buf.append(NEWLINE); - } + for (String name : contentsNames) { + buf.append(name); + buf.append(NEWLINE); + } zipFile(new StringBufferInputStream(buf.toString()), zOut, CONTENTS_FILE, System.currentTimeMillis()); } @@ -347,19 +346,19 @@ public class AJInstaller extends MatchingTask { } protected void writeDirs(ZipOutputStream zOut, String[] dirs) throws IOException { - for (int i = 0; i < dirs.length; i++) { - File f = new File(baseDir,dirs[i]); - String name = dirs[i].replace(File.separatorChar,'/')+"/"; - zipDir(f, zOut, name); - } + for (String dir : dirs) { + File f = new File(baseDir, dir); + String name = dir.replace(File.separatorChar, '/') + "/"; + zipDir(f, zOut, name); + } } protected void writeFiles(ZipOutputStream zOut, String[] files) throws IOException { - for (int i = 0; i < files.length; i++) { - File f = new File(baseDir,files[i]); - String name = files[i].replace(File.separatorChar,'/'); - zipFile(f, zOut, name); - } + for (String file : files) { + File f = new File(baseDir, file); + String name = file.replace(File.separatorChar, '/'); + zipFile(f, zOut, name); + } } } diff --git a/build/src/main/java/org/aspectj/internal/tools/ant/taskdefs/AntBuilder.java b/build/src/main/java/org/aspectj/internal/tools/ant/taskdefs/AntBuilder.java index c4f8848d8..bef3fb0aa 100644 --- a/build/src/main/java/org/aspectj/internal/tools/ant/taskdefs/AntBuilder.java +++ b/build/src/main/java/org/aspectj/internal/tools/ant/taskdefs/AntBuilder.java @@ -95,8 +95,7 @@ public class AntBuilder extends Builder { Result[] reqs = result.getRequired(); StringBuffer depends = new StringBuffer(); boolean first = true; - for (int i = 0; i < reqs.length; i++) { - Result reqResult = reqs[i]; + for (Result reqResult : reqs) { if (!first) { depends.append(","); } else { @@ -110,8 +109,7 @@ public class AntBuilder extends Builder { targets.put(resultTargetName, target); // then recursively add any required results - for (int i = 0; i < reqs.length; i++) { - Result reqResult = reqs[i]; + for (Result reqResult : reqs) { makeTargetsForResult(reqResult, targets); } } @@ -311,8 +309,7 @@ public class AntBuilder extends Builder { public boolean setupClasspath(Result result, Path classpath) { // XXX fix test access boolean hasLibraries = false; // required libraries - for (Iterator<File> iter = result.getLibJars().iterator(); iter.hasNext();) { - File file = iter.next(); + for (File file : result.getLibJars()) { classpath.createPathElement().setLocation(file); if (!hasLibraries) { hasLibraries = true; @@ -321,16 +318,15 @@ public class AntBuilder extends Builder { // Westodo Kind kind = result.getKind(); Result[] reqs = result.getRequired(); // required modules and their exported libraries - for (int i = 0; i < reqs.length; i++) { - Result requiredResult = reqs[i]; + for (Result requiredResult : reqs) { classpath.createPathElement().setLocation(requiredResult.getOutputFile()); if (!hasLibraries) { hasLibraries = true; } // also put on classpath libraries exported from required module // XXX exported modules not supported - for (Iterator<File> iterator = requiredResult.getExportedLibJars().iterator(); iterator.hasNext();) { - classpath.createPathElement().setLocation(iterator.next()); + for (File file : requiredResult.getExportedLibJars()) { + classpath.createPathElement().setLocation(file); } } return hasLibraries; @@ -424,8 +420,7 @@ public class AntBuilder extends Builder { return new Result[0]; } ArrayList<String> toReturn = new ArrayList<String>(); - for (Iterator<Target> iter = result.iterator(); iter.hasNext();) { - Target target = iter.next(); + for (Target target : result) { String name = target.getName(); if (null == name) { throw new Error("null name?"); diff --git a/build/src/main/java/org/aspectj/internal/tools/ant/taskdefs/ConditionalTask.java b/build/src/main/java/org/aspectj/internal/tools/ant/taskdefs/ConditionalTask.java index ccb9c2149..e71795912 100644 --- a/build/src/main/java/org/aspectj/internal/tools/ant/taskdefs/ConditionalTask.java +++ b/build/src/main/java/org/aspectj/internal/tools/ant/taskdefs/ConditionalTask.java @@ -145,11 +145,11 @@ public abstract class ConditionalTask extends Task { return isOneOf(prop, trues) || isOneOf(prop, complement(falses)); } private boolean isOneOf(String prop, String[] strings) { - for (int i = 0; i < strings.length; i++) { - if (strings[i].equals(prop)) { - return true; - } - } + for (String string : strings) { + if (string.equals(prop)) { + return true; + } + } return false; } private String[] complement(String[] strings) { diff --git a/build/src/main/java/org/aspectj/internal/tools/ant/taskdefs/StripNonBodyHtml.java b/build/src/main/java/org/aspectj/internal/tools/ant/taskdefs/StripNonBodyHtml.java index a33505d95..61e29f3b3 100644 --- a/build/src/main/java/org/aspectj/internal/tools/ant/taskdefs/StripNonBodyHtml.java +++ b/build/src/main/java/org/aspectj/internal/tools/ant/taskdefs/StripNonBodyHtml.java @@ -81,13 +81,13 @@ public class StripNonBodyHtml extends MatchingTask { log("stripping " + files.length + " files"); int stripped = 0; - for (int i = 0, len = files.length; i < len; i++) { - if (processFile(files[i])) { - stripped++; - } else { - log(files[i] + " not stripped"); - } - } + for (String file : files) { + if (processFile(file)) { + stripped++; + } else { + log(file + " not stripped"); + } + } log(stripped + " files successfully stripped"); } diff --git a/build/src/main/java/org/aspectj/internal/tools/build/Builder.java b/build/src/main/java/org/aspectj/internal/tools/build/Builder.java index 8efea662a..1d7bfa7d8 100644 --- a/build/src/main/java/org/aspectj/internal/tools/build/Builder.java +++ b/build/src/main/java/org/aspectj/internal/tools/build/Builder.java @@ -281,10 +281,10 @@ public abstract class Builder { } finally { if (0 < errors.size()) { String label = "error building " + buildSpec + ": "; - for (Iterator<String> iter = errors.iterator(); iter.hasNext();) { - String m = label + iter.next(); - handler.error(m); - } + for (String error : errors) { + String m = label + error; + handler.error(m); + } } } } @@ -294,15 +294,15 @@ public abstract class Builder { */ public boolean cleanup() { boolean noErr = true; - for (ListIterator iter = tempFiles.listIterator(); iter.hasNext();) { - File file = (File) iter.next(); - if (!Util.deleteContents(file) || !file.delete()) { - if (noErr) { - noErr = false; - } - handler.log("unable to clean up " + file); - } - } + for (Object tempFile : tempFiles) { + File file = (File) tempFile; + if (!Util.deleteContents(file) || !file.delete()) { + if (noErr) { + noErr = false; + } + handler.log("unable to clean up " + file); + } + } return noErr; } @@ -345,19 +345,18 @@ public abstract class Builder { if (isLogging()) { handler.log("modules to build: " + Arrays.asList(buildList)); } - for (int i = 0; i < buildList.length; i++) { - Result required = buildList[i]; - if (!buildingEnabled) { - return false; - } - String requiredName = required.getName(); - if (!doneList.contains(requiredName)) { - doneList.add(requiredName); - if (!buildOnly(required, errors)) { - return false; - } - } - } + for (Result required : buildList) { + if (!buildingEnabled) { + return false; + } + String requiredName = required.getName(); + if (!doneList.contains(requiredName)) { + doneList.add(requiredName); + if (!buildOnly(required, errors)) { + return false; + } + } + } } return true; } @@ -439,14 +438,14 @@ public abstract class Builder { handler); ProductModule[] productModules = discoverModules(buildSpec.productDir, modules); - for (int i = 0; i < productModules.length; i++) { - if (buildSpec.verbose) { - handler.log("building product module " + productModules[i]); - } - if (!buildProductModule(productModules[i])) { - return false; - } - } + for (ProductModule module : productModules) { + if (buildSpec.verbose) { + handler.log("building product module " + module); + } + if (!buildProductModule(module)) { + return false; + } + } if (buildSpec.verbose) { handler.log("assembling product module for " + buildSpec); } @@ -476,12 +475,12 @@ public abstract class Builder { String excludes = null; { StringBuffer buf = new StringBuffer(); - for (int i = 0; i < productModules.length; i++) { - if (0 < buf.length()) { - buf.append(","); - } - buf.append(productModules[i].relativePath); - } + for (ProductModule productModule : productModules) { + if (0 < buf.length()) { + buf.append(","); + } + buf.append(productModule.relativePath); + } if (0 < buf.length()) { excludes = buf.toString(); } @@ -492,14 +491,13 @@ public abstract class Builder { } // copy binaries associated with module flag files - for (int i = 0; i < productModules.length; i++) { - final ProductModule product = productModules[i]; - final Kind kind = Result.kind(Result.NORMAL, product.assembleAll); - Result result = product.module.getResult(kind); - String targPath = Util.path(targDirPath, product.relativePath); - File jarFile = result.getOutputFile(); - copyFile(jarFile, new File(targPath), FILTER_OFF); - } + for (final ProductModule product : productModules) { + final Kind kind = Result.kind(Result.NORMAL, product.assembleAll); + Result result = product.module.getResult(kind); + String targPath = Util.path(targDirPath, product.relativePath); + File jarFile = result.getOutputFile(); + copyFile(jarFile, new File(targPath), FILTER_OFF); + } handler.log("created product in " + targDir); // ---- create installer @@ -533,9 +531,9 @@ public abstract class Builder { Result result = module.module.getResult(productKind); return buildAll(result, errors); } finally { - for (Iterator<String> iter = errors.iterator(); iter.hasNext();) { - handler.error("error building " + module + ": " + iter.next()); - } + for (String error : errors) { + handler.error("error building " + module + ": " + error); + } } } @@ -595,13 +593,12 @@ public abstract class Builder { File library = liter.next(); final String fname = library.getName(); if (null != fname) { - for (Iterator<String> iter = SKIP_LIBRARIES.iterator(); iter.hasNext();) { - String name = iter.next(); - if (fname.equals(name)) { - liter.remove(); - break; - } - } + for (String name : SKIP_LIBRARIES) { + if (fname.equals(name)) { + liter.remove(); + break; + } + } } } } diff --git a/build/src/main/java/org/aspectj/internal/tools/build/Module.java b/build/src/main/java/org/aspectj/internal/tools/build/Module.java index 58789424f..acc8fd90b 100644 --- a/build/src/main/java/org/aspectj/internal/tools/build/Module.java +++ b/build/src/main/java/org/aspectj/internal/tools/build/Module.java @@ -79,13 +79,13 @@ public class Module { return; } File[] files = srcDir.listFiles(); - for (int i = 0; i < files.length; i++) { - if (files[i].isDirectory()) { - sourceFiles(files[i], result); - } else if (isSourceFile(files[i])) { - result.add(files[i]); - } - } + for (File file : files) { + if (file.isDirectory()) { + sourceFiles(file, result); + } else if (isSourceFile(file)) { + result.add(file); + } + } } private static void addIfNew(List<File> source, List<File> sink) { @@ -107,14 +107,13 @@ public class Module { addIfNew(result.getLibJars(), known); addIfNew(result.getExportedLibJars(), known); Result[] reqs = result.getRequired(); - for (int i = 0; i < reqs.length; i++) { - Result requiredResult = reqs[i]; - File requiredJar = requiredResult.getOutputFile(); - if (!known.contains(requiredJar)) { - known.add(requiredJar); - doFindJarRequirements(requiredResult, known); - } - } + for (Result requiredResult : reqs) { + File requiredJar = requiredResult.getOutputFile(); + if (!known.contains(requiredJar)) { + known.add(requiredJar); + doFindJarRequirements(requiredResult, known); + } + } } /** @return true if this is a source file */ @@ -238,31 +237,29 @@ public class Module { } final long time = outputFile.lastModified(); File file; - for (Iterator<File> iter = result.getSrcDirs().iterator(); iter.hasNext();) { - File srcDir = iter.next(); - for (Iterator<File> srcFiles = sourceFiles(srcDir); srcFiles.hasNext();) { - file = srcFiles.next(); - if (outOfDate(time, file)) { - return true; - } - } - } + for (File srcDir : result.getSrcDirs()) { + for (Iterator<File> srcFiles = sourceFiles(srcDir); srcFiles.hasNext(); ) { + file = srcFiles.next(); + if (outOfDate(time, file)) { + return true; + } + } + } // required modules Result[] reqs = result.getRequired(); - for (int i = 0; i < reqs.length; i++) { - Result requiredResult = reqs[i]; - file = requiredResult.getOutputFile(); - if (outOfDate(time, file)) { - return true; - } - } + for (Result requiredResult : reqs) { + file = requiredResult.getOutputFile(); + if (outOfDate(time, file)) { + return true; + } + } // libraries - for (Iterator<File> iter = result.getLibJars().iterator(); iter.hasNext();) { - file = iter.next(); - if (outOfDate(time, file)) { - return true; - } - } + for (File value : result.getLibJars()) { + file = value; + if (outOfDate(time, file)) { + return true; + } + } return false; } @@ -345,14 +342,13 @@ public class Module { Util.closeSilently(fin); } RequiredBundle[] bundles = bundle.getRequiredBundles(); - for (int i = 0; i < bundles.length; i++) { - RequiredBundle required = bundles[i]; - update("src", "/" + required.name, required.text, false); - } + for (RequiredBundle required : bundles) { + update("src", "/" + required.name, required.text, false); + } String[] libs = bundle.getClasspath(); - for (int i = 0; i < libs.length; i++) { - update("lib", libs[i], libs[i], false); - } + for (String lib : libs) { + update("lib", lib, lib, false); + } return true; } @@ -478,11 +474,11 @@ public class Module { private void warnVariable(String path, String toString) { String[] known = { "JRE_LIB", "ASPECTJRT_LIB", "JRE15_LIB" }; - for (int i = 0; i < known.length; i++) { - if (known[i].equals(path)) { - return; - } - } + for (String s : known) { + if (s.equals(path)) { + return; + } + } messager.log("Module cannot handle var yet: " + toString); } @@ -645,9 +641,9 @@ public class Module { public void acceptLine(String line) { String[] tokens = tokenize(line); - for (int i = 0; i < tokens.length; i++) { - next(tokens[i]); - } + for (String token : tokens) { + next(token); + } } private Properties attributesToProperties() { diff --git a/build/src/main/java/org/aspectj/internal/tools/build/SampleGatherer.java b/build/src/main/java/org/aspectj/internal/tools/build/SampleGatherer.java index 4e9f59011..4df90dbbe 100644 --- a/build/src/main/java/org/aspectj/internal/tools/build/SampleGatherer.java +++ b/build/src/main/java/org/aspectj/internal/tools/build/SampleGatherer.java @@ -89,9 +89,9 @@ public class SampleGatherer { return; } Samples result = new Samples(); - for (int i = 0; i < args.length; i++) { - result = gather(new File(args[i]), result); - } + for (String arg : args) { + result = gather(new File(arg), result); + } StringBuffer sb = HTMLSamplesRenderer.ME.render(result, null); @@ -144,9 +144,9 @@ public class SampleGatherer { } } else if (source.isDirectory() && source.canRead()) { File[] files = source.listFiles(); - for (int i = 0; i < files.length; i++) { - doGather(files[i], sink); - } + for (File file : files) { + doGather(file, sink); + } } } @@ -156,11 +156,11 @@ public class SampleGatherer { } String path = file.getName().toLowerCase(); String[] suffixes = Sample.Kind.SOURCE_SUFFIXES; - for (int i = 0; i < suffixes.length; i++) { - if (path.endsWith(suffixes[i])) { - return true; - } - } + for (String suffix : suffixes) { + if (path.endsWith(suffix)) { + return true; + } + } return false; } @@ -451,7 +451,8 @@ class SamplesRenderer { public static final String COPYRIGHT = "<p><small>Copyright 2003 Contributors. All Rights Reserved. " - + "This sample code is made available under the Common Public "
+ "License version 1.0 available at " + + "This sample code is made available under the Common Public " + + "License version 1.0 available at " + "<a href=\"http://www.eclipse.org/legal/epl-v10.html\">" + "http://www.eclipse.org/legal/epl-v10.html</a>." + "Contributors are listed in this document as authors. " @@ -473,18 +474,16 @@ class SamplesRenderer { startList(samples, sink); List<Sample> list = samples.getSortedSamples(); String anchorName = null; - for (ListIterator<Sample> iter = list.listIterator(); - iter.hasNext();) { - Sample sample = iter.next(); - String newAnchorName = sample.anchorName; - if ((null == anchorName) - || (!anchorName.equals(newAnchorName))) { - endAnchorName(anchorName, sink); - startAnchorName(newAnchorName, sample.anchorTitle, sink); - anchorName = newAnchorName; - } - render(sample, sink); - } + for (Sample sample : list) { + String newAnchorName = sample.anchorName; + if ((null == anchorName) + || (!anchorName.equals(newAnchorName))) { + endAnchorName(anchorName, sink); + startAnchorName(newAnchorName, sample.anchorTitle, sink); + anchorName = newAnchorName; + } + render(sample, sink); + } endAnchorName(anchorName, sink); endList(samples, sink); return sink; @@ -605,17 +604,16 @@ class HTMLSamplesRenderer extends SamplesRenderer { sampleSection.append(EOL); if (doFlags) { boolean flagHeaderDone = false; - for (Iterator iter = sample.flags.iterator(); iter.hasNext();) { - String flag = (String) iter.next(); - if (!flagHeaderDone) { - sampleSection.append("<p>Comments flagged:<ul>"); - sampleSection.append(EOL); - flagHeaderDone = true; - } - sampleSection.append("<li>"); - sampleSection.append(flag); - sampleSection.append("</li>"); - } + for (String flag : sample.flags) { + if (!flagHeaderDone) { + sampleSection.append("<p>Comments flagged:<ul>"); + sampleSection.append(EOL); + flagHeaderDone = true; + } + sampleSection.append("<li>"); + sampleSection.append(flag); + sampleSection.append("</li>"); + } if (flagHeaderDone) { sampleSection.append("</ul>"); sampleSection.append(EOL); @@ -779,30 +777,29 @@ class HTMLSamplesRenderer extends SamplesRenderer { sink.append("<h2><a name=\"authorIndex\"></a>Author Index</h2>"); List<Sample> list = samples.getSortedSamples(Sample.AUTHOR_NAME_SOURCE_COMPARER); String lastAuthor = null; - for (ListIterator<Sample> iter = list.listIterator(); iter.hasNext();) { - Sample sample = iter.next(); - String author = sample.author; - if (!author.equals(lastAuthor)) { - if (null != lastAuthor) { - sink.append("</li></ul>"); - } - sink.append("<li>"); - sink.append(author); - sink.append(EOL); - sink.append("<ul>"); - sink.append(EOL); - lastAuthor = author; - } - sink.append(" <li><a href=\"#"); - sink.append(sample.anchorName); - sink.append("\">"); - if (null == sample.anchorTitle) { - sink.append(sample.anchorName); - } else { - sink.append(sample.anchorTitle); - } - sink.append("</a></li>"); - } + for (Sample sample : list) { + String author = sample.author; + if (!author.equals(lastAuthor)) { + if (null != lastAuthor) { + sink.append("</li></ul>"); + } + sink.append("<li>"); + sink.append(author); + sink.append(EOL); + sink.append("<ul>"); + sink.append(EOL); + lastAuthor = author; + } + sink.append(" <li><a href=\"#"); + sink.append(sample.anchorName); + sink.append("\">"); + if (null == sample.anchorTitle) { + sink.append(sample.anchorName); + } else { + sink.append(sample.anchorTitle); + } + sink.append("</a></li>"); + } } } @@ -812,11 +809,10 @@ class SampleUtil { public static void simpleRender(Samples result, StringBuffer sink) { List sortedSamples = result.getSortedSamples(); int i = 0; - for (ListIterator iter = sortedSamples.listIterator(); - iter.hasNext();) { - Sample sample = (Sample) iter.next(); - sink.append(i++ + ": " + sample); - } + for (Object sortedSample : sortedSamples) { + Sample sample = (Sample) sortedSample; + sink.append(i++ + ": " + sample); + } } /** result struct for getPackagePath */ diff --git a/build/src/main/java/org/aspectj/internal/tools/build/Util.java b/build/src/main/java/org/aspectj/internal/tools/build/Util.java index 9a1eb9abc..dd393ce45 100644 --- a/build/src/main/java/org/aspectj/internal/tools/build/Util.java +++ b/build/src/main/java/org/aspectj/internal/tools/build/Util.java @@ -193,10 +193,10 @@ public class Util { return false; } else if (dir.isDirectory()) { File[] files = dir.listFiles(); - for (int i = 0; i < files.length; i++) { - if (!deleteContents(files[i]) || !files[i].delete()) { - return false; - } + for (File file : files) { + if (!deleteContents(file) || !file.delete()) { + return false; + } } } return true; @@ -293,26 +293,26 @@ public class Util { if ((hits != expected.length) || (hits != actual.length)) { sb.append("unexpected ["); String prefix = ""; - for (int i = 0; i < actual.length; i++) { - if (null != actual[i]) { - sb.append(prefix); - prefix = ", "; - sb.append("\""); - sb.append(actual[i]); - sb.append("\""); - } - } + for (String value : actual) { + if (null != value) { + sb.append(prefix); + prefix = ", "; + sb.append("\""); + sb.append(value); + sb.append("\""); + } + } sb.append("] missing ["); prefix = ""; - for (int i = 0; i < expected.length; i++) { - if (null != expected[i]) { - sb.append(prefix); - prefix = ", "; - sb.append("\""); - sb.append(expected[i]); - sb.append("\""); - } - } + for (String s : expected) { + if (null != s) { + sb.append(prefix); + prefix = ", "; + sb.append("\""); + sb.append(s); + sb.append("\""); + } + } sb.append("]"); return true; } diff --git a/build/src/test/java/org/aspectj/build/BuildModuleTests.java b/build/src/test/java/org/aspectj/build/BuildModuleTests.java index 7f7550279..042548d3f 100644 --- a/build/src/test/java/org/aspectj/build/BuildModuleTests.java +++ b/build/src/test/java/org/aspectj/build/BuildModuleTests.java @@ -114,8 +114,8 @@ public class BuildModuleTests extends TestCase { public void testLicense_org_eclipse_jdt_core() { final String mod = "org.eclipse.jdt.core"; final String pre = BASE_DIR + mod + File.separator; - for (int i = 0; i < JDT_SOURCE_DIRS.length; i++) { - checkSourceDirectory(new File(pre + JDT_SOURCE_DIRS[i]), mod); + for (String jdtSourceDir : JDT_SOURCE_DIRS) { + checkSourceDirectory(new File(pre + jdtSourceDir), mod); } } @@ -167,10 +167,10 @@ public class BuildModuleTests extends TestCase { void checkLicense(String module) { File moduleDir = new File(Util.path("..", module)); File[] srcDirs = findSourceRoots(moduleDir); - for (int i = 0; i < srcDirs.length; i++) { - System.out.println(srcDirs[i]); - checkSourceDirectory(srcDirs[i], module); - } + for (File srcDir : srcDirs) { + System.out.println(srcDir); + checkSourceDirectory(srcDir, module); + } } void checkSourceDirectory(File srcDir, String module) { @@ -294,17 +294,16 @@ public class BuildModuleTests extends TestCase { } void unknownFiles(File dir, ArrayList<File> results) { File[] files = dir.listFiles(this); - for (int j = 0; j < files.length; j++) { - File file = files[j]; - if (file.isDirectory()) { - String name = file.getName(); - if (!("CVS".equals(name))) { - unknownFiles(file, results); - } - } else { - results.add(file); - } - } + for (File file : files) { + if (file.isDirectory()) { + String name = file.getName(); + if (!("CVS".equals(name))) { + unknownFiles(file, results); + } + } else { + results.add(file); + } + } } } diff --git a/build/src/test/java/org/aspectj/internal/build/BuildModuleTest.java b/build/src/test/java/org/aspectj/internal/build/BuildModuleTest.java index 4a949b447..81600ca94 100644 --- a/build/src/test/java/org/aspectj/internal/build/BuildModuleTest.java +++ b/build/src/test/java/org/aspectj/internal/build/BuildModuleTest.java @@ -106,24 +106,23 @@ public class BuildModuleTest extends TestCase { } protected void deleteTempFiles() { - for (Iterator iter = tempFiles.iterator(); iter.hasNext();) { - File file = (File) iter.next(); - if (!Util.delete(file)) { - File[] list = file.listFiles(); - if (!Util.isEmpty(list)) { - StringBuffer sb = new StringBuffer(); - sb.append("warning: BuildModuleTest unable to delete "); - sb.append(file.toString()); - sb.append("\n"); // XXX platform - for (int i = 0; i < list.length; i++) { - sb.append(" "); - sb.append(list[i].toString()); - sb.append("\n"); // XXX platform - } - System.err.println(sb.toString()); - } - } - } + for (File file : tempFiles) { + if (!Util.delete(file)) { + File[] list = file.listFiles(); + if (!Util.isEmpty(list)) { + StringBuffer sb = new StringBuffer(); + sb.append("warning: BuildModuleTest unable to delete "); + sb.append(file.toString()); + sb.append("\n"); // XXX platform + for (File value : list) { + sb.append(" "); + sb.append(value.toString()); + sb.append("\n"); // XXX platform + } + System.err.println(sb.toString()); + } + } + } } public void testAllJunitTests() { @@ -318,21 +317,21 @@ public class BuildModuleTest extends TestCase { printedMessage = true; } if (debugging()) { - for (int i = 0; i < DEBUGS.length; i++) { - if (target.equals(DEBUGS[i])) { - return true; - } - } + for (String debug : DEBUGS) { + if (target.equals(debug)) { + return true; + } + } return false; } else { - for (int i = 0; i < SKIPS.length; i++) { - if (SKIPS[i].equals(target)) { - if (printInfoMessages) { - System.err.println(target + " skipped build test [" + getClass().getName() + ".shouldBuild(..)]"); - } - return false; - } - } + for (String skip : SKIPS) { + if (skip.equals(target)) { + if (printInfoMessages) { + System.err.println(target + " skipped build test [" + getClass().getName() + ".shouldBuild(..)]"); + } + return false; + } + } } return building; } @@ -419,10 +418,10 @@ public class BuildModuleTest extends TestCase { java.setClasspath(cp); java.setClassname(classname); if (null != args) { - for (int i = 0; i < args.length; i++) { - Argument arg = java.createArg(); - arg.setValue(args[i]); - } + for (String s : args) { + Argument arg = java.createArg(); + arg.setValue(s); + } } try { java.execute(); diff --git a/build/src/test/java/org/aspectj/internal/build/ModulesTest.java b/build/src/test/java/org/aspectj/internal/build/ModulesTest.java index 496cde051..383b3859d 100644 --- a/build/src/test/java/org/aspectj/internal/build/ModulesTest.java +++ b/build/src/test/java/org/aspectj/internal/build/ModulesTest.java @@ -62,12 +62,12 @@ public class ModulesTest extends TestCase { } else { File[] files = file.listFiles(); boolean result = true; - for (int i = 0; i < files.length; i++) { - if (!ModulesTest.delete(files[i]) - && result) { - result = false; - } - } + for (File value : files) { + if (!ModulesTest.delete(value) + && result) { + result = false; + } + } return (file.delete() && result); } } @@ -80,11 +80,10 @@ public class ModulesTest extends TestCase { protected void tearDown() throws Exception { super.tearDown(); - for (Iterator<File> iter = tempFiles.iterator(); iter.hasNext();) { - File file = (File) iter.next(); - if (!ModulesTest.delete(file)) { - System.err.println("warning: ModulesTest unable to delete " + file); - } + for (File file : tempFiles) { + if (!ModulesTest.delete(file)) { + System.err.println("warning: ModulesTest unable to delete " + file); + } } } @@ -270,13 +269,13 @@ public class ModulesTest extends TestCase { File libDir = new File(distDir, "tools/lib"); String[] jars = { "tools", "rt", "weaver", "lib"}; - for (int i = 0; i < jars.length; i++) { - File jar = new File(libDir, "aspectj" + jars[i] + ".jar"); - assertTrue(jar.getPath(), jar.canRead()); - if (10 > jar.length()) { - assertTrue(jar + " too small", false); - } - } + for (String s : jars) { + File jar = new File(libDir, "aspectj" + s + ".jar"); + assertTrue(jar.getPath(), jar.canRead()); + if (10 > jar.length()) { + assertTrue(jar + " too small", false); + } + } } /** * Show messages from the task. diff --git a/build/src/test/java/org/aspectj/internal/tools/build/UtilsTest.java b/build/src/test/java/org/aspectj/internal/tools/build/UtilsTest.java index 4926d42e8..e044afc01 100644 --- a/build/src/test/java/org/aspectj/internal/tools/build/UtilsTest.java +++ b/build/src/test/java/org/aspectj/internal/tools/build/UtilsTest.java @@ -49,21 +49,20 @@ public class UtilsTest extends TestCase { "aspectjrt" }) { void checkOthers(OSGIBundle osgiBundle, StringBuffer sb) { RequiredBundle[] bundles = osgiBundle.getRequiredBundles(); - for (int i = 0; i < bundles.length; i++) { - RequiredBundle bundle = bundles[i]; - if ("aspectjrt".equals(bundle.name)) { - if (!bundle.optional) { - sb - .append("expected required bundle aspectjrt to be optional"); - } - String version = "[1.5.0,1.5.5]"; - if (!(version.equals(bundle.versions))) { - sb.append("expected version " + version - + " got " + bundle.versions - + " for required bundle aspectjrt"); - } - } - } + for (RequiredBundle bundle : bundles) { + if ("aspectjrt".equals(bundle.name)) { + if (!bundle.optional) { + sb + .append("expected required bundle aspectjrt to be optional"); + } + String version = "[1.5.0,1.5.5]"; + if (!(version.equals(bundle.versions))) { + sb.append("expected version " + version + + " got " + bundle.versions + + " for required bundle aspectjrt"); + } + } + } } } }; @@ -140,9 +139,9 @@ public class UtilsTest extends TestCase { /** disabled pending research */ public void skip_testOSGIManifests() throws Exception { StringBuffer sb = new StringBuffer(); - for (int i = 0; i < TESTS.length; i++) { - TESTS[i].run(sb); - } + for (ManifestTest test : TESTS) { + test.run(sb); + } if (0 < sb.length()) { fail(sb.toString()); } |