groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject groovy git commit: Simplify finding generics implementation class
Date Thu, 10 May 2018 11:21:53 GMT
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_6_X 353a7840a -> c7cf36ff2


Simplify finding generics implementation class

(cherry picked from commit e7766ff)


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

Branch: refs/heads/GROOVY_2_6_X
Commit: c7cf36ff29106a737eee407b8995338d969cd8db
Parents: 353a784
Author: sunlan <sunlan@apache.org>
Authored: Thu May 10 19:20:16 2018 +0800
Committer: sunlan <sunlan@apache.org>
Committed: Thu May 10 19:21:49 2018 +0800

----------------------------------------------------------------------
 .../stc/StaticTypeCheckingSupport.java          | 28 +++++++++++---------
 1 file changed, 16 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/c7cf36ff/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 0175601..fa05c45 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
@@ -1215,29 +1215,29 @@ public abstract class StaticTypeCheckingSupport {
      * The resolved types can not help us to choose methods correctly if the argument is
a string:  T: Object, S: Serializable
      * so we need actual types:  T: String, S: Long
      */
-    private static Map<GenericsType, GenericsType> makeDeclaringAndActualGenericsTypeMap(ClassNode
declaringClassForDistance, ClassNode actualReceiverForDistance) {
-        GenericsType[] declaringGenericsTypes = declaringClassForDistance.getGenericsTypes();
-        GenericsType[] actualGenericsTypes = actualReceiverForDistance.getGenericsTypes();
+    private static Map<GenericsType, GenericsType> makeDeclaringAndActualGenericsTypeMap(ClassNode
declaringClass, ClassNode actualReceiver) {
+        GenericsType[] declaringGenericsTypes = declaringClass.getGenericsTypes();
+        GenericsType[] actualGenericsTypes = actualReceiver.getGenericsTypes();
 
         if (null == declaringGenericsTypes) {
             return Collections.emptyMap();
         }
 
         if (null == actualGenericsTypes) {
-            List<ClassNode> superClassAndInterfaceList = getAllSuperClassesAndInterfaces(actualReceiverForDistance);
+            List<ClassNode> superClassAndInterfaceList = getAllSuperClassesAndInterfaces(actualReceiver);
 
             for (ClassNode cn : superClassAndInterfaceList) {
-                if (cn.isDerivedFrom(declaringClassForDistance)) {
+                if (declaringClass.equals(cn.redirect())) {
                     actualGenericsTypes = cn.getGenericsTypes();
 
-                    if (null != actualGenericsTypes && declaringGenericsTypes.length
== actualGenericsTypes.length) {
+                    if (isGenericsTypeArraysLengthEqual(declaringGenericsTypes, actualGenericsTypes))
{
                         break;
                     }
                 }
             }
         }
 
-        if (null == actualGenericsTypes || declaringGenericsTypes.length != actualGenericsTypes.length)
{
+        if (!isGenericsTypeArraysLengthEqual(declaringGenericsTypes, actualGenericsTypes))
{
             return Collections.emptyMap();
         }
 
@@ -1249,11 +1249,15 @@ public abstract class StaticTypeCheckingSupport {
         return result;
     }
 
-    private static List<ClassNode> getAllSuperClassesAndInterfaces(ClassNode actualReceiverForDistance)
{
+    private static boolean isGenericsTypeArraysLengthEqual(GenericsType[] declaringGenericsTypes,
GenericsType[] actualGenericsTypes) {
+        return null != actualGenericsTypes && declaringGenericsTypes.length == actualGenericsTypes.length;
+    }
+
+    private static List<ClassNode> getAllSuperClassesAndInterfaces(ClassNode actualReceiver)
{
         List<ClassNode> superClassAndInterfaceList = new LinkedList<>();
-        List<ClassNode> allSuperClassNodeList = getAllUnresolvedSuperClasses(actualReceiverForDistance);
+        List<ClassNode> allSuperClassNodeList = getAllUnresolvedSuperClasses(actualReceiver);
         superClassAndInterfaceList.addAll(allSuperClassNodeList);
-        superClassAndInterfaceList.addAll(actualReceiverForDistance.getAllInterfaces());
+        superClassAndInterfaceList.addAll(actualReceiver.getAllInterfaces());
 
         for (ClassNode superClassNode : allSuperClassNodeList) {
             superClassAndInterfaceList.addAll(superClassNode.getAllInterfaces());
@@ -1262,10 +1266,10 @@ public abstract class StaticTypeCheckingSupport {
         return superClassAndInterfaceList;
     }
 
-    private static List<ClassNode> getAllUnresolvedSuperClasses(ClassNode actualReceiverForDistance)
{
+    private static List<ClassNode> getAllUnresolvedSuperClasses(ClassNode actualReceiver)
{
         List<ClassNode> superClassNodeList = new LinkedList<>();
 
-        for (ClassNode cn = actualReceiverForDistance.getUnresolvedSuperClass(); null !=
cn && ClassHelper.OBJECT_TYPE != cn; cn = cn.getUnresolvedSuperClass()) {
+        for (ClassNode cn = actualReceiver.getUnresolvedSuperClass(); null != cn &&
ClassHelper.OBJECT_TYPE != cn; cn = cn.getUnresolvedSuperClass()) {
             superClassNodeList.add(cn);
         }
 


Mime
View raw message