groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject groovy git commit: Disambiguate methods by name
Date Wed, 31 Jan 2018 05:04:16 GMT
Repository: groovy
Updated Branches:
  refs/heads/native-lambda a4de62c89 -> 2823724cd


Disambiguate methods by name


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

Branch: refs/heads/native-lambda
Commit: 2823724cdf44eb3b35b771c7ca8ef3646b9a1693
Parents: a4de62c
Author: sunlan <sunlan@apache.org>
Authored: Wed Jan 31 13:04:10 2018 +0800
Committer: sunlan <sunlan@apache.org>
Committed: Wed Jan 31 13:04:10 2018 +0800

----------------------------------------------------------------------
 .../groovy/classgen/asm/InvocationWriter.java   | 12 ++++++++--
 .../stc/StaticTypeCheckingVisitor.java          | 24 ++++++++++++++++++--
 2 files changed, 32 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/2823724c/src/main/java/org/codehaus/groovy/classgen/asm/InvocationWriter.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/InvocationWriter.java b/src/main/java/org/codehaus/groovy/classgen/asm/InvocationWriter.java
index b9e1011..bfb9f7d 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/InvocationWriter.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/InvocationWriter.java
@@ -484,9 +484,17 @@ public class InvocationWriter {
             return false;
         }
 
-        ClassNode type = call.getObjectExpression().getType();
+        Expression objectExpression = call.getObjectExpression();
+
+        if (null == objectExpression) {
+            return false;
+        }
+
+        if (AsmClassGenerator.isThisExpression(objectExpression)) {
+            return false;
+        }
 
-        if (ClassHelper.isFunctionInterface(type)) {
+        if (ClassHelper.isFunctionInterface(objectExpression.getType())) {
             return true;
         }
 

http://git-wip-us.apache.org/repos/asf/groovy/blob/2823724c/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 d2e9bb2..2e4dc2e 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -3164,6 +3164,8 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport
{
                         addCategoryMethodCallError(call);
                     }
                     mn = disambiguateMethods(mn, chosenReceiver!=null?chosenReceiver.getType():null,
args, call);
+
+
                     if (mn.size() == 1) {
                         MethodNode directMethodCallCandidate = mn.get(0);
                         if (call.getNodeMetaData(StaticTypesMarker.DYNAMIC_RESOLUTION) ==
null &&
@@ -3958,7 +3960,7 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport
{
         return null;
     }
 
-    private List<MethodNode> disambiguateMethods(List<MethodNode> methods, ClassNode
receiver, ClassNode[] argTypes, final Expression expr) {
+    private List<MethodNode> disambiguateMethods(List<MethodNode> methods, ClassNode
receiver, ClassNode[] argTypes, final Expression call) {
         if (methods.size()>1 && receiver!=null && argTypes!=null) {
             List<MethodNode> filteredWithGenerics = new LinkedList<MethodNode>();
             for (MethodNode methodNode : methods) {
@@ -3969,8 +3971,26 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport
{
             if (filteredWithGenerics.size()==1) {
                 return filteredWithGenerics;
             }
-            methods = extension.handleAmbiguousMethods(methods, expr);
+            methods = extension.handleAmbiguousMethods(methods, call);
         }
+
+        if (methods.size() > 1) {
+            if (call instanceof MethodCall) {
+                List<MethodNode> methodNodeList = new LinkedList<>();
+
+                String methodName = ((MethodCall) call).getMethodAsString();
+
+                for (MethodNode methodNode : methods) {
+                    if (!methodNode.getName().equals(methodName)) {
+                        continue;
+                    }
+                    methodNodeList.add(methodNode);
+                }
+
+                methods = methodNodeList;
+            }
+        }
+
         return methods;
     }
 


Mime
View raw message