groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject [groovy] branch master updated: GROOVY-9008: Tweak the error message
Date Fri, 12 Apr 2019 16:48:55 GMT
This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new d744dfb  GROOVY-9008: Tweak the error message
d744dfb is described below

commit d744dfbbdc0741750e3af0b233c46af298a1e724
Author: Daniel Sun <sunlan@apache.org>
AuthorDate: Sat Apr 13 00:47:35 2019 +0800

    GROOVY-9008: Tweak the error message
---
 .../sc/StaticTypesMethodReferenceExpressionWriter.java    | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesMethodReferenceExpressionWriter.java
b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesMethodReferenceExpressionWriter.java
index 031fa76..fa12832 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesMethodReferenceExpressionWriter.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesMethodReferenceExpressionWriter.java
@@ -43,6 +43,7 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.stream.Collectors;
 
 import static org.codehaus.groovy.ast.tools.GeneralUtils.args;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.block;
@@ -57,7 +58,7 @@ import static org.codehaus.groovy.transform.stc.StaticTypesMarker.CLOSURE_ARGUME
  * @since 3.0.0
  */
 public class StaticTypesMethodReferenceExpressionWriter extends MethodReferenceExpressionWriter
implements AbstractFunctionalInterfaceWriter {
-    private static final String MR_EXPR_INSTANCE = "__MR_EXPR_INSTANCE";
+    private static final String METHODREF_EXPR_INSTANCE = "__METHODREF_EXPR_INSTANCE";
 
     public StaticTypesMethodReferenceExpressionWriter(WriterController controller) {
         super(controller);
@@ -103,7 +104,11 @@ public class StaticTypesMethodReferenceExpressionWriter extends MethodReferenceE
 
         if (null == methodRefMethod) {
             throw new GroovyRuntimeException("Failed to find the expected method["
-                    + methodRefName + "(" + Arrays.asList(parametersWithExactType) + ")]
in type[" + typeOrTargetRefType.getName() + "]");
+                    + methodRefName + "("
+                    + Arrays.stream(parametersWithExactType)
+                            .map(e -> e.getType().getName())
+                            .collect(Collectors.joining(","))
+                    + ")] in the type[" + typeOrTargetRefType.getName() + "]");
         }
 
         methodRefMethod.putNodeMetaData(ORIGINAL_PARAMETERS_WITH_EXACT_TYPE, parametersWithExactType);
@@ -190,7 +195,7 @@ public class StaticTypesMethodReferenceExpressionWriter extends MethodReferenceE
 
         if (!(isClassExpr(methodRef))) {
             ClassNode methodRefTargetType = methodRef.getType();
-            prependParameter(methodReferenceSharedVariableList, MR_EXPR_INSTANCE, methodRefTargetType);
+            prependParameter(methodReferenceSharedVariableList, METHODREF_EXPR_INSTANCE,
methodRefTargetType);
         }
 
         return BytecodeHelper.getMethodDescriptor(functionalInterfaceType.redirect(), methodReferenceSharedVariableList.toArray(Parameter.EMPTY_ARRAY));
@@ -270,7 +275,9 @@ public class StaticTypesMethodReferenceExpressionWriter extends MethodReferenceE
 
         return candidates.stream()
                 .map(e -> Tuple.tuple(e, matchingScore(e, methodRef)))
-                .min((t1, t2) -> Integer.compare(t2.getV2(), t1.getV2())).map(Tuple2::getV1).orElse(null);
+                .min((t1, t2) -> Integer.compare(t2.getV2(), t1.getV2()))
+                .map(Tuple2::getV1)
+                .orElse(null);
     }
 
     private static Integer matchingScore(MethodNode mn, Expression typeOrTargetRef) {


Mime
View raw message