You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2017/09/25 12:12:59 UTC
[2/2] groovy git commit: Minor refactoring: remove duplicated code
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/d3717915
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/d3717915
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/d3717915
Branch: refs/heads/GROOVY_2_6_X
Commit: d37179152f03658802787f60d1a60b17fac043ab
Parents: ef4e30a
Author: sunlan <su...@apache.org>
Authored: Mon Sep 25 19:32:15 2017 +0800
Committer: sunlan <su...@apache.org>
Committed: Mon Sep 25 20:12:50 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/d3717915/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());
}