groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject groovy git commit: minor refactor: prepare to remove some duplicated code
Date Thu, 25 Jan 2018 11:13:10 GMT
Repository: groovy
Updated Branches:
  refs/heads/master 7be5f2f82 -> d2706f74b


minor refactor: prepare to remove some duplicated code


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

Branch: refs/heads/master
Commit: d2706f74b2b3f69b5c40a9416c26a77655a44a23
Parents: 7be5f2f
Author: paulk <paulk@asert.com.au>
Authored: Thu Jan 25 21:13:01 2018 +1000
Committer: paulk <paulk@asert.com.au>
Committed: Thu Jan 25 21:13:01 2018 +1000

----------------------------------------------------------------------
 .../codehaus/groovy/ast/tools/GeneralUtils.java |  8 ++--
 .../TupleConstructorASTTransformation.java      | 48 ++++++++++----------
 2 files changed, 28 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/d2706f74/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java b/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java
index b61ae64..807ea7d 100644
--- a/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java
+++ b/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java
@@ -466,16 +466,16 @@ public class GeneralUtils {
         return result;
     }
 
-    public static List<PropertyNode> getAllFields(Set<String> names, ClassNode
cNode, boolean includeProperties, boolean includeFields, boolean allProperties, boolean traverseSuperClasses)
{
-        return getAllFields(names, cNode, cNode, includeProperties, includeFields, allProperties,
traverseSuperClasses);
+    public static List<PropertyNode> getAllProperties(Set<String> names, ClassNode
cNode, boolean includeProperties, boolean includeFields, boolean allProperties, boolean traverseSuperClasses)
{
+        return getAllProperties(names, cNode, cNode, includeProperties, includeFields, allProperties,
traverseSuperClasses);
     }
 
-    private static List<PropertyNode> getAllFields(Set<String> names, ClassNode
origType, ClassNode cNode, boolean includeProperties, boolean includeFields, boolean allProperties,
boolean traverseSuperClasses) {
+    private static List<PropertyNode> getAllProperties(Set<String> names, ClassNode
origType, ClassNode cNode, boolean includeProperties, boolean includeFields, boolean allProperties,
boolean traverseSuperClasses) {
         final List<PropertyNode> result;
         if (cNode == ClassHelper.OBJECT_TYPE || !traverseSuperClasses) {
             result = new ArrayList<PropertyNode>();
         } else {
-            result = getAllFields(names, origType, cNode.getSuperClass(), includeProperties,
includeFields, allProperties, true);
+            result = getAllProperties(names, origType, cNode.getSuperClass(), includeProperties,
includeFields, allProperties, true);
         }
         if (includeProperties) {
             for (PropertyNode pNode : cNode.getProperties()) {

http://git-wip-us.apache.org/repos/asf/groovy/blob/d2706f74/src/main/java/org/codehaus/groovy/transform/TupleConstructorASTTransformation.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/transform/TupleConstructorASTTransformation.java
b/src/main/java/org/codehaus/groovy/transform/TupleConstructorASTTransformation.java
index 179ba1a..7cefac6 100644
--- a/src/main/java/org/codehaus/groovy/transform/TupleConstructorASTTransformation.java
+++ b/src/main/java/org/codehaus/groovy/transform/TupleConstructorASTTransformation.java
@@ -61,7 +61,7 @@ import static org.codehaus.groovy.ast.tools.GeneralUtils.constX;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.copyStatementsWithSuperAdjustment;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.ctorX;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.equalsNullX;
-import static org.codehaus.groovy.ast.tools.GeneralUtils.getAllFields;
+import static org.codehaus.groovy.ast.tools.GeneralUtils.getAllProperties;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.getSetterName;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.ifElseS;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.ifS;
@@ -136,18 +136,9 @@ public class TupleConstructorASTTransformation extends AbstractASTTransformation
                 return;
             }
 
-            // TODO remove duplication between various paths below
-            List<PropertyNode> list = ImmutableASTTransformation.getProperties(cNode,
includeSuperProperties, allProperties);
-            boolean specialHashMapCase = ImmutableASTTransformation.isSpecialHashMapCase(list);
-            if (makeImmutable) {
-                if (!specialHashMapCase) {
-                    ImmutableASTTransformation.createConstructorOrdered(cNode, list);
-                }
-            } else {
-                createConstructor(this, cNode, includeFields, includeProperties, includeSuperFields,
includeSuperProperties,
-                        callSuper, force, excludes, includes, useSetters, defaults, allNames,
allProperties, sourceUnit,
-                        (ClosureExpression) pre, (ClosureExpression) post);
-            }
+            createConstructor(this, cNode, includeFields, includeProperties, includeSuperFields,
includeSuperProperties,
+                    callSuper, force, excludes, includes, useSetters, defaults, allNames,
allProperties, makeImmutable,
+                    sourceUnit, (ClosureExpression) pre, (ClosureExpression) post);
 
             if (pre != null) {
                 anno.setMember("pre", new ClosureExpression(new Parameter[0], EmptyStatement.INSTANCE));
@@ -177,27 +168,36 @@ public class TupleConstructorASTTransformation extends AbstractASTTransformation
                                          List<String> excludes, final List<String>
includes, boolean useSetters, boolean
                                                  defaults, boolean allNames, SourceUnit sourceUnit,
ClosureExpression
                                                  pre, ClosureExpression post) {
-        createConstructor(xform, cNode, includeFields, includeProperties, includeSuperFields,
includeSuperProperties, callSuper, force, excludes, includes, useSetters, defaults, allNames,
false, sourceUnit, pre, post);
+        createConstructor(xform, cNode, includeFields, includeProperties, includeSuperFields,
includeSuperProperties, callSuper, force, excludes, includes, useSetters, defaults, allNames,
false, false, sourceUnit, pre, post);
     }
 
     public static void createConstructor(AbstractASTTransformation xform, ClassNode cNode,
boolean includeFields,
-                                         boolean includeProperties, boolean includeSuperFields,
boolean
-                                                 includeSuperProperties, boolean callSuper,
boolean force,
-                                         List<String> excludes, final List<String>
includes, boolean useSetters, boolean
-                                                 defaults, boolean allNames, boolean allProperties,
SourceUnit sourceUnit, ClosureExpression
-                                                 pre, ClosureExpression post) {
-        // no processing if existing constructors found
-        if (!cNode.getDeclaredConstructors().isEmpty() && !force) return;
-
+                                         boolean includeProperties, boolean includeSuperFields,
boolean includeSuperProperties,
+                                         boolean callSuper, boolean force, List<String>
excludes, final List<String> includes,
+                                         boolean useSetters, boolean defaults, boolean allNames,
boolean allProperties, boolean makeImmutable,
+                                         SourceUnit sourceUnit, ClosureExpression pre, ClosureExpression
post) {
         Set<String> names = new HashSet<String>();
         List<PropertyNode> superList;
         if (includeSuperProperties || includeSuperFields) {
-            superList = getAllFields(names, cNode.getSuperClass(), includeSuperProperties,
includeSuperFields, allProperties, true);
+            superList = getAllProperties(names, cNode.getSuperClass(), includeSuperProperties,
includeSuperFields, allProperties, true);
         } else {
             superList = new ArrayList<PropertyNode>();
         }
 
-        List<PropertyNode> list = getAllFields(names, cNode, true, includeFields, allProperties,
false);
+        List<PropertyNode> list = getAllProperties(names, cNode, true, includeFields,
allProperties, false);
+
+        if (makeImmutable) {
+            boolean specialHashMapCase = (ImmutableASTTransformation.isSpecialHashMapCase(list)
&& superList.isEmpty()) ||
+                    (ImmutableASTTransformation.isSpecialHashMapCase(superList) &&
list.isEmpty());
+            if (!specialHashMapCase) {
+                superList.addAll(list);
+                ImmutableASTTransformation.createConstructorOrdered(cNode, superList);
+            }
+            return;
+        }
+
+        // no processing if existing constructors found
+        if (!cNode.getDeclaredConstructors().isEmpty() && !force) return;
 
         final List<Parameter> params = new ArrayList<Parameter>();
         final List<Expression> superParams = new ArrayList<Expression>();


Mime
View raw message