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 /tests/src/test/java/org/aspectj/systemtest/incremental/tools | |
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 'tests/src/test/java/org/aspectj/systemtest/incremental/tools')
4 files changed, 39 insertions, 54 deletions
diff --git a/tests/src/test/java/org/aspectj/systemtest/incremental/tools/AbstractMultiProjectIncrementalAjdeInteractionTestbed.java b/tests/src/test/java/org/aspectj/systemtest/incremental/tools/AbstractMultiProjectIncrementalAjdeInteractionTestbed.java index 229a22a5d..916801690 100644 --- a/tests/src/test/java/org/aspectj/systemtest/incremental/tools/AbstractMultiProjectIncrementalAjdeInteractionTestbed.java +++ b/tests/src/test/java/org/aspectj/systemtest/incremental/tools/AbstractMultiProjectIncrementalAjdeInteractionTestbed.java @@ -65,8 +65,8 @@ public class AbstractMultiProjectIncrementalAjdeInteractionTestbed extends AjdeI // System.out.println("kvp: " + object + " = " + m.get(object)); // } // } - for (Iterator<IProgramElement> i = node.getChildren().iterator(); i.hasNext();) { - dumptree( i.next(), indent + 2); + for (IProgramElement iProgramElement : node.getChildren()) { + dumptree(iProgramElement, indent + 2); } } } @@ -113,11 +113,10 @@ public class AbstractMultiProjectIncrementalAjdeInteractionTestbed extends AjdeI IRelationshipMap relmap = getModelFor(project).getRelationshipMap(); int ctr = 0; Set<String> entries = relmap.getEntries(); - for (Iterator<String> iter = entries.iterator(); iter.hasNext();) { - String hid = (String) iter.next(); + for (String hid : entries) { List<IRelationship> rels = relmap.get(hid); - for (Iterator<IRelationship> iterator = rels.iterator(); iterator.hasNext();) { - ctr+=iterator.next().getTargets().size(); + for (IRelationship rel : rels) { + ctr += rel.getTargets().size(); } } return ctr; @@ -152,8 +151,7 @@ public class AbstractMultiProjectIncrementalAjdeInteractionTestbed extends AjdeI String contents[] = location.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(location, string); if (f.isDirectory()) { collectUpFiles(f, base, collectionPoint); @@ -206,8 +204,7 @@ public class AbstractMultiProjectIncrementalAjdeInteractionTestbed extends AjdeI 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); diff --git a/tests/src/test/java/org/aspectj/systemtest/incremental/tools/AjdeInteractionTestbed.java b/tests/src/test/java/org/aspectj/systemtest/incremental/tools/AjdeInteractionTestbed.java index 0fe276f46..9c5770ef8 100644 --- a/tests/src/test/java/org/aspectj/systemtest/incremental/tools/AjdeInteractionTestbed.java +++ b/tests/src/test/java/org/aspectj/systemtest/incremental/tools/AjdeInteractionTestbed.java @@ -244,13 +244,13 @@ public class AjdeInteractionTestbed extends TestCase { List<String> filesForCompilation = new ArrayList<String>(); collectUpFiles(projectBase, projectBase, filesForCompilation); boolean changed = false; - for (int i = 0; i < filesForCompilation.size(); i++) { - if (!currentFiles.contains(filesForCompilation.get(i))) { + for (String s : filesForCompilation) { + if (!currentFiles.contains(s)) { changed = true; } } - for (int i = 0; i < currentFiles.size(); i++) { - if (!filesForCompilation.contains(currentFiles.get(i))) { + for (String currentFile : currentFiles) { + if (!filesForCompilation.contains(currentFile)) { changed = true; } } @@ -266,13 +266,13 @@ public class AjdeInteractionTestbed extends TestCase { List<String> collector = new ArrayList<String>(); collectUpXmlFiles(projectBase, projectBase, collector); boolean changed = false; - for (int i = 0; i < collector.size(); i++) { - if (!currentXmlFiles.contains(collector.get(i))) { + for (String s : collector) { + if (!currentXmlFiles.contains(s)) { changed = true; } } - for (int i = 0; i < currentXmlFiles.size(); i++) { - if (!collector.contains(currentXmlFiles.get(i))) { + for (String currentXmlFile : currentXmlFiles) { + if (!collector.contains(currentXmlFile)) { changed = true; } } @@ -286,8 +286,7 @@ public class AjdeInteractionTestbed extends TestCase { if (contents == null) { return; } - for (int i = 0; i < contents.length; i++) { - String string = contents[i]; + for (String string : contents) { File f = new File(location, string); if (f.isDirectory()) { collectUpFiles(f, base, collectionPoint); @@ -311,8 +310,7 @@ public class AjdeInteractionTestbed extends TestCase { if (contents == null) { return; } - for (int i = 0; i < contents.length; i++) { - String string = contents[i]; + for (String string : contents) { File f = new File(location, string); if (f.isDirectory()) { collectUpXmlFiles(f, base, collectionPoint); @@ -365,8 +363,7 @@ public class AjdeInteractionTestbed extends TestCase { public void checkForError(String projectName, String anError) { AjCompiler compiler = CompilerFactory.getCompilerForProjectWithDir(sandboxDir + File.separator + projectName); List<IMessage> messages = ((MultiProjTestMessageHandler) compiler.getMessageHandler()).getErrorMessages(); - for (Iterator<IMessage> iter = messages.iterator(); iter.hasNext();) { - IMessage element = iter.next(); + for (IMessage element : messages) { if (element.getMessage().indexOf(anError) != -1) { return; } @@ -409,13 +406,13 @@ public class AjdeInteractionTestbed extends TestCase { System.out.println("Build took: " + getTimeTakenForBuild(projectName) + "ms"); List<String> compiled = getCompiledFiles(projectName); System.out.println("Compiled: " + compiled.size() + " files"); - for (Iterator<String> iter = compiled.iterator(); iter.hasNext();) { - System.out.println(" :" + iter.next()); + for (String value : compiled) { + System.out.println(" :" + value); } List<String> woven = getWovenClasses(projectName); System.out.println("Wove: " + woven.size() + " files"); - for (Iterator<String> iter = woven.iterator(); iter.hasNext();) { - System.out.println(" :" + iter.next()); + for (String s : woven) { + System.out.println(" :" + s); } if (wasFullBuild()) { System.out.println("It was a batch (full) build"); diff --git a/tests/src/test/java/org/aspectj/systemtest/incremental/tools/MoreOutputLocationManagerTests.java b/tests/src/test/java/org/aspectj/systemtest/incremental/tools/MoreOutputLocationManagerTests.java index c35b88610..538d2dcbd 100644 --- a/tests/src/test/java/org/aspectj/systemtest/incremental/tools/MoreOutputLocationManagerTests.java +++ b/tests/src/test/java/org/aspectj/systemtest/incremental/tools/MoreOutputLocationManagerTests.java @@ -68,8 +68,7 @@ public class MoreOutputLocationManagerTests extends AbstractMultiProjectIncremen Map<String,File> classNameToFileMap = state.getClassNameToFileMap(); assertFalse("expected there to be classes ", classNameToFileMap.isEmpty()); Set<Map.Entry<String,File>> entrySet = classNameToFileMap.entrySet(); - for (Iterator<Map.Entry<String,File>> iterator = entrySet.iterator(); iterator.hasNext();) { - Map.Entry<String,File> entry = iterator.next(); + for (Map.Entry<String, File> entry : entrySet) { String className = entry.getKey(); String fullClassName = expectedOutputDir + File.separator + className.replace('.', File.separatorChar) + ".class"; File file = entry.getValue(); diff --git a/tests/src/test/java/org/aspectj/systemtest/incremental/tools/MultiProjectIncrementalTests.java b/tests/src/test/java/org/aspectj/systemtest/incremental/tools/MultiProjectIncrementalTests.java index 0d01d9634..75600dded 100644 --- a/tests/src/test/java/org/aspectj/systemtest/incremental/tools/MultiProjectIncrementalTests.java +++ b/tests/src/test/java/org/aspectj/systemtest/incremental/tools/MultiProjectIncrementalTests.java @@ -921,8 +921,7 @@ public class MultiProjectIncrementalTests extends AbstractMultiProjectIncrementa checkWasFullBuild(); List<IMessage> weaveMessages = getWeavingMessages(p); if (weaveMessages.size() != 1) { - for (Iterator<IMessage> iterator = weaveMessages.iterator(); iterator.hasNext();) { - Object object = iterator.next(); + for (Object object : weaveMessages) { System.out.println(object); } fail("Expected just one weave message. The aop.xml should have limited the weaving"); @@ -939,8 +938,7 @@ public class MultiProjectIncrementalTests extends AbstractMultiProjectIncrementa assertNotNull(ps); assertEquals(2, ps.size()); int count = 0; - for (Iterator<String> iterator = ps.iterator(); iterator.hasNext();) { - String type = iterator.next(); + for (String type : ps) { if (type.equals("java.io.Serializable")) { count++; } @@ -997,14 +995,13 @@ public class MultiProjectIncrementalTests extends AbstractMultiProjectIncrementa IRelationshipMap asmRelMap = getModelFor("P4").getRelationshipMap(); assertEquals("There should be two relationships in the relationship map", 2, asmRelMap.getEntries().size()); - for (Iterator<String> iter = asmRelMap.getEntries().iterator(); iter.hasNext();) { - String sourceOfRelationship = (String) iter.next(); + for (String sourceOfRelationship : asmRelMap.getEntries()) { IProgramElement ipe = getModelFor("P4").getHierarchy().findElementForHandle(sourceOfRelationship); assertNotNull("expected to find IProgramElement with handle " + sourceOfRelationship + " but didn't", ipe); - if (ipe.getKind().equals(IProgramElement.Kind.ADVICE)) { + if (ipe.getKind().equals(Kind.ADVICE)) { assertEquals("expected source of relationship to be " + advice.toString() + " but found " + ipe.toString(), advice, ipe); - } else if (ipe.getKind().equals(IProgramElement.Kind.CODE)) { + } else if (ipe.getKind().equals(Kind.CODE)) { assertEquals( "expected source of relationship to be " + codeElement.toString() + " but found " + ipe.toString(), codeElement, ipe); @@ -1014,17 +1011,16 @@ public class MultiProjectIncrementalTests extends AbstractMultiProjectIncrementa } List<IRelationship> relationships = asmRelMap.get(ipe); assertNotNull("expected " + ipe.getName() + " to have some " + "relationships", relationships); - for (Iterator<IRelationship> iterator = relationships.iterator(); iterator.hasNext();) { - Relationship rel = (Relationship) iterator.next(); + for (IRelationship relationship : relationships) { + Relationship rel = (Relationship) relationship; List<String> targets = rel.getTargets(); - for (Iterator<String> iterator2 = targets.iterator(); iterator2.hasNext();) { - String t = (String) iterator2.next(); + for (String t : targets) { IProgramElement link = getModelFor("P4").getHierarchy().findElementForHandle(t); - if (ipe.getKind().equals(IProgramElement.Kind.ADVICE)) { + if (ipe.getKind().equals(Kind.ADVICE)) { assertEquals( "expected target of relationship to be " + codeElement.toString() + " but found " + link.toString(), codeElement, link); - } else if (ipe.getKind().equals(IProgramElement.Kind.CODE)) { + } else if (ipe.getKind().equals(Kind.CODE)) { assertEquals( "expected target of relationship to be " + advice.toString() + " but found " + link.toString(), advice, link); @@ -1102,21 +1098,18 @@ public class MultiProjectIncrementalTests extends AbstractMultiProjectIncrementa IProgramElement root = model.getHierarchy().getRoot(); ProgramElement theITD = (ProgramElement) findElementAtLine(root, 7); Map<String, Object> m = theITD.kvpairs; - for (Iterator<String> iterator = m.keySet().iterator(); iterator.hasNext();) { - String type = iterator.next(); + for (String type : m.keySet()) { System.out.println(type + " = " + m.get(type)); } // return type of the ITD assertEquals("a.b.c.B", theITD.getCorrespondingType(true)); List<char[]> ptypes = theITD.getParameterTypes(); - for (Iterator<char[]> iterator = ptypes.iterator(); iterator.hasNext();) { - char[] object = iterator.next(); + for (char[] object : ptypes) { System.out.println("p = " + new String(object)); } ProgramElement decp = (ProgramElement) findElementAtLine(root, 8); m = decp.kvpairs; - for (Iterator<String> iterator = m.keySet().iterator(); iterator.hasNext();) { - String type = iterator.next(); + for (String type : m.keySet()) { System.out.println(type + " = " + m.get(type)); } List<String> l = decp.getParentTypes(); @@ -1723,8 +1716,8 @@ public class MultiProjectIncrementalTests extends AbstractMultiProjectIncrementa } List<IProgramElement> kids = start.getChildren(); if (kids != null) { - for (int i = 0; i < kids.size(); i++) { - IProgramElement found = getChild((IProgramElement) kids.get(i), name); + for (IProgramElement kid : kids) { + IProgramElement found = getChild((IProgramElement) kid, name); if (found != null) { return found; } @@ -3939,8 +3932,7 @@ public class MultiProjectIncrementalTests extends AbstractMultiProjectIncrementa if (rels == null) { fail("Did not find any related elements!"); } - for (Iterator<IRelationship> iter = rels.iterator(); iter.hasNext();) { - IRelationship element = iter.next(); + for (IRelationship element : rels) { List<String> targets = element.getTargets(); if (output == null) { output = new ArrayList<String>(); |