Repository: groovy
Updated Branches:
  refs/heads/master d8d551e1d -> 6f73fb997


Trivial refactoring: remove duplicated code


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

Branch: refs/heads/master
Commit: 6f73fb99734f3ef722dcc60e0c11072ad9cd8141
Parents: d8d551e
Author: sunlan <sun...@apache.org>
Authored: Mon Feb 5 09:04:23 2018 +0800
Committer: sunlan <sun...@apache.org>
Committed: Mon Feb 5 09:04:23 2018 +0800

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


http://git-wip-us.apache.org/repos/asf/groovy/blob/6f73fb99/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