diff options
author | Lars Grefer <eclipse@larsgrefer.de> | 2020-08-08 03:09:01 +0200 |
---|---|---|
committer | Lars Grefer <eclipse@larsgrefer.de> | 2020-08-08 03:09:01 +0200 |
commit | a508fd5315c6330f2057c219aebc35b15d0ea497 (patch) | |
tree | c0ec3cef4e3411f22e5124ae36eba542a35a495a /org.aspectj.ajdt.core | |
parent | 72194b7982ddfa8e9864d0a9934905bb76b90f33 (diff) | |
download | aspectj-a508fd5315c6330f2057c219aebc35b15d0ea497.tar.gz aspectj-a508fd5315c6330f2057c219aebc35b15d0ea497.zip |
'while' loop replaceable with enhanced 'for' loop
Reports while loops which iterate over collections, and can be replaced with an enhanced for loop (i.e. foreach iteration syntax).
Signed-off-by: Lars Grefer <eclipse@larsgrefer.de>
Diffstat (limited to 'org.aspectj.ajdt.core')
-rw-r--r-- | org.aspectj.ajdt.core/src/main/java/org/aspectj/org/eclipse/jdt/core/dom/AjASTConverter.java | 42 |
1 files changed, 19 insertions, 23 deletions
diff --git a/org.aspectj.ajdt.core/src/main/java/org/aspectj/org/eclipse/jdt/core/dom/AjASTConverter.java b/org.aspectj.ajdt.core/src/main/java/org/aspectj/org/eclipse/jdt/core/dom/AjASTConverter.java index 57602a440..32794ef44 100644 --- a/org.aspectj.ajdt.core/src/main/java/org/aspectj/org/eclipse/jdt/core/dom/AjASTConverter.java +++ b/org.aspectj.ajdt.core/src/main/java/org/aspectj/org/eclipse/jdt/core/dom/AjASTConverter.java @@ -1993,9 +1993,8 @@ public class AjASTConverter extends ASTConverter { if (this.resolveBindings) { recordNodes(docComment, javadoc); // resolve member and method references binding - Iterator tags = docComment.tags().listIterator(); - while (tags.hasNext()) { - recordNodes(javadoc, (TagElement) tags.next()); + for (Object o : docComment.tags()) { + recordNodes(javadoc, (TagElement) o); } } bodyDeclaration.setJavadoc(docComment); @@ -2016,9 +2015,8 @@ public class AjASTConverter extends ASTConverter { if (this.resolveBindings) { recordNodes(docComment, javadoc); // resolve member and method references binding - Iterator tags = docComment.tags().listIterator(); - while (tags.hasNext()) { - recordNodes(javadoc, (TagElement) tags.next()); + for (Object o : docComment.tags()) { + recordNodes(javadoc, (TagElement) o); } } packageDeclaration.setJavadoc(docComment); @@ -3389,9 +3387,8 @@ public class AjASTConverter extends ASTConverter { } protected void recordNodes(org.aspectj.org.eclipse.jdt.internal.compiler.ast.Javadoc javadoc, TagElement tagElement) { - Iterator fragments = tagElement.fragments().listIterator(); - while (fragments.hasNext()) { - ASTNode node = (ASTNode) fragments.next(); + for (Object value : tagElement.fragments()) { + ASTNode node = (ASTNode) value; if (node.getNodeType() == ASTNode.MEMBER_REF) { MemberRef memberRef = (MemberRef) node; Name name = memberRef.getName(); @@ -3404,16 +3401,16 @@ public class AjASTConverter extends ASTConverter { } // Replace qualifier to have all nodes recorded if (memberRef.getQualifier() != null) { - org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeReference typeRef = null; + TypeReference typeRef = null; if (compilerNode instanceof JavadocFieldReference) { org.aspectj.org.eclipse.jdt.internal.compiler.ast.Expression expression = ((JavadocFieldReference) compilerNode).receiver; - if (expression instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeReference) { - typeRef = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeReference) expression; + if (expression instanceof TypeReference) { + typeRef = (TypeReference) expression; } } else if (compilerNode instanceof JavadocMessageSend) { org.aspectj.org.eclipse.jdt.internal.compiler.ast.Expression expression = ((JavadocMessageSend) compilerNode).receiver; - if (expression instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeReference) { - typeRef = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeReference) expression; + if (expression instanceof TypeReference) { + typeRef = (TypeReference) expression; } } if (typeRef != null) { @@ -3431,16 +3428,16 @@ public class AjASTConverter extends ASTConverter { if (compilerNode != null) { recordNodes(methodRef, compilerNode); // get type ref - org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeReference typeRef = null; + TypeReference typeRef = null; if (compilerNode instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.JavadocAllocationExpression) { typeRef = ((org.aspectj.org.eclipse.jdt.internal.compiler.ast.JavadocAllocationExpression) compilerNode).type; if (typeRef != null) { recordNodes(name, compilerNode); } - } else if (compilerNode instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.JavadocMessageSend) { - org.aspectj.org.eclipse.jdt.internal.compiler.ast.Expression expression = ((org.aspectj.org.eclipse.jdt.internal.compiler.ast.JavadocMessageSend) compilerNode).receiver; - if (expression instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeReference) { - typeRef = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeReference) expression; + } else if (compilerNode instanceof JavadocMessageSend) { + org.aspectj.org.eclipse.jdt.internal.compiler.ast.Expression expression = ((JavadocMessageSend) compilerNode).receiver; + if (expression instanceof TypeReference) { + typeRef = (TypeReference) expression; } // TODO (frederic) remove following line to fix bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=62650 recordNodes(name, compilerNode); @@ -3451,16 +3448,15 @@ public class AjASTConverter extends ASTConverter { } } // Resolve parameters - Iterator parameters = methodRef.parameters().listIterator(); - while (parameters.hasNext()) { - MethodRefParameter param = (MethodRefParameter) parameters.next(); + for (Object o : methodRef.parameters()) { + MethodRefParameter param = (MethodRefParameter) o; org.aspectj.org.eclipse.jdt.internal.compiler.ast.Expression expression = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.Expression) javadoc .getNodeStartingAt(param.getStartPosition()); if (expression != null) { recordNodes(param, expression); if (expression instanceof JavadocArgumentExpression) { JavadocArgumentExpression argExpr = (JavadocArgumentExpression) expression; - org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeReference typeRef = argExpr.argument.type; + TypeReference typeRef = argExpr.argument.type; if (this.ast.apiLevel >= AST.JLS3) { param.setVarargs(argExpr.argument.isVarArgs()); } |