use receiver type as owner when calling Java methods
This commit is contained in:
@@ -680,16 +680,21 @@ public class ExpressionCodegen extends JetVisitor {
|
|||||||
Method methodDescriptor;
|
Method methodDescriptor;
|
||||||
if (declarationPsiElement instanceof PsiMethod) {
|
if (declarationPsiElement instanceof PsiMethod) {
|
||||||
PsiMethod psiMethod = (PsiMethod) declarationPsiElement;
|
PsiMethod psiMethod = (PsiMethod) declarationPsiElement;
|
||||||
|
String owner = JetTypeMapper.jvmName(psiMethod.getContainingClass());
|
||||||
methodDescriptor = getMethodDescriptor(psiMethod);
|
methodDescriptor = getMethodDescriptor(psiMethod);
|
||||||
final boolean isStatic = psiMethod.hasModifierProperty(PsiModifier.STATIC);
|
final boolean isStatic = psiMethod.hasModifierProperty(PsiModifier.STATIC);
|
||||||
|
|
||||||
if (!isStatic) {
|
if (!isStatic) {
|
||||||
ensureReceiverOnStack(expression);
|
ensureReceiverOnStack(expression);
|
||||||
|
if (expression.getParent() instanceof JetQualifiedExpression) {
|
||||||
|
final JetExpression receiver = ((JetQualifiedExpression) expression.getParent()).getReceiverExpression();
|
||||||
|
owner = expressionType(receiver).getInternalName();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
pushMethodArguments(expression, methodDescriptor);
|
pushMethodArguments(expression, methodDescriptor);
|
||||||
|
|
||||||
v.visitMethodInsn(isStatic ? Opcodes.INVOKESTATIC : Opcodes.INVOKEVIRTUAL,
|
v.visitMethodInsn(isStatic ? Opcodes.INVOKESTATIC : Opcodes.INVOKEVIRTUAL,
|
||||||
JetTypeMapper.jvmName(psiMethod.getContainingClass()),
|
owner,
|
||||||
methodDescriptor.getName(),
|
methodDescriptor.getName(),
|
||||||
methodDescriptor.getDescriptor());
|
methodDescriptor.getDescriptor());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -393,4 +393,11 @@ public class NamespaceGenTest extends CodegenTestCase {
|
|||||||
main.invoke(null, l);
|
main.invoke(null, l);
|
||||||
assertEquals(10, l.get(0).intValue());
|
assertEquals(10, l.get(0).intValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testCallMethodDeclaredInSuperclass() throws Exception {
|
||||||
|
loadText("fun foo(sb: StringBuilder) = sb.charAt(0)");
|
||||||
|
final Method main = generateFunction();
|
||||||
|
final StringBuilder sb = new StringBuilder("x");
|
||||||
|
assertEquals('x', ((Character) main.invoke(null, sb)).charValue());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user