Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_5_X 82f1d4c4a -> 32752f268


Trivial refactoring: remove duplicated code

(cherry picked from commit 6f73fb9)


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

Branch: refs/heads/GROOVY_2_5_X
Commit: 32752f26855cdfb497f6b3be1271274ed41d250c
Parents: 82f1d4c
Author: sunlan <sun...@apache.org>
Authored: Mon Feb 5 09:04:23 2018 +0800
Committer: sunlan <sun...@apache.org>
Committed: Mon Feb 5 09:46:12 2018 +0800

----------------------------------------------------------------------
 .../transform/AbstractASTTransformation.java    | 54 ++++++++++----------
 1 file changed, 27 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/32752f26/src/main/java/org/codehaus/groovy/transform/AbstractASTTransformation.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/codehaus/groovy/transform/AbstractASTTransformation.java 
b/src/main/java/org/codehaus/groovy/transform/AbstractASTTransformation.java
index e8ca861..4498e95 100644
--- a/src/main/java/org/codehaus/groovy/transform/AbstractASTTransformation.java
+++ b/src/main/java/org/codehaus/groovy/transform/AbstractASTTransformation.java
@@ -141,18 +141,12 @@ public abstract class AbstractASTTransformation 
implements Opcodes, ASTTransform
             return null;
         }
         if (expr instanceof ListExpression) {
-            List<String> list = new ArrayList<String>();
             final ListExpression listExpression = (ListExpression) expr;
             if (isUndefinedMarkerList(listExpression)) {
                 return null;
             }
-            for (Expression itemExpr : listExpression.getExpressions()) {
-                if (itemExpr != null && itemExpr instanceof 
ConstantExpression) {
-                    Object value = ((ConstantExpression) itemExpr).getValue();
-                    if (value != null) list.add(value.toString());
-                }
-            }
-            return list;
+
+            return getValueStringList(listExpression);
         }
         return tokenize(getMemberStringValue(anno, name));
     }
@@ -175,32 +169,32 @@ public abstract class AbstractASTTransformation 
implements Opcodes, ASTTransform
         List<String> list;
         Expression expr = anno.getMember(name);
         if (expr != null && expr instanceof ListExpression) {
-            list = new ArrayList<String>();
             final ListExpression listExpression = (ListExpression) expr;
-            for (Expression itemExpr : listExpression.getExpressions()) {
-                if (itemExpr != null && itemExpr instanceof 
ConstantExpression) {
-                    Object value = ((ConstantExpression) itemExpr).getValue();
-                    if (value != null) list.add(value.toString());
-                }
-            }
+            list = getValueStringList(listExpression);
         } else {
             list = tokenize(getMemberStringValue(anno, name));
         }
         return list;
     }
 
+    private static List<String> getValueStringList(ListExpression 
listExpression) {
+        List<String> list = new ArrayList<String>();
+        for (Expression itemExpr : listExpression.getExpressions()) {
+            if (itemExpr != null && itemExpr instanceof ConstantExpression) {
+                Object value = ((ConstantExpression) itemExpr).getValue();
+                if (value != null) list.add(value.toString());
+            }
+        }
+        return list;
+    }
+
     @Deprecated
     public List<ClassNode> getClassList(AnnotationNode anno, String name) {
         List<ClassNode> list = new ArrayList<ClassNode>();
         Expression expr = anno.getMember(name);
         if (expr != null && expr instanceof ListExpression) {
             final ListExpression listExpression = (ListExpression) expr;
-            for (Expression itemExpr : listExpression.getExpressions()) {
-                if (itemExpr != null && itemExpr instanceof ClassExpression) {
-                    ClassNode cn = itemExpr.getType();
-                    if (cn != null) list.add(cn);
-                }
-            }
+            list = getTypeList(listExpression);
         } else if (expr != null && expr instanceof ClassExpression) {
             ClassNode cn = expr.getType();
             if (cn != null) list.add(cn);
@@ -219,12 +213,7 @@ public abstract class AbstractASTTransformation implements 
Opcodes, ASTTransform
             if (isUndefinedMarkerList(listExpression)) {
                 return null;
             }
-            for (Expression itemExpr : listExpression.getExpressions()) {
-                if (itemExpr != null && itemExpr instanceof ClassExpression) {
-                    ClassNode cn = itemExpr.getType();
-                    if (cn != null) list.add(cn);
-                }
-            }
+            list = getTypeList(listExpression);
         } else if (expr instanceof ClassExpression) {
             ClassNode cn = expr.getType();
             if (isUndefined(cn)) return null;
@@ -233,6 +222,17 @@ public abstract class AbstractASTTransformation implements 
Opcodes, ASTTransform
         return list;
     }
 
+    private static List<ClassNode> getTypeList(ListExpression listExpression) {
+        List<ClassNode> list = new ArrayList<ClassNode>();
+        for (Expression itemExpr : listExpression.getExpressions()) {
+            if (itemExpr != null && itemExpr instanceof ClassExpression) {
+                ClassNode cn = itemExpr.getType();
+                if (cn != null) list.add(cn);
+            }
+        }
+        return list;
+    }
+
     public void addError(String msg, ASTNode expr) {
         sourceUnit.getErrorCollector().addErrorAndContinue(new 
SyntaxErrorMessage(
                         new SyntaxException(msg + '\n', expr.getLineNumber(), 
expr.getColumnNumber(),

Reply via email to