groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject groovy git commit: Minor refactoring: remove duplicated code
Date Fri, 18 May 2018 14:48:23 GMT
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_6_X 8291749bb -> 1f380d2a5


Minor refactoring: remove duplicated code

(cherry picked from commit 86e27aa)


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

Branch: refs/heads/GROOVY_2_6_X
Commit: 1f380d2a58e8ebd59a44a0fcb6b6ae838f44bda1
Parents: 8291749
Author: sunlan <sunlan@apache.org>
Authored: Fri May 18 22:47:19 2018 +0800
Committer: sunlan <sunlan@apache.org>
Committed: Fri May 18 22:48:18 2018 +0800

----------------------------------------------------------------------
 .../codehaus/groovy/ast/tools/GenericsUtils.java   |  9 ++++-----
 .../transform/stc/StaticTypeCheckingVisitor.java   | 17 ++++++-----------
 2 files changed, 10 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/1f380d2a/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java b/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java
index 27f2bd9..2e8a103 100644
--- a/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java
+++ b/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java
@@ -198,13 +198,12 @@ public class GenericsUtils {
         }
     }
 
-    private static String toGenericTypesString(GenericsType[] genericsTypes) {
+    public static String toGenericTypesString(GenericsType[] genericsTypes) {
         if (genericsTypes == null) return "";
         StringBuilder sb = new StringBuilder("<");
-        for (int i = 0; i < genericsTypes.length; i++) {
-            final GenericsType genericsType = genericsTypes[i];
-            sb.append(genericsType.toString());
-            if (i < genericsTypes.length - 1) {
+        for (int i = 0, n = genericsTypes.length; i < n; i++) {
+            sb.append(genericsTypes[i].toString());
+            if (i < n - 1) {
                 sb.append(",");
             }
         }

http://git-wip-us.apache.org/repos/asf/groovy/blob/1f380d2a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
index 5369ffe..8b0f70e 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -169,6 +169,7 @@ import static org.codehaus.groovy.ast.tools.GeneralUtils.binX;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.callX;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.castX;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.varX;
+import static org.codehaus.groovy.ast.tools.GenericsUtils.toGenericTypesString;
 import static org.codehaus.groovy.ast.tools.WideningCategories.LowestUpperBoundClassNode;
 import static org.codehaus.groovy.ast.tools.WideningCategories.isBigDecCategory;
 import static org.codehaus.groovy.ast.tools.WideningCategories.isBigIntCategory;
@@ -5167,17 +5168,11 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport
{
 
     private static String toMethodGenericTypesString(MethodNode node) {
         GenericsType[] genericsTypes = node.getGenericsTypes();
-        if (genericsTypes == null) return "";
-        StringBuilder sb = new StringBuilder("<");
-        for (int i = 0; i < genericsTypes.length; i++) {
-            final GenericsType genericsType = genericsTypes[i];
-            sb.append(genericsType.toString());
-            if (i < genericsTypes.length - 1) {
-                sb.append(",");
-            }
-        }
-        sb.append("> ");
-        return sb.toString();
+
+        if (genericsTypes == null)
+            return "";
+
+        return toGenericTypesString(genericsTypes);
     }
 
     protected static String formatArgumentList(ClassNode[] nodes) {


Mime
View raw message