groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject groovy git commit: Trivial refactoring: remove duplicated code
Date Mon, 05 Feb 2018 01:45:36 GMT
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_6_X f347a8faf -> 78abeb540


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/78abeb54
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/78abeb54
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/78abeb54

Branch: refs/heads/GROOVY_2_6_X
Commit: 78abeb540dd5c2d2c544b3a44b45729bb7079a86
Parents: f347a8f
Author: sunlan <sunlan@apache.org>
Authored: Mon Feb 5 09:04:23 2018 +0800
Committer: sunlan <sunlan@apache.org>
Committed: Mon Feb 5 09:45:31 2018 +0800

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


http://git-wip-us.apache.org/repos/asf/groovy/blob/78abeb54/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(),


Mime
View raw message