aboutsummaryrefslogtreecommitdiffstats
path: root/asm
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 /asm
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 'asm')
-rw-r--r--asm/src/main/java/org/aspectj/asm/AsmManager.java25
-rw-r--r--asm/src/main/java/org/aspectj/asm/IProgramElement.java10
-rw-r--r--asm/src/main/java/org/aspectj/asm/IRelationship.java6
-rw-r--r--asm/src/main/java/org/aspectj/asm/internal/JDTLikeHandleProvider.java6
-rw-r--r--asm/src/main/java/org/aspectj/asm/internal/ProgramElement.java7
-rw-r--r--asm/src/main/java/org/aspectj/asm/internal/RelationshipMap.java3
6 files changed, 24 insertions, 33 deletions
diff --git a/asm/src/main/java/org/aspectj/asm/AsmManager.java b/asm/src/main/java/org/aspectj/asm/AsmManager.java
index 2ab34c862..6972dda3a 100644
--- a/asm/src/main/java/org/aspectj/asm/AsmManager.java
+++ b/asm/src/main/java/org/aspectj/asm/AsmManager.java
@@ -157,8 +157,7 @@ public class AsmManager implements IStructureModel {
IProgramElement fileNode = node;
ArrayList<IProgramElement> peNodes = new ArrayList<IProgramElement>();
getAllStructureChildren(fileNode, peNodes, showSubMember, showMemberAndType);
- for (Iterator<IProgramElement> it = peNodes.iterator(); it.hasNext();) {
- IProgramElement peNode = it.next();
+ for (IProgramElement peNode : peNodes) {
List<IProgramElement> entries = new ArrayList<IProgramElement>();
entries.add(peNode);
ISourceLocation sourceLoc = peNode.getSourceLocation();
@@ -733,8 +732,8 @@ public class AsmManager implements IStructureModel {
if (relationshipsToRemove.size() == relationships.size()) {
sourcesToRemove.add(hid);
} else {
- for (int i = 0; i < relationshipsToRemove.size(); i++) {
- relationships.remove(relationshipsToRemove.get(i));
+ for (IRelationship iRelationship : relationshipsToRemove) {
+ relationships.remove(iRelationship);
}
}
}
@@ -815,8 +814,8 @@ public class AsmManager implements IStructureModel {
if (relationshipsToRemove.size() == relationships.size()) {
sourcesToRemove.add(hid);
} else {
- for (int i = 0; i < relationshipsToRemove.size(); i++) {
- relationships.remove(relationshipsToRemove.get(i));
+ for (IRelationship iRelationship : relationshipsToRemove) {
+ relationships.remove(iRelationship);
}
}
}
@@ -960,15 +959,13 @@ public class AsmManager implements IStructureModel {
List<IRelationship> relationshipsToRemove = new ArrayList<IRelationship>();
// Iterate through the relationships against this source
// handle
- for (Iterator<IRelationship> reliter = relationships.iterator(); reliter.hasNext();) {
- IRelationship rel = reliter.next();
+ for (IRelationship rel : relationships) {
List<String> targets = rel.getTargets();
List<String> targetsToRemove = new ArrayList<String>();
// Iterate through the targets for this relationship
- for (Iterator<String> targetIter = targets.iterator(); targetIter.hasNext();) {
- String targethid = targetIter.next();
-// tgthandlecounter++;
+ for (String targethid : targets) {
+ // tgthandlecounter++;
// Do we already know it doesn't exist?
if (nonExistingHandles.contains(targethid)) {
if (dumpDeltaProcessing) {
@@ -1040,8 +1037,7 @@ public class AsmManager implements IStructureModel {
} else {
// MEMORY LEAK - we don't remove the
// relationships !!
- for (int i = 0; i < relationshipsToRemove.size(); i++) {
- IRelationship irel = relationshipsToRemove.get(i);
+ for (IRelationship irel : relationshipsToRemove) {
verifyAssumption(mapper.remove(hid, irel), "Failed to remove relationship " + irel.getName()
+ " for shid " + hid);
}
@@ -1055,8 +1051,7 @@ public class AsmManager implements IStructureModel {
}
}
// Remove sources that have no valid relationships any more
- for (Iterator<String> srciter = sourcesToRemove.iterator(); srciter.hasNext();) {
- String hid = srciter.next();
+ for (String hid : sourcesToRemove) {
mapper.removeAll(hid);
IProgramElement ipe = hierarchy.getElement(hid);
if (ipe != null) {
diff --git a/asm/src/main/java/org/aspectj/asm/IProgramElement.java b/asm/src/main/java/org/aspectj/asm/IProgramElement.java
index 19e6d95ac..402376217 100644
--- a/asm/src/main/java/org/aspectj/asm/IProgramElement.java
+++ b/asm/src/main/java/org/aspectj/asm/IProgramElement.java
@@ -330,11 +330,11 @@ public interface IProgramElement extends Serializable {
};
public static Kind getKindForString(String kindString) {
- for (int i = 0; i < ALL.length; i++) {
- if (ALL[i].toString().equals(kindString)) {
- return ALL[i];
- }
- }
+ for (Kind kind : ALL) {
+ if (kind.toString().equals(kindString)) {
+ return kind;
+ }
+ }
return ERROR;
}
diff --git a/asm/src/main/java/org/aspectj/asm/IRelationship.java b/asm/src/main/java/org/aspectj/asm/IRelationship.java
index 86633cf36..441a3d2d0 100644
--- a/asm/src/main/java/org/aspectj/asm/IRelationship.java
+++ b/asm/src/main/java/org/aspectj/asm/IRelationship.java
@@ -75,9 +75,9 @@ public interface IRelationship extends Serializable {
* @return the Kind instance
*/
public static Kind getKindFor(String stringFormOfRelationshipKind) {
- for (int i = 0; i < ALL.length; i++) {
- if (ALL[i].name.equals(stringFormOfRelationshipKind)) {
- return ALL[i];
+ for (Kind kind : ALL) {
+ if (kind.name.equals(stringFormOfRelationshipKind)) {
+ return kind;
}
}
return null;
diff --git a/asm/src/main/java/org/aspectj/asm/internal/JDTLikeHandleProvider.java b/asm/src/main/java/org/aspectj/asm/internal/JDTLikeHandleProvider.java
index 3751dfc1b..15eb990ee 100644
--- a/asm/src/main/java/org/aspectj/asm/internal/JDTLikeHandleProvider.java
+++ b/asm/src/main/java/org/aspectj/asm/internal/JDTLikeHandleProvider.java
@@ -136,8 +136,7 @@ public class JDTLikeHandleProvider implements IElementHandleProvider {
List<char[]> parameterTypes = ipe.getParameterSignatures();
StringBuffer sb = new StringBuffer();
if (sourceRefs != null) {
- for (int i = 0; i < sourceRefs.size(); i++) {
- String sourceRef = sourceRefs.get(i);
+ for (String sourceRef : sourceRefs) {
sb.append(HandleProviderDelimiter.getDelimiter(ipe));
sb.append(sourceRef);
}
@@ -164,8 +163,7 @@ public class JDTLikeHandleProvider implements IElementHandleProvider {
if (ipe.getKind().isInterTypeMember()) {
int count = 1;
List<IProgramElement> kids = ipe.getParent().getChildren();
- for (Iterator<IProgramElement> iterator = kids.iterator(); iterator.hasNext();) {
- IProgramElement object = iterator.next();
+ for (IProgramElement object : kids) {
if (object.equals(ipe)) {
break;
}
diff --git a/asm/src/main/java/org/aspectj/asm/internal/ProgramElement.java b/asm/src/main/java/org/aspectj/asm/internal/ProgramElement.java
index 51aafd936..c1479f70f 100644
--- a/asm/src/main/java/org/aspectj/asm/internal/ProgramElement.java
+++ b/asm/src/main/java/org/aspectj/asm/internal/ProgramElement.java
@@ -544,8 +544,8 @@ public class ProgramElement implements IProgramElement {
if (children == null) {
return;
}
- for (Iterator<IProgramElement> it = children.iterator(); it.hasNext();) {
- (it.next()).setParent(this);
+ for (IProgramElement child : children) {
+ child.setParent(this);
}
}
@@ -751,8 +751,7 @@ public class ProgramElement implements IProgramElement {
return Collections.emptyList();
}
List<char[]> params = new ArrayList<char[]>();
- for (Iterator<char[]> iter = l.iterator(); iter.hasNext();) {
- char[] param = iter.next();
+ for (char[] param : l) {
params.add(NameConvertor.convertFromSignature(param));
}
return params;
diff --git a/asm/src/main/java/org/aspectj/asm/internal/RelationshipMap.java b/asm/src/main/java/org/aspectj/asm/internal/RelationshipMap.java
index 1fea7bb85..0df2fdd89 100644
--- a/asm/src/main/java/org/aspectj/asm/internal/RelationshipMap.java
+++ b/asm/src/main/java/org/aspectj/asm/internal/RelationshipMap.java
@@ -62,8 +62,7 @@ public class RelationshipMap extends HashMap<String, List<IRelationship>> implem
super.put(source, relationships);
return rel;
} else {
- for (Iterator<IRelationship> it = relationships.iterator(); it.hasNext();) {
- IRelationship curr = it.next();
+ for (IRelationship curr : relationships) {
if (curr.getKind() == kind && curr.getName().equals(relationshipName) && curr.hasRuntimeTest() == runtimeTest) {
return curr;
}