aboutsummaryrefslogtreecommitdiffstats
path: root/ajdoc
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 /ajdoc
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 'ajdoc')
-rw-r--r--ajdoc/src/main/java/org/aspectj/tools/ajdoc/HtmlDecorator.java24
-rw-r--r--ajdoc/src/main/java/org/aspectj/tools/ajdoc/Main.java32
-rw-r--r--ajdoc/src/main/java/org/aspectj/tools/ajdoc/StructureUtil.java15
-rw-r--r--ajdoc/src/main/java/org/aspectj/tools/ajdoc/StubFileGenerator.java11
-rw-r--r--ajdoc/src/test/java/org/aspectj/tools/ajdoc/AjdocOutputChecker.java8
-rw-r--r--ajdoc/src/test/java/org/aspectj/tools/ajdoc/AjdocTestCase.java13
6 files changed, 47 insertions, 56 deletions
diff --git a/ajdoc/src/main/java/org/aspectj/tools/ajdoc/HtmlDecorator.java b/ajdoc/src/main/java/org/aspectj/tools/ajdoc/HtmlDecorator.java
index 7dd50b4ef..35e84ca5a 100644
--- a/ajdoc/src/main/java/org/aspectj/tools/ajdoc/HtmlDecorator.java
+++ b/ajdoc/src/main/java/org/aspectj/tools/ajdoc/HtmlDecorator.java
@@ -58,8 +58,8 @@ class HtmlDecorator {
rootDir = newRootDir;
declIDTable = table;
docVisibilityModifier = docModifier;
- for (int i = 0; i < inputFiles.length; i++) {
- decorateHTMLFromIPEs(getProgramElements(model, inputFiles[i].getCanonicalPath()), rootDir.getCanonicalPath()
+ for (File inputFile : inputFiles) {
+ decorateHTMLFromIPEs(getProgramElements(model, inputFile.getCanonicalPath()), rootDir.getCanonicalPath()
+ Config.DIR_SEP_CHAR, docModifier, false);
}
}
@@ -67,8 +67,7 @@ class HtmlDecorator {
static void decorateHTMLFromIPEs(IProgramElement[] decls, String base, String docModifier, boolean exceededNestingLevel)
throws IOException {
if (decls != null) {
- for (int i = 0; i < decls.length; i++) {
- IProgramElement decl = decls[i];
+ for (IProgramElement decl : decls) {
decorateHTMLFromIPE(decl, base, docModifier, exceededNestingLevel);
}
}
@@ -311,8 +310,7 @@ class HtmlDecorator {
if (fieldsDeclaredOn != null && !constDeclaredOn.isEmpty()) {
insertDeclarationsSummary(fileBuffer, constDeclaredOn, ITD_CONSTRUCTOR_SUMMARY, index);
}
- for (Iterator<IProgramElement> it = node.getChildren().iterator(); it.hasNext();) {
- IProgramElement member = it.next();
+ for (IProgramElement member : node.getChildren()) {
if (member.getKind().equals(IProgramElement.Kind.POINTCUT)) {
pointcuts.add(member);
} else if (member.getKind().equals(IProgramElement.Kind.ADVICE)) {
@@ -365,8 +363,8 @@ class HtmlDecorator {
insertIndex += tableHead.length();
// insert the body of the table
- for (int i = 0; i < decls.size(); i++) {
- IProgramElement decl = (IProgramElement) decls.get(i);
+ for (Object o : decls) {
+ IProgramElement decl = (IProgramElement) o;
if (isAboveVisibility(decl)) {
// insert the table row accordingly
String comment = generateSummaryComment(decl);
@@ -413,8 +411,8 @@ class HtmlDecorator {
private static boolean declsAboveVisibilityExist(List decls) {
boolean exist = false;
- for (Iterator it = decls.iterator(); it.hasNext();) {
- IProgramElement element = (IProgramElement) it.next();
+ for (Object decl : decls) {
+ IProgramElement element = (IProgramElement) decl;
if (isAboveVisibility(element))
exist = true;
}
@@ -810,11 +808,11 @@ class HtmlDecorator {
static String generateHREFName(IProgramElement decl) {
StringBuffer hrefLinkBuffer = new StringBuffer();
char[] declChars = decl.toLabelString().toCharArray();
- for (int i = 0; i < declChars.length; i++) {
- if (declChars[i] == '"') {
+ for (char declChar : declChars) {
+ if (declChar == '"') {
hrefLinkBuffer.append("quot;");
} else {
- hrefLinkBuffer.append(declChars[i]);
+ hrefLinkBuffer.append(declChar);
}
}
return hrefLinkBuffer.toString();
diff --git a/ajdoc/src/main/java/org/aspectj/tools/ajdoc/Main.java b/ajdoc/src/main/java/org/aspectj/tools/ajdoc/Main.java
index e4cf8be44..0f01a058f 100644
--- a/ajdoc/src/main/java/org/aspectj/tools/ajdoc/Main.java
+++ b/ajdoc/src/main/java/org/aspectj/tools/ajdoc/Main.java
@@ -171,14 +171,14 @@ public class Main implements Config {
*/
private static void packageHTML(AsmManager model, File[] inputFiles) throws IOException {
ArrayList<String> dirList = new ArrayList<String>();
- for (int i = 0; i < inputFiles.length; i++) {
- String packageName = StructureUtil.getPackageDeclarationFromFile(model, inputFiles[i]);
+ for (File inputFile : inputFiles) {
+ String packageName = StructureUtil.getPackageDeclarationFromFile(model, inputFile);
// Only copy the package.html file once.
if (dirList.contains(packageName))
continue;
// Check to see if there exist a package.html file for this package.
- String dir = inputFiles[i].getAbsolutePath().substring(0, inputFiles[i].getAbsolutePath().lastIndexOf(File.separator));
+ String dir = inputFile.getAbsolutePath().substring(0, inputFile.getAbsolutePath().lastIndexOf(File.separator));
File input = new File(dir + Config.DIR_SEP_CHAR + "package.html");
File inDir = new File(dir + Config.DIR_SEP_CHAR + "doc-files");
// If it does not exist lets go to the next package.
@@ -226,8 +226,8 @@ public class Main implements Config {
for (; i < ajcOptions.size(); i++) {
argsToCompiler[i] = ajcOptions.elementAt(i);
}
- for (int j = 0; j < inputFiles.length; j++) {
- argsToCompiler[i] = inputFiles[j].getAbsolutePath();
+ for (File inputFile : inputFiles) {
+ argsToCompiler[i] = inputFile.getAbsolutePath();
// System.out.println(">> file to ajc: " + inputFiles[j].getAbsolutePath());
i++;
}
@@ -281,8 +281,8 @@ public class Main implements Config {
for (int k = 0; k < signatureFiles.length; k++) {
javadocargs[options.size() + k] = StructureUtil.translateAjPathName(signatureFiles[k].getCanonicalPath());
}
- for (int k = 0; k < signatureFiles.length; k++) {
- files.add(StructureUtil.translateAjPathName(signatureFiles[k].getCanonicalPath()));
+ for (File signatureFile : signatureFiles) {
+ files.add(StructureUtil.translateAjPathName(signatureFile.getCanonicalPath()));
}
}
if (LangUtil.is19VMOrGreater()) {
@@ -321,8 +321,8 @@ public class Main implements Config {
return f.getName().equals("package-summary.html");
}
});
- for (int j = 0; j < files.length; j++) {
- removeDeclIDsFromFile(files[j].getAbsolutePath(), false);
+ for (File file : files) {
+ removeDeclIDsFromFile(file.getAbsolutePath(), false);
}
}
}
@@ -478,8 +478,8 @@ public class Main implements Config {
// System.err.println(argList);
args = new String[argList.size()];
int counter = 0;
- for (Iterator<String> it = argList.iterator(); it.hasNext();) {
- args[counter] = it.next();
+ for (String s : argList) {
+ args[counter] = s;
counter++;
}
} catch (FileNotFoundException e) {
@@ -530,8 +530,8 @@ public class Main implements Config {
if (vargs.size() == 0) {
displayHelpAndExit(null);
}
- for (int i = 0; i < vargs.size(); i++) {
- String arg = (String) vargs.get(i);
+ for (Object varg : vargs) {
+ String arg = (String) varg;
ignoreArg = false;
if (addNextAsDocDir) {
docDir = arg;
@@ -694,16 +694,16 @@ public class Main implements Config {
int index2 = name.length();
if ((index1 >= 0 && index2 >= 0)
&& (name.substring(index1, index2).equals(".java") || name.substring(index1, index2)
- .equals(".aj"))) {
+ .equals(".aj"))) {
return true;
} else {
return false;
}
}
});
- for (int j = 0; j < files.length; j++) {
+ for (String file : files) {
filenames.addElement(sourcepath.elementAt(c) + Config.DIR_SEP_CHAR + arg
- + Config.DIR_SEP_CHAR + files[j]);
+ + Config.DIR_SEP_CHAR + file);
}
} else if (c == sourcepath.size()) { // last element on classpath
System.out.println("ajdoc: No package, class, or source file " + "found named " + arg + ".");
diff --git a/ajdoc/src/main/java/org/aspectj/tools/ajdoc/StructureUtil.java b/ajdoc/src/main/java/org/aspectj/tools/ajdoc/StructureUtil.java
index 3d866b625..2fdd95698 100644
--- a/ajdoc/src/main/java/org/aspectj/tools/ajdoc/StructureUtil.java
+++ b/ajdoc/src/main/java/org/aspectj/tools/ajdoc/StructureUtil.java
@@ -47,16 +47,14 @@ public class StructureUtil {
if (rels != null) {
relations.addAll(rels);
}
- for (Iterator<IProgramElement> iter = node.getChildren().iterator(); iter.hasNext();) {
- IProgramElement child = (IProgramElement) iter.next();
+ for (IProgramElement child : node.getChildren()) {
// if we're not a type, or if we are and the child is code, then
// we want to get the relationships for this child - this means that the
// correct relationships appear against the type in the ajdoc
if (!node.getKind().isType() || child.getKind().equals(IProgramElement.Kind.CODE)) {
List<IRelationship> childRelations = node.getModel().getRelationshipMap().get(child);
if (childRelations != null) {
- for (Iterator<IRelationship> iterator = childRelations.iterator(); iterator.hasNext();) {
- IRelationship rel = (IRelationship) iterator.next();
+ for (IRelationship rel : childRelations) {
if (!relations.contains(rel)) {
relations.add(rel);
}
@@ -67,11 +65,10 @@ public class StructureUtil {
if (relations == null || relations.isEmpty())
return null;
List<String> targets = new ArrayList<String>();
- for (Iterator<IRelationship> it = relations.iterator(); it.hasNext();) {
- IRelationship rtn = (IRelationship) it.next();
+ for (IRelationship rtn : relations) {
if (rtn.getKind().equals(kind) && ((relName != null && relName.equals(rtn.getName())) || relName == null)) {
List<String> targs = rtn.getTargets();
- for (String element: targs) {
+ for (String element : targs) {
if (!targets.contains(element)) {
targets.add(element);
}
@@ -125,8 +122,8 @@ public class StructureUtil {
}
String modifiers = "";
- for (Iterator modIt = node.getModifiers().iterator(); modIt.hasNext();) {
- modifiers += modIt.next() + " ";
+ for (IProgramElement.Modifiers value : node.getModifiers()) {
+ modifiers += value + " ";
}
if (node.getKind().equals(IProgramElement.Kind.METHOD) || node.getKind().equals(IProgramElement.Kind.FIELD)) {
diff --git a/ajdoc/src/main/java/org/aspectj/tools/ajdoc/StubFileGenerator.java b/ajdoc/src/main/java/org/aspectj/tools/ajdoc/StubFileGenerator.java
index 6b5c816f7..cd8a01e26 100644
--- a/ajdoc/src/main/java/org/aspectj/tools/ajdoc/StubFileGenerator.java
+++ b/ajdoc/src/main/java/org/aspectj/tools/ajdoc/StubFileGenerator.java
@@ -59,8 +59,7 @@ class StubFileGenerator {
}
IProgramElement fileNode = model.getHierarchy().findElementForSourceFile(inputFile.getAbsolutePath());
- for (Iterator it = fileNode.getChildren().iterator(); it.hasNext();) {
- IProgramElement node = (IProgramElement) it.next();
+ for (IProgramElement node : fileNode.getChildren()) {
if (node.getKind().isPackageDeclaration()) {
// skip
} else if (node.getKind().equals(IProgramElement.Kind.IMPORT_REFERENCE)) {
@@ -84,8 +83,8 @@ class StubFileGenerator {
private static void processImportDeclaration(IProgramElement node, PrintWriter writer) throws IOException {
List imports = node.getChildren();
- for (Iterator i = imports.iterator(); i.hasNext();) {
- IProgramElement importNode = (IProgramElement) i.next();
+ for (Object anImport : imports) {
+ IProgramElement importNode = (IProgramElement) anImport;
writer.println(importNode.getSourceSignature());
}
}
@@ -111,8 +110,8 @@ class StubFileGenerator {
private static void processMembers(List/* IProgramElement */members, PrintWriter writer, boolean declaringTypeIsInterface)
throws DocException {
- for (Iterator it = members.iterator(); it.hasNext();) {
- IProgramElement member = (IProgramElement) it.next();
+ for (Object o : members) {
+ IProgramElement member = (IProgramElement) o;
if (member.getKind().isType()) {
if (!member.getParent().getKind().equals(IProgramElement.Kind.METHOD) && !StructureUtil.isAnonymous(member)) {// don't
diff --git a/ajdoc/src/test/java/org/aspectj/tools/ajdoc/AjdocOutputChecker.java b/ajdoc/src/test/java/org/aspectj/tools/ajdoc/AjdocOutputChecker.java
index 2100f7dba..b22d1250d 100644
--- a/ajdoc/src/test/java/org/aspectj/tools/ajdoc/AjdocOutputChecker.java
+++ b/ajdoc/src/test/java/org/aspectj/tools/ajdoc/AjdocOutputChecker.java
@@ -61,8 +61,7 @@ public class AjdocOutputChecker {
*/
public static List<String> getMissingStringsInFile(File htmlFile, String[] requiredStrings) throws Exception {
List<String> missingStrings = new ArrayList<String>();
- for (int i = 0; i < requiredStrings.length; i++) {
- String string = requiredStrings[i];
+ for (String string : requiredStrings) {
if (!containsString(htmlFile, string)) {
missingStrings.add(string);
}
@@ -122,9 +121,8 @@ public class AjdocOutputChecker {
public static List<String> getMissingStringsInSection(File htmlFile,
String[] requiredStrings, String sectionHeader) throws Exception {
List<String> missingStrings = new ArrayList<String>();
- for (int i = 0; i < requiredStrings.length; i++) {
- String string = requiredStrings[i];
- if (!containsStringWithinSection(htmlFile,string,sectionHeader)) {
+ for (String string : requiredStrings) {
+ if (!containsStringWithinSection(htmlFile, string, sectionHeader)) {
missingStrings.add(string);
}
}
diff --git a/ajdoc/src/test/java/org/aspectj/tools/ajdoc/AjdocTestCase.java b/ajdoc/src/test/java/org/aspectj/tools/ajdoc/AjdocTestCase.java
index 26dda1187..6dfd5633f 100644
--- a/ajdoc/src/test/java/org/aspectj/tools/ajdoc/AjdocTestCase.java
+++ b/ajdoc/src/test/java/org/aspectj/tools/ajdoc/AjdocTestCase.java
@@ -97,8 +97,7 @@ public abstract class AjdocTestCase 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);
@@ -209,9 +208,9 @@ public abstract class AjdocTestCase extends TestCase {
if (inputFiles.length == 0) {
fail("need to pass some files into ajdoc");
}
- for (int i = 0; i < inputFiles.length; i++) {
- if (!inputFiles[i].exists()) {
- fail(inputFiles[i].getAbsolutePath() + " does not exist");
+ for (File inputFile : inputFiles) {
+ if (!inputFile.exists()) {
+ fail(inputFile.getAbsolutePath() + " does not exist");
}
}
@@ -305,8 +304,8 @@ public abstract class AjdocTestCase extends TestCase {
public void runAjdoc(List options) {
String[] args = new String[options.size()];
int i = 0;
- for (Iterator iter = options.iterator(); iter.hasNext();) {
- String element = (String) iter.next();
+ for (Object option : options) {
+ String element = (String) option;
args[i] = element;
i++;
}