groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject [groovy] 10/18: Minor refactoring: 'for' loop can be replaced with 'foreach'
Date Sun, 03 Nov 2019 15:42:26 GMT
This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 1528aeace57fee2a3807ca62485db702354b3182
Author: Daniel Sun <sunlan@apache.org>
AuthorDate: Sun Nov 3 22:49:34 2019 +0800

    Minor refactoring: 'for' loop can be replaced with 'foreach'
    
    (cherry picked from commit d6765906874951e69647b1d42af98c8212e1f81a)
---
 .../java/groovy/lang/BenchmarkInterceptor.java     |   6 +-
 src/main/java/groovy/lang/ExpandoMetaClass.java    |   5 +-
 src/main/java/groovy/lang/MetaClassImpl.java       |  28 +++---
 .../util/concurrentlinkedhashmap/Weighers.java     |   8 +-
 src/main/java/org/codehaus/groovy/antlr/Main.java  |  31 +++---
 .../groovy/ast/expr/ArgumentListExpression.java    |   3 +-
 .../codehaus/groovy/ast/tools/GenericsUtils.java   |   4 +-
 .../groovy/classgen/AsmClassGenerator.java         |  18 ++--
 .../codehaus/groovy/classgen/BytecodeSequence.java |   7 +-
 .../groovy/classgen/DummyClassGenerator.java       |   9 +-
 .../codehaus/groovy/classgen/asm/CompileStack.java |   9 +-
 .../groovy/classgen/asm/InvocationWriter.java      |  15 ++-
 .../codehaus/groovy/classgen/asm/MethodCaller.java |   3 +-
 .../groovy/reflection/CachedConstructor.java       |   3 +-
 .../groovy/runtime/EncodingGroovyMethods.java      |   4 +-
 .../groovy/runtime/ScriptBytecodeAdapter.java      |   4 +-
 .../runtime/metaclass/ConcurrentReaderHashMap.java | 108 ++++++++++-----------
 .../runtime/metaclass/MetaClassRegistryImpl.java   |   4 +-
 .../groovy/runtime/metaclass/MetaMethodIndex.java  |   4 +-
 .../java/org/codehaus/groovy/syntax/CSTNode.java   |  14 +--
 .../codehaus/groovy/tools/FileSystemCompiler.java  |   4 +-
 .../groovy/tools/javac/JavaStubGenerator.java      |   6 +-
 .../groovy/tools/shell/util/MessageSource.java     |  11 +--
 .../transform/AnnotationCollectorTransform.java    |   3 +-
 .../transform/stc/StaticTypeCheckingSupport.java   |   3 +-
 .../groovy/util/AbstractConcurrentMap.java         |  12 +--
 .../groovy/util/AbstractConcurrentMapBase.java     | 100 +++++++++----------
 .../groovy/util/ManagedConcurrentLinkedQueue.java  |   4 +-
 .../codehaus/groovy/vmplugin/v5/JUnit4Utils.java   |   6 +-
 .../v7/IndyGuardsFiltersAndSignatures.java         |   5 +-
 30 files changed, 199 insertions(+), 242 deletions(-)

diff --git a/src/main/java/groovy/lang/BenchmarkInterceptor.java b/src/main/java/groovy/lang/BenchmarkInterceptor.java
index 793286d..e289bda 100644
--- a/src/main/java/groovy/lang/BenchmarkInterceptor.java
+++ b/src/main/java/groovy/lang/BenchmarkInterceptor.java
@@ -107,14 +107,14 @@ public class BenchmarkInterceptor implements Interceptor {
      */
     public List statistic() {
         List result = new LinkedList();
-        for (Iterator iter = calls.keySet().iterator(); iter.hasNext();) {
+        for (Object o : calls.keySet()) {
             Object[] line = new Object[3];
             result.add(line);
-            line[0] = iter.next();
+            line[0] = o;
             List times = (List) calls.get(line[0]);
             line[1] = times.size() / 2;
             int accTime = 0;
-            for (Iterator it = times.iterator(); it.hasNext();) {
+            for (Iterator it = times.iterator(); it.hasNext(); ) {
                 Long start = (Long) it.next();
                 Long end = (Long) it.next();
                 accTime += end - start;
diff --git a/src/main/java/groovy/lang/ExpandoMetaClass.java b/src/main/java/groovy/lang/ExpandoMetaClass.java
index 42abd56..e3bdff7 100644
--- a/src/main/java/groovy/lang/ExpandoMetaClass.java
+++ b/src/main/java/groovy/lang/ExpandoMetaClass.java
@@ -49,7 +49,6 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
@@ -1060,8 +1059,8 @@ public class ExpandoMetaClass extends MetaClassImpl implements GroovyObject {
      * @param modifiedSuperExpandos A list of modified super ExpandoMetaClass
      */
     public void refreshInheritedMethods(Set modifiedSuperExpandos) {
-        for (Iterator i = modifiedSuperExpandos.iterator(); i.hasNext();) {
-            ExpandoMetaClass superExpando = (ExpandoMetaClass) i.next();
+        for (Object modifiedSuperExpando : modifiedSuperExpandos) {
+            ExpandoMetaClass superExpando = (ExpandoMetaClass) modifiedSuperExpando;
             if (superExpando != this) {
                 refreshInheritedMethods(superExpando);
             }
diff --git a/src/main/java/groovy/lang/MetaClassImpl.java b/src/main/java/groovy/lang/MetaClassImpl.java
index 8cee0f2..94cb823 100644
--- a/src/main/java/groovy/lang/MetaClassImpl.java
+++ b/src/main/java/groovy/lang/MetaClassImpl.java
@@ -721,8 +721,8 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass {
                 } else {
                     arr = ((FastArray) answer).copy();
                 }
-                for (Iterator iter = used.iterator(); iter.hasNext(); ) {
-                    MetaMethod element = (MetaMethod) iter.next();
+                for (Object o : used) {
+                    MetaMethod element = (MetaMethod) o;
                     if (!element.getDeclaringClass().getTheClass().isAssignableFrom(sender))
                         continue;
                     filterMatchingMethodForCategory(arr, element);
@@ -1821,8 +1821,8 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass {
      */
     public void setProperties(Object bean, Map map) {
         checkInitalised();
-        for (Iterator iter = map.entrySet().iterator(); iter.hasNext(); ) {
-            Map.Entry entry = (Map.Entry) iter.next();
+        for (Object o : map.entrySet()) {
+            Map.Entry entry = (Map.Entry) o;
             String key = entry.getKey().toString();
 
             Object value = entry.getValue();
@@ -2116,8 +2116,8 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass {
     private static MetaMethod getCategoryMethodMissing(Class sender) {
         List possibleGenericMethods = GroovyCategorySupport.getCategoryMethods("methodMissing");
         if (possibleGenericMethods != null) {
-            for (Iterator iter = possibleGenericMethods.iterator(); iter.hasNext(); ) {
-                MetaMethod mmethod = (MetaMethod) iter.next();
+            for (Object possibleGenericMethod : possibleGenericMethods) {
+                MetaMethod mmethod = (MetaMethod) possibleGenericMethod;
                 if (!mmethod.getDeclaringClass().getTheClass().isAssignableFrom(sender))
                     continue;
 
@@ -2133,8 +2133,8 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass {
     private static MetaMethod getCategoryMethodGetter(Class sender, String name, boolean useLongVersion) {
         List possibleGenericMethods = GroovyCategorySupport.getCategoryMethods(name);
         if (possibleGenericMethods != null) {
-            for (Iterator iter = possibleGenericMethods.iterator(); iter.hasNext(); ) {
-                MetaMethod mmethod = (MetaMethod) iter.next();
+            for (Object possibleGenericMethod : possibleGenericMethods) {
+                MetaMethod mmethod = (MetaMethod) possibleGenericMethod;
                 if (!mmethod.getDeclaringClass().getTheClass().isAssignableFrom(sender))
                     continue;
 
@@ -2154,8 +2154,8 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass {
     private static MetaMethod getCategoryMethodSetter(Class sender, String name, boolean useLongVersion) {
         List possibleGenericMethods = GroovyCategorySupport.getCategoryMethods(name);
         if (possibleGenericMethods != null) {
-            for (Iterator iter = possibleGenericMethods.iterator(); iter.hasNext(); ) {
-                MetaMethod mmethod = (MetaMethod) iter.next();
+            for (Object possibleGenericMethod : possibleGenericMethods) {
+                MetaMethod mmethod = (MetaMethod) possibleGenericMethod;
                 if (!mmethod.getDeclaringClass().getTheClass().isAssignableFrom(sender))
                     continue;
 
@@ -2472,12 +2472,12 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass {
     }
 
     private void inheritStaticInterfaceFields(LinkedList superClasses, Set interfaces) {
-        for (Iterator interfaceIter = interfaces.iterator(); interfaceIter.hasNext(); ) {
-            CachedClass iclass = (CachedClass) interfaceIter.next();
+        for (Object anInterface : interfaces) {
+            CachedClass iclass = (CachedClass) anInterface;
             SingleKeyHashMap iPropertyIndex = classPropertyIndex.getNotNull(iclass);
             addFields(iclass, iPropertyIndex);
-            for (Iterator classIter = superClasses.iterator(); classIter.hasNext(); ) {
-                CachedClass sclass = (CachedClass) classIter.next();
+            for (Object superClass : superClasses) {
+                CachedClass sclass = (CachedClass) superClass;
                 if (!iclass.getTheClass().isAssignableFrom(sclass.getTheClass())) continue;
                 SingleKeyHashMap sPropertyIndex = classPropertyIndex.getNotNull(sclass);
                 copyNonPrivateFields(iPropertyIndex, sPropertyIndex, null);
diff --git a/src/main/java/org/apache/groovy/util/concurrentlinkedhashmap/Weighers.java b/src/main/java/org/apache/groovy/util/concurrentlinkedhashmap/Weighers.java
index 6713c4a..1fb654a 100644
--- a/src/main/java/org/apache/groovy/util/concurrentlinkedhashmap/Weighers.java
+++ b/src/main/java/org/apache/groovy/util/concurrentlinkedhashmap/Weighers.java
@@ -17,7 +17,6 @@ package org.apache.groovy.util.concurrentlinkedhashmap;
 
 import java.io.Serializable;
 import java.util.Collection;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -235,10 +234,9 @@ public final class Weighers {
         return ((Collection<?>) values).size();
       }
       int size = 0;
-      for (Iterator<?> i = values.iterator(); i.hasNext();) {
-        i.next();
-        size++;
-      }
+        for (Object value : values) {
+            size++;
+        }
       return size;
     }
   }
diff --git a/src/main/java/org/codehaus/groovy/antlr/Main.java b/src/main/java/org/codehaus/groovy/antlr/Main.java
index ae3bb5f..ca10099 100644
--- a/src/main/java/org/codehaus/groovy/antlr/Main.java
+++ b/src/main/java/org/codehaus/groovy/antlr/Main.java
@@ -46,33 +46,29 @@ class Main {
                 System.err.println("Parsing...");
 
                 // for each directory/file specified on the command line
-                for(int i=0; i< args.length;i++) {
-                    if ( args[i].equals("-showtree") ) {
+                for (String arg : args) {
+                    if (arg.equals("-showtree")) {
                         showTree = true;
                     }
                     //else if ( args[i].equals("-xml") ) {
                     //    xml = true;
                     //}
-                    else if ( args[i].equals("-verbose") ) {
+                    else if (arg.equals("-verbose")) {
                         verbose = true;
-                    }
-                    else if ( args[i].equals("-trace") ) {
+                    } else if (arg.equals("-trace")) {
                         GroovyRecognizer.tracing = true;
                         GroovyLexer.tracing = true;
-                    }
-                    else if ( args[i].equals("-traceParser") ) {
+                    } else if (arg.equals("-traceParser")) {
                         GroovyRecognizer.tracing = true;
-                    }
-                    else if ( args[i].equals("-traceLexer") ) {
+                    } else if (arg.equals("-traceLexer")) {
                         GroovyLexer.tracing = true;
+                    } else if (arg.equals("-whitespaceIncluded")) {
+                        whitespaceIncluded = true;
+                    } else {
+                        doFile(new File(arg)); // parse it
                     }
-                                        else if ( args[i].equals("-whitespaceIncluded") ) {
-                                            whitespaceIncluded = true;
-                                        }
-                                        else {
-                        doFile(new File(args[i])); // parse it
-                    }
-                } }
+                }
+            }
             else
                 System.err.println("Usage: java -jar groovyc.jar [-showtree] [-verbose] [-trace{,Lexer,Parser}]"+
                                    "<directory or file name>");
@@ -91,8 +87,7 @@ class Main {
         // If this is a directory, walk each file/dir in that directory
         if (f.isDirectory()) {
             String files[] = f.list();
-            for(int i=0; i < files.length; i++)
-                doFile(new File(f, files[i]));
+            for (String file : files) doFile(new File(f, file));
         }
 
         // otherwise, if this is a groovy file, parse it!
diff --git a/src/main/java/org/codehaus/groovy/ast/expr/ArgumentListExpression.java b/src/main/java/org/codehaus/groovy/ast/expr/ArgumentListExpression.java
index 0f4a7e4..a70fbed 100644
--- a/src/main/java/org/codehaus/groovy/ast/expr/ArgumentListExpression.java
+++ b/src/main/java/org/codehaus/groovy/ast/expr/ArgumentListExpression.java
@@ -45,8 +45,7 @@ public class ArgumentListExpression extends TupleExpression {
     }
 
     public ArgumentListExpression(Parameter[] parameters) {
-        for (int i = 0; i < parameters.length; i++) {
-            Parameter parameter = parameters[i];
+        for (Parameter parameter : parameters) {
             addExpression(new VariableExpression(parameter));
         }
     }
diff --git a/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java b/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java
index bb2214b..da4e4be 100644
--- a/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java
+++ b/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java
@@ -656,8 +656,8 @@ public class GenericsUtils {
                 ClassNode[] newUpper = upper;
                 if (upper != null && upper.length > 0) {
                     ClassNode[] upperCorrected = new ClassNode[upper.length];
-                    for (int j = 0; j < upper.length; j++) {
-                        upperCorrected[i] = correctToGenericsSpecRecurse(genericsSpec, upper[j]);
+                    for (ClassNode classNode : upper) {
+                        upperCorrected[i] = correctToGenericsSpecRecurse(genericsSpec, classNode);
                     }
                     upper = upperCorrected;
                 }
diff --git a/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java b/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
index 31719f5..2111e0a 100644
--- a/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
+++ b/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
@@ -414,9 +414,9 @@ public class AsmClassGenerator extends ClassGenerator {
 
         // Add parameter names to the MethodVisitor (jdk8+ only)
         if (getCompileUnit().getConfig().getParameters()) {
-            for (int i = 0; i < parameters.length; i++) {
+            for (Parameter parameter : parameters) {
                 // TODO handle ACC_SYNTHETIC for enum method parameters?
-                mv.visitParameter(parameters[i].getName(), 0);
+                mv.visitParameter(parameter.getName(), 0);
             }
         }
 
@@ -860,8 +860,8 @@ public class AsmClassGenerator extends ClassGenerator {
         } else {
             return arguments instanceof SpreadExpression;
         }
-        for (Iterator iter = args.iterator(); iter.hasNext();) {
-            if (iter.next() instanceof SpreadExpression) return true;
+        for (Object arg : args) {
+            if (arg instanceof SpreadExpression) return true;
         }
         return false;
     }
@@ -1600,8 +1600,7 @@ public class AsmClassGenerator extends ClassGenerator {
         mv.visitTypeInsn(ANEWARRAY, "java/lang/Object");
 
         int i = 0;
-        for (Iterator iter = entries.iterator(); iter.hasNext();) {
-            Object object = iter.next();
+        for (Object object : entries) {
             MapEntryExpression entry = (MapEntryExpression) object;
 
             mv.visitInsn(DUP);
@@ -1699,8 +1698,8 @@ public class AsmClassGenerator extends ClassGenerator {
         int size = 0;
         int dimensions = 0;
         if (sizeExpression != null) {
-            for (Iterator iter = sizeExpression.iterator(); iter.hasNext();) {
-                Expression element = (Expression) iter.next();
+            for (Object o : sizeExpression) {
+                Expression element = (Expression) o;
                 if (element == ConstantExpression.EMPTY_EXPRESSION) break;
                 dimensions++;
                 // let's convert to an int
@@ -1915,8 +1914,7 @@ public class AsmClassGenerator extends ClassGenerator {
         MethodVisitor mv = controller.getMethodVisitor();
         List instructions = bytecodeSequence.getInstructions();
         int mark = controller.getOperandStack().getStackLength();
-        for (Iterator iterator = instructions.iterator(); iterator.hasNext();) {
-            Object part = iterator.next();
+        for (Object part : instructions) {
             if (part instanceof EmptyExpression) {
                 mv.visitInsn(ACONST_NULL);
             } else if (part instanceof Expression) {
diff --git a/src/main/java/org/codehaus/groovy/classgen/BytecodeSequence.java b/src/main/java/org/codehaus/groovy/classgen/BytecodeSequence.java
index 7da3c4d..b70b855 100644
--- a/src/main/java/org/codehaus/groovy/classgen/BytecodeSequence.java
+++ b/src/main/java/org/codehaus/groovy/classgen/BytecodeSequence.java
@@ -23,7 +23,6 @@ import org.codehaus.groovy.ast.GroovyCodeVisitor;
 import org.codehaus.groovy.ast.stmt.Statement;
 
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
 
 /**
@@ -66,10 +65,10 @@ public class BytecodeSequence extends Statement {
             gen.visitBytecodeSequence(this);
             return;
         }
-        for (Iterator iterator = instructions.iterator(); iterator.hasNext();) {
-            Object part = (Object) iterator.next();
+        for (BytecodeInstruction instruction : instructions) {
+            Object part = (Object) instruction;
             if (part instanceof ASTNode) {
-                ((ASTNode)part).visit(visitor);
+                ((ASTNode) part).visit(visitor);
             }
         }
     }
diff --git a/src/main/java/org/codehaus/groovy/classgen/DummyClassGenerator.java b/src/main/java/org/codehaus/groovy/classgen/DummyClassGenerator.java
index b85f91a..8b7e05d 100644
--- a/src/main/java/org/codehaus/groovy/classgen/DummyClassGenerator.java
+++ b/src/main/java/org/codehaus/groovy/classgen/DummyClassGenerator.java
@@ -34,8 +34,6 @@ import org.objectweb.asm.ClassVisitor;
 import org.objectweb.asm.MethodVisitor;
 import org.objectweb.asm.Opcodes;
 
-import java.util.Iterator;
-
 /**
  * To generate a class that has all the fields and methods, except that fields are not initialized
  * and methods are empty. It's intended for being used as a place holder during code generation
@@ -84,8 +82,7 @@ public class DummyClassGenerator extends ClassGenerator {
 
             classNode.visitContents(this);
 
-            for (Iterator iter = innerClasses.iterator(); iter.hasNext();) {
-                ClassNode innerClass = (ClassNode) iter.next();
+            for (ClassNode innerClass : innerClasses) {
                 ClassNode innerClassType = innerClass;
                 String innerClassInternalName = BytecodeHelper.getClassInternalName(innerClassType);
                 String outerClassName = internalClassName; // default for inner classes
@@ -163,8 +160,8 @@ public class DummyClassGenerator extends ClassGenerator {
     }
 
     protected void visitParameters(ASTNode node, Parameter[] parameters) {
-        for (int i = 0, size = parameters.length; i < size; i++) {
-            visitParameter(node, parameters[i]);
+        for (Parameter parameter : parameters) {
+            visitParameter(node, parameter);
         }
     }
 
diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/CompileStack.java b/src/main/java/org/codehaus/groovy/classgen/asm/CompileStack.java
index 5686b75..4bd54c4 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/CompileStack.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/CompileStack.java
@@ -31,7 +31,6 @@ import org.objectweb.asm.Opcodes;
 
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.ListIterator;
@@ -239,8 +238,8 @@ public class CompileStack implements Opcodes {
     private void setEndLabels(){
         Label endLabel = new Label();
         controller.getMethodVisitor().visitLabel(endLabel);
-        for (Iterator iter = stackVariables.values().iterator(); iter.hasNext();) {
-            BytecodeVariable var = (BytecodeVariable) iter.next();
+        for (Object o : stackVariables.values()) {
+            BytecodeVariable var = (BytecodeVariable) o;
             var.setEndLabel(endLabel);
         }
         thisEndLabel = endLabel;
@@ -365,8 +364,8 @@ public class CompileStack implements Opcodes {
                 mv.visitLocalVariable("this", className, null, thisStartLabel, thisEndLabel, 0);
             }
 
-            for (Iterator iterator = usedVariables.iterator(); iterator.hasNext();) {
-                BytecodeVariable v = (BytecodeVariable) iterator.next();
+            for (Object usedVariable : usedVariables) {
+                BytecodeVariable v = (BytecodeVariable) usedVariable;
                 ClassNode t = v.getType();
                 if (v.isHolder()) t = ClassHelper.REFERENCE_TYPE;
                 String type = BytecodeHelper.getTypeDescription(t);
diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/InvocationWriter.java b/src/main/java/org/codehaus/groovy/classgen/asm/InvocationWriter.java
index c4a40ad..472f70a 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/InvocationWriter.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/InvocationWriter.java
@@ -810,8 +810,8 @@ public class InvocationWriter {
         Label defaultLabel = new Label();
         Label afterSwitch = new Label();
         mv.visitLookupSwitchInsn(defaultLabel, indices, targets);
-        for (int i = 0; i < targets.length; i++) {
-            mv.visitLabel(targets[i]);
+        for (Label target : targets) {
+            mv.visitLabel(target);
             // to keep the stack height, we need to leave
             // one Object[] on the stack as last element. At the
             // same time, we need the Object[] on top of the stack
@@ -845,13 +845,13 @@ public class InvocationWriter {
             // vargs need special attention and transformation though
             Parameter[] parameters = cn.getParameters();
             int lengthWithoutVargs = parameters.length;
-            if (parameters.length>0 && parameters[parameters.length-1].getType().isArray()) {
+            if (parameters.length > 0 && parameters[parameters.length - 1].getType().isArray()) {
                 lengthWithoutVargs--;
             }
             for (int p = 0; p < lengthWithoutVargs; p++) {
                 loadAndCastElement(operandStack, mv, parameters, p);
             }
-            if (parameters.length>lengthWithoutVargs) {
+            if (parameters.length > lengthWithoutVargs) {
                 ClassNode type = parameters[lengthWithoutVargs].getType();
                 BytecodeHelper.pushConstant(mv, lengthWithoutVargs);
                 controller.getAcg().visitClassExpression(new ClassExpression(type));
@@ -907,12 +907,11 @@ public class InvocationWriter {
     // we match only on the number of arguments, not anything else
     private static ConstructorNode getMatchingConstructor(List<ConstructorNode> constructors, List<Expression> argumentList) {
         ConstructorNode lastMatch = null;
-        for (int i=0; i<constructors.size(); i++) {
-            ConstructorNode cn = constructors.get(i);
+        for (ConstructorNode cn : constructors) {
             Parameter[] params = cn.getParameters();
             // if number of parameters does not match we have no match
-            if (argumentList.size()!=params.length) continue;
-            if (lastMatch==null) {
+            if (argumentList.size() != params.length) continue;
+            if (lastMatch == null) {
                 lastMatch = cn;
             } else {
                 // we already had a match so we don't make a direct call at all
diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/MethodCaller.java b/src/main/java/org/codehaus/groovy/classgen/asm/MethodCaller.java
index 9ebb34d..85fae66 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/MethodCaller.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/MethodCaller.java
@@ -75,8 +75,7 @@ public class MethodCaller implements Opcodes {
 
     protected Method getMethod() {
         Method[] methods = theClass.getMethods();
-        for (int i = 0; i < methods.length; i++) {
-            Method method = methods[i];
+        for (Method method : methods) {
             if (method.getName().equals(name)) {
                 return method;
             }
diff --git a/src/main/java/org/codehaus/groovy/reflection/CachedConstructor.java b/src/main/java/org/codehaus/groovy/reflection/CachedConstructor.java
index cb43103..347b9b0 100644
--- a/src/main/java/org/codehaus/groovy/reflection/CachedConstructor.java
+++ b/src/main/java/org/codehaus/groovy/reflection/CachedConstructor.java
@@ -47,8 +47,7 @@ public class CachedConstructor extends ParameterTypes {
 
     public static CachedConstructor find(Constructor constructor) {
         CachedConstructor[] constructors = ReflectionCache.getCachedClass(constructor.getDeclaringClass()).getConstructors();
-        for (int i = 0; i < constructors.length; i++) {
-            CachedConstructor cachedConstructor = constructors[i];
+        for (CachedConstructor cachedConstructor : constructors) {
             if (cachedConstructor.cachedConstructor.equals(constructor))
                 return cachedConstructor;
         }
diff --git a/src/main/java/org/codehaus/groovy/runtime/EncodingGroovyMethods.java b/src/main/java/org/codehaus/groovy/runtime/EncodingGroovyMethods.java
index d41f04e..2d4ba4f 100644
--- a/src/main/java/org/codehaus/groovy/runtime/EncodingGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/EncodingGroovyMethods.java
@@ -317,9 +317,9 @@ public class EncodingGroovyMethods {
     public static Writable encodeHex(final byte[] data) {
         return new Writable() {
             public Writer writeTo(Writer out) throws IOException {
-                for (int i = 0; i < data.length; i++) {
+                for (byte datum : data) {
                     // convert byte into unsigned hex string
-                    String hexString = Integer.toHexString(data[i] & 0xFF);
+                    String hexString = Integer.toHexString(datum & 0xFF);
 
                     // add leading zero if the length of the string is one
                     if (hexString.length() < 2) {
diff --git a/src/main/java/org/codehaus/groovy/runtime/ScriptBytecodeAdapter.java b/src/main/java/org/codehaus/groovy/runtime/ScriptBytecodeAdapter.java
index df1a4c4..69cd50f 100644
--- a/src/main/java/org/codehaus/groovy/runtime/ScriptBytecodeAdapter.java
+++ b/src/main/java/org/codehaus/groovy/runtime/ScriptBytecodeAdapter.java
@@ -799,8 +799,8 @@ public class ScriptBytecodeAdapter {
         List ret = new ArrayList();
         int argsPos = 0;
         int spreadPos = 0;
-        for (int pos = 0; pos < positions.length; pos++) {
-            for (; argsPos < positions[pos]; argsPos++) {
+        for (int position : positions) {
+            for (; argsPos < position; argsPos++) {
                 ret.add(args[argsPos]);
             }
             Object value = spreads[spreadPos];
diff --git a/src/main/java/org/codehaus/groovy/runtime/metaclass/ConcurrentReaderHashMap.java b/src/main/java/org/codehaus/groovy/runtime/metaclass/ConcurrentReaderHashMap.java
index 560cf97..86277db 100644
--- a/src/main/java/org/codehaus/groovy/runtime/metaclass/ConcurrentReaderHashMap.java
+++ b/src/main/java/org/codehaus/groovy/runtime/metaclass/ConcurrentReaderHashMap.java
@@ -572,42 +572,40 @@ public class ConcurrentReaderHashMap
      * reader thread that may be in the midst of traversing table
      * right now.)
      */
-    
-    for (int i = 0; i < oldCapacity ; i++) {
-      // We need to guarantee that any existing reads of old Map can
-      // proceed. So we cannot yet null out each bin.
-      Entry e = oldTable[i];
-      
-      if (e != null) {
-        int idx = e.hash & mask;
-        Entry next = e.next;
-        
-        //  Single node on list
-        if (next == null) 
-          newTable[idx] = e;
-        
-        else {    
-          // Reuse trailing consecutive sequence of all same bit
-          Entry lastRun = e;
-          int lastIdx = idx;
-          for (Entry last = next; last != null; last = last.next) {
-            int k = last.hash & mask;
-            if (k != lastIdx) {
-              lastIdx = k;
-              lastRun = last;
-            }
-          }
-          newTable[lastIdx] = lastRun;
-          
-          // Clone all remaining nodes
-          for (Entry p = e; p != lastRun; p = p.next) {
-            int k = p.hash & mask;
-            newTable[k] = new Entry(p.hash, p.key, 
-                                    p.value, newTable[k]);
+
+      for (Entry e : oldTable) {
+          // We need to guarantee that any existing reads of old Map can
+          // proceed. So we cannot yet null out each bin.
+          if (e != null) {
+              int idx = e.hash & mask;
+              Entry next = e.next;
+
+              //  Single node on list
+              if (next == null)
+                  newTable[idx] = e;
+
+              else {
+                  // Reuse trailing consecutive sequence of all same bit
+                  Entry lastRun = e;
+                  int lastIdx = idx;
+                  for (Entry last = next; last != null; last = last.next) {
+                      int k = last.hash & mask;
+                      if (k != lastIdx) {
+                          lastIdx = k;
+                          lastRun = last;
+                      }
+                  }
+                  newTable[lastIdx] = lastRun;
+
+                  // Clone all remaining nodes
+                  for (Entry p = e; p != lastRun; p = p.next) {
+                      int k = p.hash & mask;
+                      newTable[k] = new Entry(p.hash, p.key,
+                              p.value, newTable[k]);
+                  }
+              }
           }
-        }
       }
-    }
 
     table = newTable;
     recordModification(newTable);
@@ -716,12 +714,12 @@ public class ConcurrentReaderHashMap
     if (value == null) throw new NullPointerException();
 
     Entry tab[] = getTableForReading();
-    
-    for (int i = 0 ; i < tab.length; ++i) {
-      for (Entry e = tab[i] ; e != null ; e = e.next) 
-        if (value.equals(e.value))
-          return true;
-    }
+
+      for (Entry entry : tab) {
+          for (Entry e = entry; e != null; e = e.next)
+              if (value.equals(e.value))
+                  return true;
+      }
 
     return false;
   }
@@ -768,12 +766,12 @@ public class ConcurrentReaderHashMap
     while (n >= threshold)
       rehash();
 
-    for (Iterator it = t.entrySet().iterator(); it.hasNext();) {
-      Map.Entry entry = (Map.Entry) it.next();
-      Object key = entry.getKey();
-      Object value = entry.getValue();
-      put(key, value);
-    }
+      for (Object o : t.entrySet()) {
+          Map.Entry entry = (Map.Entry) o;
+          Object key = entry.getKey();
+          Object value = entry.getValue();
+          put(key, value);
+      }
   }
 
 
@@ -868,14 +866,12 @@ public class ConcurrentReaderHashMap
     }
     public Object[] toArray() {
       Collection c = new ArrayList();
-      for (Iterator i = iterator(); i.hasNext(); )
-          c.add(i.next());
+        for (Object o : this) c.add(o);
       return c.toArray();
     }
     public Object[] toArray(Object[] a) {
       Collection c = new ArrayList();
-      for (Iterator i = iterator(); i.hasNext(); )
-          c.add(i.next());
+        for (Object o : this) c.add(o);
       return c.toArray(a);
     }
   }
@@ -911,14 +907,12 @@ public class ConcurrentReaderHashMap
     }
     public Object[] toArray() {
       Collection c = new ArrayList();
-      for (Iterator i = iterator(); i.hasNext(); )
-          c.add(i.next());
+        for (Object o : this) c.add(o);
       return c.toArray();
     }
     public Object[] toArray(Object[] a) {
       Collection c = new ArrayList();
-      for (Iterator i = iterator(); i.hasNext(); )
-          c.add(i.next());
+        for (Object o : this) c.add(o);
       return c.toArray(a);
     }
   }
@@ -964,14 +958,12 @@ public class ConcurrentReaderHashMap
     }
     public Object[] toArray() {
       Collection c = new ArrayList();
-      for (Iterator i = iterator(); i.hasNext(); )
-          c.add(i.next());
+        for (Object o : this) c.add(o);
       return c.toArray();
     }
     public Object[] toArray(Object[] a) {
       Collection c = new ArrayList();
-      for (Iterator i = iterator(); i.hasNext(); )
-          c.add(i.next());
+        for (Object o : this) c.add(o);
       return c.toArray(a);
     }
   }
diff --git a/src/main/java/org/codehaus/groovy/runtime/metaclass/MetaClassRegistryImpl.java b/src/main/java/org/codehaus/groovy/runtime/metaclass/MetaClassRegistryImpl.java
index 5edca84..791323d 100644
--- a/src/main/java/org/codehaus/groovy/runtime/metaclass/MetaClassRegistryImpl.java
+++ b/src/main/java/org/codehaus/groovy/runtime/metaclass/MetaClassRegistryImpl.java
@@ -389,8 +389,8 @@ public class MetaClassRegistryImpl implements MetaClassRegistry{
     protected void fireConstantMetaClassUpdate(Object obj, Class c, final MetaClass oldMC, MetaClass newMc) {
         MetaClassRegistryChangeEventListener[]  listener = getMetaClassRegistryChangeEventListeners();
         MetaClassRegistryChangeEvent cmcu = new MetaClassRegistryChangeEvent(this, obj, c, oldMC, newMc);
-        for (int i = 0; i<listener.length; i++) {
-            listener[i].updateConstantMetaClass(cmcu);
+        for (MetaClassRegistryChangeEventListener metaClassRegistryChangeEventListener : listener) {
+            metaClassRegistryChangeEventListener.updateConstantMetaClass(cmcu);
         }
     }
 
diff --git a/src/main/java/org/codehaus/groovy/runtime/metaclass/MetaMethodIndex.java b/src/main/java/org/codehaus/groovy/runtime/metaclass/MetaMethodIndex.java
index b70b344..e1ca0f8 100644
--- a/src/main/java/org/codehaus/groovy/runtime/metaclass/MetaMethodIndex.java
+++ b/src/main/java/org/codehaus/groovy/runtime/metaclass/MetaMethodIndex.java
@@ -487,8 +487,8 @@ public class MetaMethodIndex {
         Entry[] table = this.table;
         int length = table.length;
 
-        for (int j = 0; j < length; j++) {
-            for (Entry e = table[j]; e != null; e = e.nextHashEntry) {
+        for (Entry entry : table) {
+            for (Entry e = entry; e != null; e = e.nextHashEntry) {
                 if (e.methods instanceof FastArray)
                     e.methodsForSuper = ((FastArray) e.methods).copy();
                 else
diff --git a/src/main/java/org/codehaus/groovy/syntax/CSTNode.java b/src/main/java/org/codehaus/groovy/syntax/CSTNode.java
index 631c8ed..e074681 100644
--- a/src/main/java/org/codehaus/groovy/syntax/CSTNode.java
+++ b/src/main/java/org/codehaus/groovy/syntax/CSTNode.java
@@ -85,8 +85,8 @@ public abstract class CSTNode {
      */
     public boolean isOneOf(int[] types) {
         int meaning = getMeaning();
-        for (int i = 0; i < types.length; i++) {
-            if (Types.ofType(meaning, types[i])) {
+        for (int type : types) {
+            if (Types.ofType(meaning, type)) {
                 return true;
             }
         }
@@ -99,8 +99,8 @@ public abstract class CSTNode {
      */
     public boolean isAllOf(int[] types) {
         int meaning = getMeaning();
-        for (int i = 0; i < types.length; i++) {
-            if (!Types.ofType(meaning, types[i])) {
+        for (int type : types) {
+            if (!Types.ofType(meaning, type)) {
                 return false;
             }
         }
@@ -114,9 +114,9 @@ public abstract class CSTNode {
      */
     public int getMeaningAs(int[] types) {
 
-        for (int i = 0; i < types.length; i++) {
-            if (isA(types[i])) {
-                return types[i];
+        for (int type : types) {
+            if (isA(type)) {
+                return type;
             }
         }
 
diff --git a/src/main/java/org/codehaus/groovy/tools/FileSystemCompiler.java b/src/main/java/org/codehaus/groovy/tools/FileSystemCompiler.java
index 2c02e86..39e103f 100644
--- a/src/main/java/org/codehaus/groovy/tools/FileSystemCompiler.java
+++ b/src/main/java/org/codehaus/groovy/tools/FileSystemCompiler.java
@@ -299,8 +299,8 @@ public class FileSystemCompiler {
             file.delete();
         } else if (file.isDirectory()) {
             File[] files = file.listFiles();
-            for (int i = 0; i < files.length; i++) {
-                deleteRecursive(files[i]);
+            for (File value : files) {
+                deleteRecursive(value);
             }
             file.delete();
         }
diff --git a/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java b/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
index 3fec399..2510ff0 100644
--- a/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
+++ b/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
@@ -611,9 +611,9 @@ public class JavaStubGenerator {
 
 
         // if all remaining exceptions are used in the stub we are good
-        outer: for (int i=0; i<superExceptions.length; i++) {
-            ClassNode superExc = superExceptions[i];
-            for (ClassNode stub:stubExceptions) {
+        outer:
+        for (ClassNode superExc : superExceptions) {
+            for (ClassNode stub : stubExceptions) {
                 if (stub.isDerivedFrom(superExc)) continue outer;
             }
             // not found
diff --git a/src/main/java/org/codehaus/groovy/tools/shell/util/MessageSource.java b/src/main/java/org/codehaus/groovy/tools/shell/util/MessageSource.java
index 1797043..82f5e6a 100644
--- a/src/main/java/org/codehaus/groovy/tools/shell/util/MessageSource.java
+++ b/src/main/java/org/codehaus/groovy/tools/shell/util/MessageSource.java
@@ -97,16 +97,15 @@ public class MessageSource
         MissingResourceException error = null;
         
         ResourceBundle[] bundles = getBundles();
-        
-        for (int i=0; i<bundles.length; i++) {
+
+        for (ResourceBundle bundle : bundles) {
             try {
-                return bundles[i].getString(code);
-            }
-            catch (MissingResourceException e) {
+                return bundle.getString(code);
+            } catch (MissingResourceException e) {
                 //
                 // FIXME: For now just save the first error, should really roll a new message with all of the details
                 //
-                
+
                 if (error != null) {
                     error = e;
                 }
diff --git a/src/main/java/org/codehaus/groovy/transform/AnnotationCollectorTransform.java b/src/main/java/org/codehaus/groovy/transform/AnnotationCollectorTransform.java
index e256fc0..efe75e7 100644
--- a/src/main/java/org/codehaus/groovy/transform/AnnotationCollectorTransform.java
+++ b/src/main/java/org/codehaus/groovy/transform/AnnotationCollectorTransform.java
@@ -97,8 +97,7 @@ public class AnnotationCollectorTransform {
          */
         public void transformClass(ClassNode cn) {
             AnnotationNode collector = null;
-            for (ListIterator<AnnotationNode> it = cn.getAnnotations().listIterator(); it.hasNext(); ) {
-                AnnotationNode an = it.next();
+            for (AnnotationNode an : cn.getAnnotations()) {
                 if (an.getClassNode().getName().equals(AnnotationCollector.class.getName())) {
                     collector = an;
                     break;
diff --git a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
index dd74327..f27988a 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
@@ -978,8 +978,7 @@ public abstract class StaticTypeCheckingSupport {
         if (c.equals(interfaceClass)) return 0;
         ClassNode[] interfaces = c.getInterfaces();
         int max = -1;
-        for (int i = 0; i < interfaces.length; i++) {
-            final ClassNode anInterface = interfaces[i];
+        for (final ClassNode anInterface : interfaces) {
             int sub = getMaximumInterfaceDistance(anInterface, interfaceClass);
             // we need to keep the -1 to track the mismatch, a +1
             // by any means could let it look like a direct match
diff --git a/src/main/java/org/codehaus/groovy/util/AbstractConcurrentMap.java b/src/main/java/org/codehaus/groovy/util/AbstractConcurrentMap.java
index c341326..3fbf8e0 100644
--- a/src/main/java/org/codehaus/groovy/util/AbstractConcurrentMap.java
+++ b/src/main/java/org/codehaus/groovy/util/AbstractConcurrentMap.java
@@ -68,8 +68,8 @@ public abstract class AbstractConcurrentMap<K, V> extends AbstractConcurrentMapB
                 }
                 else {
                     Object arr [] = (Object[]) o;
-                    for (int i = 0; i < arr.length; i++) {
-                        Entry<K,V> e = (Entry<K,V>) arr[i];
+                    for (Object value : arr) {
+                        Entry<K, V> e = (Entry<K, V>) value;
                         if (e != null && e.isEqual(key, hash)) {
                             return e.getValue();
                         }
@@ -91,8 +91,8 @@ public abstract class AbstractConcurrentMap<K, V> extends AbstractConcurrentMapB
                 }
                 else {
                     Object arr [] = (Object[]) o;
-                    for (int i = 0; i < arr.length; i++) {
-                        Entry<K,V> e = (Entry<K,V>) arr[i];
+                    for (Object item : arr) {
+                        Entry<K, V> e = (Entry<K, V>) item;
                         if (e != null && e.isEqual(key, hash)) {
                             return e;
                         }
@@ -129,8 +129,8 @@ public abstract class AbstractConcurrentMap<K, V> extends AbstractConcurrentMapB
                     }
                     else {
                         Object arr [] = (Object[]) o;
-                        for (int i = 0; i < arr.length; i++) {
-                            Entry e = (Entry) arr[i];
+                        for (Object item : arr) {
+                            Entry e = (Entry) item;
                             if (e != null && e.isEqual(key, hash)) {
                                 e.setValue(value);
                                 return e;
diff --git a/src/main/java/org/codehaus/groovy/util/AbstractConcurrentMapBase.java b/src/main/java/org/codehaus/groovy/util/AbstractConcurrentMapBase.java
index f0625f6..500e3d4 100644
--- a/src/main/java/org/codehaus/groovy/util/AbstractConcurrentMapBase.java
+++ b/src/main/java/org/codehaus/groovy/util/AbstractConcurrentMapBase.java
@@ -68,24 +68,22 @@ public abstract class AbstractConcurrentMapBase {
 
     public int fullSize() {
         int count = 0;
-        for (int i = 0; i < segments.length; i++) {
-            segments[i].lock();
+        for (Segment segment : segments) {
+            segment.lock();
             try {
-                for (int j = 0; j < segments[i].table.length; j++) {
-                    Object o = segments[i].table [j];
+                for (int j = 0; j < segment.table.length; j++) {
+                    Object o = segment.table[j];
                     if (o != null) {
                         if (o instanceof Entry) {
                             count++;
-                        }
-                        else {
-                            Object arr [] = (Object[]) o;
+                        } else {
+                            Object arr[] = (Object[]) o;
                             count += arr.length;
                         }
                     }
                 }
-            }
-            finally {
-                segments[i].unlock();
+            } finally {
+                segment.unlock();
             }
         }
         return count;
@@ -93,30 +91,28 @@ public abstract class AbstractConcurrentMapBase {
 
     public int size() {
         int count = 0;
-        for (int i = 0; i < segments.length; i++) {
-            segments[i].lock();
+        for (Segment segment : segments) {
+            segment.lock();
             try {
-                for (int j = 0; j < segments[i].table.length; j++) {
-                    Object o = segments[i].table [j];
+                for (int j = 0; j < segment.table.length; j++) {
+                    Object o = segment.table[j];
                     if (o != null) {
                         if (o instanceof Entry) {
                             Entry e = (Entry) o;
                             if (e.isValid())
-                              count++;
-                        }
-                        else {
-                            Object arr [] = (Object[]) o;
-                            for (int k = 0; k < arr.length; k++) {
-                                Entry info = (Entry) arr[k];
+                                count++;
+                        } else {
+                            Object arr[] = (Object[]) o;
+                            for (Object value : arr) {
+                                Entry info = (Entry) value;
                                 if (info != null && info.isValid())
                                     count++;
                             }
                         }
                     }
                 }
-            }
-            finally {
-                segments[i].unlock();
+            } finally {
+                segment.unlock();
             }
         }
         return count;
@@ -124,30 +120,28 @@ public abstract class AbstractConcurrentMapBase {
 
     public Collection values() {
         Collection result = new LinkedList();
-        for (int i = 0; i < segments.length; i++) {
-            segments[i].lock();
+        for (Segment segment : segments) {
+            segment.lock();
             try {
-                for (int j = 0; j < segments[i].table.length; j++) {
-                    Object o = segments[i].table [j];
+                for (int j = 0; j < segment.table.length; j++) {
+                    Object o = segment.table[j];
                     if (o != null) {
                         if (o instanceof Entry) {
                             Entry e = (Entry) o;
                             if (e.isValid())
-                              result.add(e);
-                        }
-                        else {
-                            Object arr [] = (Object[]) o;
-                            for (int k = 0; k < arr.length; k++) {
-                                Entry info = (Entry) arr[k];
+                                result.add(e);
+                        } else {
+                            Object arr[] = (Object[]) o;
+                            for (Object value : arr) {
+                                Entry info = (Entry) value;
                                 if (info != null && info.isValid())
                                     result.add(info);
                             }
                         }
                     }
                 }
-            }
-            finally {
-                segments[i].unlock();
+            } finally {
+                segment.unlock();
             }
         }
         return result;
@@ -187,19 +181,17 @@ public abstract class AbstractConcurrentMapBase {
                     else {
                         Object arr [] = (Object[]) o;
                         Object res = null;
-                        for (int i = 0; i < arr.length; i++) {
-                            Entry info = (Entry) arr[i];
+                        for (Object value : arr) {
+                            Entry info = (Entry) value;
                             if (info != null) {
-                                if(info != e) {
-                                  if (info.isValid()) {
-                                     res = put(info, res);
-                                  }
-                                  else {
-                                      newCount--;
-                                  }
-                                }
-                                else {
-                                  newCount--;
+                                if (info != e) {
+                                    if (info.isValid()) {
+                                        res = put(info, res);
+                                    } else {
+                                        newCount--;
+                                    }
+                                } else {
+                                    newCount--;
                                 }
                             }
                         }
@@ -261,8 +253,7 @@ public abstract class AbstractConcurrentMapBase {
             Object[] newTable = new Object[newCount+1 < threshold ? oldCapacity : oldCapacity << 1];
             int sizeMask = newTable.length - 1;
             newCount = 0;
-            for (int i = 0; i < oldCapacity ; i++) {
-                Object o = oldTable[i];
+            for (Object o : oldTable) {
                 if (o != null) {
                     if (o instanceof Entry) {
                         Entry e = (Entry) o;
@@ -271,11 +262,10 @@ public abstract class AbstractConcurrentMapBase {
                             put(e, index, newTable);
                             newCount++;
                         }
-                    }
-                    else {
-                        Object arr [] = (Object[]) o;
-                        for (int j = 0; j < arr.length; j++) {
-                            Entry e = (Entry) arr[j];
+                    } else {
+                        Object arr[] = (Object[]) o;
+                        for (Object value : arr) {
+                            Entry e = (Entry) value;
                             if (e != null && e.isValid()) {
                                 int index = e.getHash() & sizeMask;
                                 put(e, index, newTable);
diff --git a/src/main/java/org/codehaus/groovy/util/ManagedConcurrentLinkedQueue.java b/src/main/java/org/codehaus/groovy/util/ManagedConcurrentLinkedQueue.java
index ab98f72..ea697c2 100644
--- a/src/main/java/org/codehaus/groovy/util/ManagedConcurrentLinkedQueue.java
+++ b/src/main/java/org/codehaus/groovy/util/ManagedConcurrentLinkedQueue.java
@@ -91,8 +91,8 @@ public class ManagedConcurrentLinkedQueue<T> implements Iterable<T> {
      */
     public List<T> values() {
         List<T> result = new ArrayList<T>();
-        for (Iterator<T> itr = iterator(); itr.hasNext(); ) {
-            result.add(itr.next());
+        for (T t : this) {
+            result.add(t);
         }
         return result;
     }
diff --git a/src/main/java/org/codehaus/groovy/vmplugin/v5/JUnit4Utils.java b/src/main/java/org/codehaus/groovy/vmplugin/v5/JUnit4Utils.java
index 621bc39..10ce200 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/v5/JUnit4Utils.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/v5/JUnit4Utils.java
@@ -54,8 +54,7 @@ public class JUnit4Utils {
                 } else {
                     Class testAnnotationClass = loader.loadClass("org.junit.Test");
                     Method[] methods = scriptClass.getMethods();
-                    for (int i = 0; i < methods.length; i++) {
-                        Method method = methods[i];
+                    for (Method method : methods) {
                         annotation = method.getAnnotation(testAnnotationClass);
                         if (annotation != null) {
                             isTest = true;
@@ -89,8 +88,7 @@ public class JUnit4Utils {
             System.out.print(", Failures: " + InvokerHelper.getProperty(result, "failureCount"));
             System.out.println(", Time: " + InvokerHelper.getProperty(result, "runTime"));
             List failures = (List) InvokerHelper.getProperty(result, "failures");
-            for (int i = 0; i < failures.size(); i++) {
-                Object f = failures.get(i);
+            for (Object f : failures) {
                 System.out.println("Test Failure: " + InvokerHelper.getProperty(f, "description"));
                 System.out.println(InvokerHelper.getProperty(f, "trace"));
             }
diff --git a/src/main/java/org/codehaus/groovy/vmplugin/v7/IndyGuardsFiltersAndSignatures.java b/src/main/java/org/codehaus/groovy/vmplugin/v7/IndyGuardsFiltersAndSignatures.java
index d86bcfd..2cffc58 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/v7/IndyGuardsFiltersAndSignatures.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/v7/IndyGuardsFiltersAndSignatures.java
@@ -43,7 +43,6 @@ import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.Map;
 
 import static org.codehaus.groovy.vmplugin.v7.IndyInterface.LOOKUP;
@@ -131,8 +130,8 @@ public class IndyGuardsFiltersAndSignatures {
      * with property map.
      */
     public static Object setBeanProperties(MetaClass mc, Object bean, Map properties) {
-        for (Iterator iter = properties.entrySet().iterator(); iter.hasNext();) {
-            Map.Entry entry = (Map.Entry) iter.next();
+        for (Object o : properties.entrySet()) {
+            Map.Entry entry = (Map.Entry) o;
             String key = entry.getKey().toString();
 
             Object value = entry.getValue();


Mime
View raw message