groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject [2/2] groovy git commit: Minor refactoring: remove duplicated code
Date Mon, 25 Sep 2017 12:14:20 GMT
Minor refactoring: remove duplicated code

(cherry picked from commit 92062ba)


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

Branch: refs/heads/GROOVY_2_5_X
Commit: 992aae687ebae13c34bdc8d1b8311ac0ec064036
Parents: a8470e3
Author: sunlan <sunlan@apache.org>
Authored: Mon Sep 25 19:32:15 2017 +0800
Committer: sunlan <sunlan@apache.org>
Committed: Mon Sep 25 20:14:09 2017 +0800

----------------------------------------------------------------------
 .../codehaus/groovy/ast/tools/GeneralUtils.java | 23 ++++++++++----------
 1 file changed, 11 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/992aae68/src/main/org/codehaus/groovy/ast/tools/GeneralUtils.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/ast/tools/GeneralUtils.java b/src/main/org/codehaus/groovy/ast/tools/GeneralUtils.java
index 5b49a12..252d6e3 100644
--- a/src/main/org/codehaus/groovy/ast/tools/GeneralUtils.java
+++ b/src/main/org/codehaus/groovy/ast/tools/GeneralUtils.java
@@ -679,16 +679,20 @@ public class GeneralUtils {
     public static Expression getterThisX(ClassNode annotatedNode, PropertyNode pNode) {
         ClassNode owner = pNode.getDeclaringClass();
         if (annotatedNode.equals(owner)) {
-            String getterName = "get" + MetaClassHelper.capitalize(pNode.getName());
-            boolean existingExplicitGetter = annotatedNode.getMethod(getterName, Parameter.EMPTY_ARRAY)
!= null;
-            if (ClassHelper.boolean_TYPE.equals(pNode.getOriginType()) && !existingExplicitGetter)
{
-                getterName = "is" + MetaClassHelper.capitalize(pNode.getName());
-            }
-            return callThisX(getterName);
+            return callThisX(getterName(annotatedNode, pNode));
         }
         return propX(new VariableExpression("this"), pNode.getName());
     }
 
+    private static String getterName(ClassNode annotatedNode, PropertyNode pNode) {
+        String getterName = "get" + MetaClassHelper.capitalize(pNode.getName());
+        boolean existingExplicitGetter = annotatedNode.getMethod(getterName, Parameter.EMPTY_ARRAY)
!= null;
+        if (ClassHelper.boolean_TYPE.equals(pNode.getOriginType()) && !existingExplicitGetter)
{
+            getterName = "is" + MetaClassHelper.capitalize(pNode.getName());
+        }
+        return getterName;
+    }
+
     /**
      * This method is similar to {@link #propX(Expression, Expression)} but will make sure
that if the property
      * being accessed is defined inside the classnode provided as a parameter, then a getter
call is generated
@@ -701,12 +705,7 @@ public class GeneralUtils {
     public static Expression getterX(ClassNode annotatedNode, Expression receiver, PropertyNode
pNode) {
         ClassNode owner = pNode.getDeclaringClass();
         if (annotatedNode.equals(owner)) {
-            String getterName = "get" + MetaClassHelper.capitalize(pNode.getName());
-            boolean existingExplicitGetter = annotatedNode.getMethod(getterName, Parameter.EMPTY_ARRAY)
!= null;
-            if (ClassHelper.boolean_TYPE.equals(pNode.getOriginType()) && !existingExplicitGetter)
{
-                getterName = "is" + MetaClassHelper.capitalize(pNode.getName());
-            }
-            return callX(receiver, getterName);
+            return callX(receiver, getterName(annotatedNode, pNode));
         }
         return propX(receiver, pNode.getName());
     }


Mime
View raw message