groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject [1/2] groovy git commit: Minor refactoring: remove duplicated code
Date Mon, 25 Sep 2017 12:12:58 GMT
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_6_X ef4e30aa7 -> 120f252a8


Minor refactoring: remove duplicated code

(cherry picked from commit 7ddc324)


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

Branch: refs/heads/GROOVY_2_6_X
Commit: 120f252a8fa377d307558ce89541caaabdc477c0
Parents: d371791
Author: sunlan <sunlan@apache.org>
Authored: Mon Sep 25 19:42:46 2017 +0800
Committer: sunlan <sunlan@apache.org>
Committed: Mon Sep 25 20:12:50 2017 +0800

----------------------------------------------------------------------
 src/main/org/codehaus/groovy/ast/ClassNode.java | 25 ++++++++++----------
 1 file changed, 13 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/120f252a/src/main/org/codehaus/groovy/ast/ClassNode.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/ast/ClassNode.java b/src/main/org/codehaus/groovy/ast/ClassNode.java
index f7ad48d..8c9bac1 100644
--- a/src/main/org/codehaus/groovy/ast/ClassNode.java
+++ b/src/main/org/codehaus/groovy/ast/ClassNode.java
@@ -537,26 +537,27 @@ public class ClassNode extends AnnotatedNode implements Opcodes, GroovydocHolder
     }
 
     public void addField(FieldNode node) {
-        final ClassNode r = redirect();
-        node.setDeclaringClass(r);
-        node.setOwner(r);
-        if (r.fields == null)
-            r.fields = new LinkedList<FieldNode> ();
-        if (r.fieldIndex == null)
-            r.fieldIndex = new HashMap<String,FieldNode> ();
-        r.fields.add(node);
-        r.fieldIndex.put(node.getName(), node);
+        addField(node, false);
     }
 
     public void addFieldFirst(FieldNode node) {
+        addField(node, true);
+    }
+
+    private void addField(FieldNode node, boolean isFirst) {
         final ClassNode r = redirect();
         node.setDeclaringClass(r);
         node.setOwner(r);
         if (r.fields == null)
-            r.fields = new LinkedList<FieldNode> ();
+            r.fields = new LinkedList<>();
         if (r.fieldIndex == null)
-            r.fieldIndex = new HashMap<String,FieldNode> ();
-        r.fields.addFirst(node);
+            r.fieldIndex = new HashMap<>();
+
+        if (isFirst)
+            r.fields.addFirst(node);
+        else
+            r.fields.add(node);
+
         r.fieldIndex.put(node.getName(), node);
     }
 


Mime
View raw message