groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject [2/2] groovy git commit: Minor refactoring: reuse `findActualTypeByPlaceholderName`
Date Sun, 13 May 2018 16:07:10 GMT
Minor refactoring: reuse `findActualTypeByPlaceholderName`

(cherry picked from commit b8b5bd5)


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

Branch: refs/heads/GROOVY_2_5_X
Commit: b8fb3beca97da3babc70d00fc84961791b40f9a9
Parents: bfe91af
Author: sunlan <sunlan@apache.org>
Authored: Mon May 14 00:00:34 2018 +0800
Committer: sunlan <sunlan@apache.org>
Committed: Mon May 14 00:06:54 2018 +0800

----------------------------------------------------------------------
 .../groovy/transform/stc/StaticTypeCheckingSupport.java | 12 ++++--------
 .../groovy/transform/stc/StaticTypeCheckingVisitor.java |  8 ++++----
 2 files changed, 8 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/b8fb3bec/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
index b3ca258..5843aa3 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
@@ -1183,14 +1183,10 @@ public abstract class StaticTypeCheckingSupport {
         return isExtensionMethodNode ? 0 : 1;
     }
 
-    private static ClassNode findGenericsTypeByPlaceholderName(String placeholderName, Map<String,
GenericsType> placeholderInfo) {
-        for (Map.Entry<String, GenericsType> entry : placeholderInfo.entrySet()) {
-            if (placeholderName.equals(entry.getKey())) {
-                return entry.getValue().getType();
-            }
-        }
+    public static ClassNode findActualTypeByPlaceholderName(String placeholderName, Map<String,
GenericsType> placeholderInfo) {
+        GenericsType gt = placeholderInfo.get(placeholderName);
 
-        return null;
+        return null == gt ? null : gt.getType().redirect();
     }
 
     private static Parameter[] makeRawTypes(Parameter[] params, ClassNode declaringClassForDistance,
ClassNode actualReceiverForDistance) {
@@ -1200,7 +1196,7 @@ public abstract class StaticTypeCheckingSupport {
         for (int i = 0; i < params.length; i++) {
             Parameter oldP = params[i];
 
-            ClassNode actualType = findGenericsTypeByPlaceholderName(oldP.getType().getUnresolvedName(),
placeholderInfo);
+            ClassNode actualType = findActualTypeByPlaceholderName(oldP.getType().getUnresolvedName(),
placeholderInfo);
             Parameter newP = new Parameter(makeRawType(null == actualType ? oldP.getType()
: actualType), oldP.getName());
             newParam[i] = newP;
         }

http://git-wip-us.apache.org/repos/asf/groovy/blob/b8fb3bec/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 b7ad3fe..edddd7d 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -217,6 +217,7 @@ import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.choose
 import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.evaluateExpression;
 import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.extractGenericsConnections;
 import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.extractGenericsParameterMapOfThis;
+import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.findActualTypeByPlaceholderName;
 import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.findDGMMethodsByNameAndArguments;
 import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.findSetters;
 import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.findTargetVariable;
@@ -594,11 +595,10 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport
{
             ClassNode parameterizedType = GenericsUtils.findParameterizedType(fieldNode.getDeclaringClass(),
typeCheckingContext.getEnclosingClassNode());
             if (null != parameterizedType) {
                 ClassNode originalType = fieldNode.getOriginType();
-                GenericsType gt = GenericsUtils.extractPlaceholders(parameterizedType).get(originalType.getUnresolvedName());
+                ClassNode actualType = findActualTypeByPlaceholderName(originalType.getUnresolvedName(),
GenericsUtils.extractPlaceholders(parameterizedType));
 
-                if (null != gt) {
-                    ClassNode redirect = gt.getType().redirect();
-                    storeType(vexp, redirect);
+                if (null != actualType) {
+                    storeType(vexp, actualType);
                     return;
                 }
             }


Mime
View raw message