groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject [2/4] groovy git commit: Minor refactoring: iterate maps via entrySet
Date Tue, 05 Dec 2017 01:59:58 GMT
Minor refactoring: iterate maps via entrySet

(cherry picked from commit cfbd6d2)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/17c180a5
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/17c180a5
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/17c180a5

Branch: refs/heads/GROOVY_2_5_X
Commit: 17c180a5b9e5d341709d38a17e4de52269729a44
Parents: c3b070e
Author: sunlan <sunlan@apache.org>
Authored: Tue Dec 5 08:28:50 2017 +0800
Committer: sunlan <sunlan@apache.org>
Committed: Tue Dec 5 09:59:38 2017 +0800

----------------------------------------------------------------------
 .../apache/groovy/ast/tools/ClassNodeUtils.java    |  6 +++---
 .../groovy/tools/javac/JavaStubGenerator.java      |  5 +++--
 .../ASTTransformationCollectorCodeVisitor.java     |  5 +++--
 .../groovy/ant/AntProjectPropertiesDelegate.java   |  8 +++-----
 .../tools/groovydoc/SimpleGroovyRootDoc.java       | 17 ++++++++++-------
 .../groovy/xml/streamingmarkupsupport/Builder.java | 15 +++++++--------
 6 files changed, 29 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/17c180a5/src/main/org/apache/groovy/ast/tools/ClassNodeUtils.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/groovy/ast/tools/ClassNodeUtils.java b/src/main/org/apache/groovy/ast/tools/ClassNodeUtils.java
index 77509d0..98e0fe2 100644
--- a/src/main/org/apache/groovy/ast/tools/ClassNodeUtils.java
+++ b/src/main/org/apache/groovy/ast/tools/ClassNodeUtils.java
@@ -90,10 +90,10 @@ public class ClassNodeUtils {
         // add in unimplemented abstract methods from the interfaces
         for (ClassNode iface : cNode.getInterfaces()) {
             Map<String, MethodNode> ifaceMethodsMap = iface.getDeclaredMethodsMap();
-            for (String methSig : ifaceMethodsMap.keySet()) {
+            for (Map.Entry<String, MethodNode> entry : ifaceMethodsMap.entrySet())
{
+                String methSig = entry.getKey();
                 if (!methodsMap.containsKey(methSig)) {
-                    MethodNode methNode = ifaceMethodsMap.get(methSig);
-                    methodsMap.put(methSig, methNode);
+                    methodsMap.put(methSig, entry.getValue());
                 }
             }
         }

http://git-wip-us.apache.org/repos/asf/groovy/blob/17c180a5/src/main/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/tools/javac/JavaStubGenerator.java b/src/main/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
index a5dd6cc..a8674b0 100644
--- a/src/main/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
+++ b/src/main/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
@@ -848,10 +848,11 @@ public class JavaStubGenerator {
         out.print("@" + annotation.getClassNode().getName().replace('$', '.') + "(");
         boolean first = true;
         Map<String, Expression> members = annotation.getMembers();
-        for (String key : members.keySet()) {
+        for (Map.Entry<String, Expression> entry : members.entrySet()) {
+            String key = entry.getKey();
             if (first) first = false;
             else out.print(", ");
-            out.print(key + "=" + getAnnotationValue(members.get(key)).replace('$', '.'));
+            out.print(key + "=" + getAnnotationValue(entry.getValue()).replace('$', '.'));
         }
         out.print(") ");
     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/17c180a5/src/main/org/codehaus/groovy/transform/ASTTransformationCollectorCodeVisitor.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/transform/ASTTransformationCollectorCodeVisitor.java
b/src/main/org/codehaus/groovy/transform/ASTTransformationCollectorCodeVisitor.java
index 465e7b1..7629ee7 100644
--- a/src/main/org/codehaus/groovy/transform/ASTTransformationCollectorCodeVisitor.java
+++ b/src/main/org/codehaus/groovy/transform/ASTTransformationCollectorCodeVisitor.java
@@ -144,8 +144,9 @@ public class ASTTransformationCollectorCodeVisitor extends ClassCodeVisitorSuppo
 
     private static void deleteExisting(boolean mergeParams, Map<Integer, List<AnnotationNode>>
existingMap, List<AnnotationNode> replacements) {
         for (AnnotationNode replacement : replacements) {
-            for (Integer key : existingMap.keySet()) {
-                List<AnnotationNode> annotationNodes = new ArrayList<AnnotationNode>(existingMap.get(key));
+            for (Map.Entry<Integer, List<AnnotationNode>> entry : existingMap.entrySet())
{
+                Integer key = entry.getKey();
+                List<AnnotationNode> annotationNodes = new ArrayList<AnnotationNode>(entry.getValue());
                 Iterator<AnnotationNode> iterator = annotationNodes.iterator();
                 while (iterator.hasNext()) {
                     AnnotationNode existing = iterator.next();

http://git-wip-us.apache.org/repos/asf/groovy/blob/17c180a5/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/AntProjectPropertiesDelegate.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/AntProjectPropertiesDelegate.java
b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/AntProjectPropertiesDelegate.java
index 12a6048..b02c22a 100644
--- a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/AntProjectPropertiesDelegate.java
+++ b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/AntProjectPropertiesDelegate.java
@@ -100,11 +100,9 @@ public class AntProjectPropertiesDelegate extends Hashtable {
     }
 
     public synchronized void putAll(Map t) {
-        Set keySet = t.keySet();
-        for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
-            Object key = iterator.next();
-            Object value = t.get(key);
-            put(key, value);
+        for (Object e : t.entrySet()) {
+            Map.Entry entry = (Map.Entry) e;
+            put(entry.getKey(), entry.getValue());
         }
     }
 

http://git-wip-us.apache.org/repos/asf/groovy/blob/17c180a5/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyRootDoc.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyRootDoc.java
b/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyRootDoc.java
index 7c9c172..cc0dd1b 100644
--- a/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyRootDoc.java
+++ b/subprojects/groovy-groovydoc/src/main/java/org/codehaus/groovy/tools/groovydoc/SimpleGroovyRootDoc.java
@@ -43,8 +43,9 @@ public class SimpleGroovyRootDoc extends SimpleGroovyDoc implements GroovyRootDo
 
     public GroovyClassDoc classNamed(GroovyClassDoc groovyClassDoc, String name) {
         // look for full match or match excluding package
-        for (String key : classDocs.keySet()) {
-            if (key.equals(name)) return classDocs.get(key);
+        for (Map.Entry<String, GroovyClassDoc> entry : classDocs.entrySet()) {
+            String key = entry.getKey();
+            if (key.equals(name)) return entry.getValue();
             int lastSlashIdx = key.lastIndexOf('/');
             if (lastSlashIdx > 0) {
                 String shortKey = key.substring(lastSlashIdx + 1);
@@ -54,7 +55,7 @@ public class SimpleGroovyRootDoc extends SimpleGroovyDoc implements GroovyRootDo
                 if (hasPackage) fullPathName = fullPathName.substring(0, fullPathName.lastIndexOf('/'));
 
                 if (shortKey.equals(name) && (!hasPackage || key.startsWith(fullPathName)))
{
-                    return classDocs.get(key);
+                    return entry.getValue();
                 }
             }
         }
@@ -62,8 +63,9 @@ public class SimpleGroovyRootDoc extends SimpleGroovyDoc implements GroovyRootDo
     }
 
     public GroovyClassDoc classNamedExact(String name) {
-        for (String key : classDocs.keySet()) {
-            if (key.equals(name)) return classDocs.get(key);
+        for (Map.Entry<String, GroovyClassDoc> entry : classDocs.entrySet()) {
+            String key = entry.getKey();
+            if (key.equals(name)) return entry.getValue();
         }
         return null;
     }
@@ -120,11 +122,12 @@ public class SimpleGroovyRootDoc extends SimpleGroovyDoc implements
GroovyRootDo
 
     public Map<String, GroovyClassDoc> getVisibleClasses(List importedClassesAndPackages)
{
         Map<String, GroovyClassDoc> visibleClasses = new LinkedHashMap<String, GroovyClassDoc>();
-        for (String fullClassName : classDocs.keySet()) {
+        for (Map.Entry<String, GroovyClassDoc> entry : classDocs.entrySet()) {
+            String fullClassName = entry.getKey();
             String equivalentPackageImport = fullClassName.replaceAll("[^/]+$", "*");
             if (importedClassesAndPackages.contains(fullClassName) ||
                     importedClassesAndPackages.contains(equivalentPackageImport)) {
-                GroovyClassDoc classDoc = classDocs.get(fullClassName);
+                GroovyClassDoc classDoc = entry.getValue();
                 visibleClasses.put(classDoc.name(), classDoc);
             }
         }

http://git-wip-us.apache.org/repos/asf/groovy/blob/17c180a5/subprojects/groovy-xml/src/main/java/groovy/xml/streamingmarkupsupport/Builder.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-xml/src/main/java/groovy/xml/streamingmarkupsupport/Builder.java
b/subprojects/groovy-xml/src/main/java/groovy/xml/streamingmarkupsupport/Builder.java
index 9b1c39d..a48ac7a 100644
--- a/subprojects/groovy-xml/src/main/java/groovy/xml/streamingmarkupsupport/Builder.java
+++ b/subprojects/groovy-xml/src/main/java/groovy/xml/streamingmarkupsupport/Builder.java
@@ -30,14 +30,13 @@ public abstract class Builder extends GroovyObjectSupport {
     protected final Map namespaceMethodMap = new HashMap();
     
     public Builder(final Map namespaceMethodMap) {
-    final Iterator keyIterator = namespaceMethodMap.keySet().iterator();
-        
-        while (keyIterator.hasNext()) {
-        final Object key = keyIterator.next();
-        final List value = (List)namespaceMethodMap.get(key);
-        final Closure dg = ((Closure)value.get(1)).asWritable();
-        
-            this.namespaceMethodMap.put(key, new Object[]{value.get(0), dg, fettleMethodMap(dg,
(Map)value.get(2))});
+        for (Object e : namespaceMethodMap.entrySet()) {
+            Map.Entry entry = (Map.Entry) e;
+            final Object key = entry.getKey();
+            final List value = (List) entry.getValue();
+            final Closure dg = ((Closure) value.get(1)).asWritable();
+
+            this.namespaceMethodMap.put(key, new Object[] { value.get(0), dg, fettleMethodMap(dg,
(Map) value.get(2)) });
         }
     }
     


Mime
View raw message