|
20 | 20 |
|
21 | 21 | import org.apache.groovy.util.Maps;
|
22 | 22 | import org.codehaus.groovy.GroovyBugError;
|
23 |
| -import org.codehaus.groovy.ast.ClassHelper; |
24 | 23 | import org.codehaus.groovy.ast.ClassNode;
|
25 | 24 | import org.codehaus.groovy.ast.GenericsType;
|
26 | 25 | import org.codehaus.groovy.ast.GenericsType.GenericsTypeName;
|
|
93 | 92 | import static org.codehaus.groovy.ast.ClassHelper.byte_TYPE;
|
94 | 93 | import static org.codehaus.groovy.ast.ClassHelper.char_TYPE;
|
95 | 94 | import static org.codehaus.groovy.ast.ClassHelper.double_TYPE;
|
| 95 | +import static org.codehaus.groovy.ast.ClassHelper.findSAM; |
96 | 96 | import static org.codehaus.groovy.ast.ClassHelper.float_TYPE;
|
97 | 97 | import static org.codehaus.groovy.ast.ClassHelper.getUnwrapper;
|
98 | 98 | import static org.codehaus.groovy.ast.ClassHelper.getWrapper;
|
@@ -913,16 +913,30 @@ && isPrimitiveType(unwrapCompare)
|
913 | 913 | if (receiver == UNKNOWN_PARAMETER_TYPE) {
|
914 | 914 | return dist;
|
915 | 915 | }
|
| 916 | + // GRECLIPSE add -- GROOVY-9852, GROOVY-9881 |
| 917 | + if (compare.isInterface()) { MethodNode sam; |
| 918 | + if (receiver.implementsInterface(compare)) { |
| 919 | + return dist + getMaximumInterfaceDistance(receiver, compare); |
| 920 | + } else if (receiver.equals(CLOSURE_TYPE) && (sam = findSAM(compare)) != null) { |
| 921 | + // GROOVY-9881: in case of multiple overloads, give preference to equal parameter count |
| 922 | + Integer closureParamCount = receiver.getNodeMetaData(StaticTypesMarker.CLOSURE_ARGUMENTS); |
| 923 | + if (closureParamCount != null && closureParamCount == sam.getParameters().length) dist -= 1; |
916 | 924 |
|
917 |
| - ClassNode ref = isPrimitiveType(receiver) && !isPrimitiveType(compare) ? ClassHelper.getWrapper(receiver) : receiver; |
| 925 | + return dist + 13; // GROOVY-9852: @FunctionalInterface vs Object |
| 926 | + } |
| 927 | + } |
| 928 | + // GRECLIPSE end |
| 929 | + ClassNode ref = isPrimitiveType(receiver) && !isPrimitiveType(compare) ? getWrapper(receiver) : receiver; |
918 | 930 | while (ref != null) {
|
| 931 | + /* GRECLIPSE edit |
919 | 932 | if (compare.equals(ref)) {
|
920 | 933 | break;
|
921 | 934 | }
|
922 | 935 | if (compare.isInterface() && ref.implementsInterface(compare)) {
|
923 | 936 | dist += getMaximumInterfaceDistance(ref, compare);
|
924 | 937 | break;
|
925 | 938 | }
|
| 939 | + */ |
926 | 940 | ref = ref.getSuperClass();
|
927 | 941 | dist += 1;
|
928 | 942 | if (OBJECT_TYPE.equals(ref))
|
|
0 commit comments