Make JetTypeMapper aware of SAM constructor arguments

This obsoletes 'replaceName' workaround that was present in ClosureCodegen but
missing in other crucial call sites of mapSignature, e.g. generation of
EnclosingMethod info

 #KT-6691 Fixed
This commit is contained in:
Alexander Udalov
2015-02-06 15:50:14 +03:00
parent ca2cfb9859
commit e7a744b315
5 changed files with 50 additions and 11 deletions
@@ -161,8 +161,7 @@ public class ClosureCodegen extends MemberCodegen<JetElement> {
erasedInterfaceFunction = samType.getAbstractMethod().getOriginal();
}
JvmMethodSignature jvmMethodSignature =
typeMapper.mapSignature(funDescriptor).replaceName(erasedInterfaceFunction.getName().toString());
JvmMethodSignature jvmMethodSignature = typeMapper.mapSignature(funDescriptor);
generateBridge(typeMapper.mapSignature(erasedInterfaceFunction).getAsmMethod(), jvmMethodSignature.getAsmMethod());
functionCodegen.generateMethod(OtherOrigin(element, funDescriptor), jvmMethodSignature, funDescriptor, strategy);
@@ -38,7 +38,10 @@ import org.jetbrains.kotlin.load.kotlin.nativeDeclarations.NativeDeclarationsPac
import org.jetbrains.kotlin.name.FqName;
import org.jetbrains.kotlin.name.FqNameUnsafe;
import org.jetbrains.kotlin.name.SpecialNames;
import org.jetbrains.kotlin.psi.JetExpression;
import org.jetbrains.kotlin.psi.JetFile;
import org.jetbrains.kotlin.psi.JetFunctionLiteral;
import org.jetbrains.kotlin.psi.JetFunctionLiteralExpression;
import org.jetbrains.kotlin.resolve.BindingContext;
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils;
import org.jetbrains.kotlin.resolve.DescriptorUtils;
@@ -584,7 +587,7 @@ public class JetTypeMapper {
}
@NotNull
private static String mapFunctionName(@NotNull FunctionDescriptor descriptor) {
private String mapFunctionName(@NotNull FunctionDescriptor descriptor) {
String platformName = getPlatformName(descriptor);
if (platformName != null) return platformName;
@@ -601,7 +604,21 @@ public class JetTypeMapper {
return PropertyCodegen.setterName(property.getName());
}
}
else if (isLocalNamedFun(descriptor) || descriptor instanceof AnonymousFunctionDescriptor) {
else if (isLocalNamedFun(descriptor)) {
return "invoke";
}
else if (descriptor instanceof AnonymousFunctionDescriptor) {
PsiElement element = DescriptorToSourceUtils.callableDescriptorToDeclaration(descriptor);
if (element instanceof JetFunctionLiteral) {
PsiElement expression = element.getParent();
if (expression instanceof JetFunctionLiteralExpression) {
SamType samType = bindingContext.get(SAM_VALUE, (JetExpression) expression);
if (samType != null) {
return samType.getAbstractMethod().getName().asString();
}
}
}
return "invoke";
}
else {