From 72194b7982ddfa8e9864d0a9934905bb76b90f33 Mon Sep 17 00:00:00 2001 From: Lars Grefer Date: Sat, 8 Aug 2020 03:06:37 +0200 Subject: '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 --- .../main/java/org/aspectj/internal/lang/reflect/StringToType.java | 6 +++--- .../aspectj/runtime/internal/cflowstack/ThreadCounterImpl11.java | 4 ++-- .../main/java/org/aspectj/runtime/reflect/MethodSignatureImpl.java | 4 ++-- .../org/aspectj/internal/lang/reflect/AjTypeWithAspectsTest.java | 6 +++--- 4 files changed, 10 insertions(+), 10 deletions(-) (limited to 'runtime/src') diff --git a/runtime/src/main/java/org/aspectj/internal/lang/reflect/StringToType.java b/runtime/src/main/java/org/aspectj/internal/lang/reflect/StringToType.java index 4be9fd71e..c658bbbd0 100644 --- a/runtime/src/main/java/org/aspectj/internal/lang/reflect/StringToType.java +++ b/runtime/src/main/java/org/aspectj/internal/lang/reflect/StringToType.java @@ -48,9 +48,9 @@ public class StringToType { } catch (ClassNotFoundException e) { // could be a type variable TypeVariable[] tVars = classScope.getTypeParameters(); - for (int i = 0; i < tVars.length; i++) { - if (tVars[i].getName().equals(typeName)) { - return tVars[i]; + for (TypeVariable tVar : tVars) { + if (tVar.getName().equals(typeName)) { + return tVar; } } throw new ClassNotFoundException(typeName); diff --git a/runtime/src/main/java/org/aspectj/runtime/internal/cflowstack/ThreadCounterImpl11.java b/runtime/src/main/java/org/aspectj/runtime/internal/cflowstack/ThreadCounterImpl11.java index 71aaacd62..bc53f9317 100644 --- a/runtime/src/main/java/org/aspectj/runtime/internal/cflowstack/ThreadCounterImpl11.java +++ b/runtime/src/main/java/org/aspectj/runtime/internal/cflowstack/ThreadCounterImpl11.java @@ -49,8 +49,8 @@ public class ThreadCounterImpl11 implements ThreadCounter { Thread t = (Thread)e.nextElement(); if (!t.isAlive()) dead_stacks.add(t); } - for (Iterator e = dead_stacks.iterator(); e.hasNext(); ) { - Thread t = (Thread)e.next(); + for (Object dead_stack : dead_stacks) { + Thread t = (Thread) dead_stack; counters.remove(t); } change_count = 0; diff --git a/runtime/src/main/java/org/aspectj/runtime/reflect/MethodSignatureImpl.java b/runtime/src/main/java/org/aspectj/runtime/reflect/MethodSignatureImpl.java index 17416bada..76ea6c6cf 100644 --- a/runtime/src/main/java/org/aspectj/runtime/reflect/MethodSignatureImpl.java +++ b/runtime/src/main/java/org/aspectj/runtime/reflect/MethodSignatureImpl.java @@ -102,8 +102,8 @@ class MethodSignatureImpl extends CodeSignatureImpl implements MethodSignature { } Class[] superinterfaces = type.getInterfaces(); if (superinterfaces != null) { - for (int i = 0; i < superinterfaces.length; i++) { - m = search(superinterfaces[i], name, params, searched); + for (Class superinterface : superinterfaces) { + m = search(superinterface, name, params, searched); if (m != null) { return m; } diff --git a/runtime/src/test/java/org/aspectj/internal/lang/reflect/AjTypeWithAspectsTest.java b/runtime/src/test/java/org/aspectj/internal/lang/reflect/AjTypeWithAspectsTest.java index af72d26f5..a2f33f91b 100644 --- a/runtime/src/test/java/org/aspectj/internal/lang/reflect/AjTypeWithAspectsTest.java +++ b/runtime/src/test/java/org/aspectj/internal/lang/reflect/AjTypeWithAspectsTest.java @@ -146,9 +146,9 @@ public class AjTypeWithAspectsTest extends TestCase { assertEquals(10,ms.length); //AV was corrupted, cannot rely on ordering String match = ""; - for (int i = 0; i < ms.length; i++) { - match = match + "--" + ms[i].getName(); - } + for (Method m : ms) { + match = match + "--" + m.getName(); + } assertTrue(match.indexOf("aMethod") >=0); } -- cgit v1.2.3