New J2K: Fix super call to Kotlin class with implicit constructor

#KT-36159 fixed
This commit is contained in:
Ilya Kirillov
2020-02-13 19:26:24 +03:00
parent 7c586ce736
commit 6b913da698
7 changed files with 37 additions and 1 deletions
@@ -344,7 +344,12 @@ class JavaToJKTreeBuilder constructor(
THIS_KEYWORD -> JKThisExpression(JKLabelEmpty(), JKNoType)
else -> throwCanNotConvertError("unknown keyword in callee position")
}
JKDelegationConstructorCall(symbol as JKMethodSymbol, callee, arguments.toJK())
val calleeSymbol = when {
symbol is JKMethodSymbol -> symbol
target is KtLightMethod -> KtClassImplicitConstructorSymbol(target, typeFactory)
else -> throwCanNotConvertError("Expected constructor call, found ${target?.javaClass?.name}")
}
JKDelegationConstructorCall(calleeSymbol, callee, arguments.toJK())
}
target is KtLightMethod -> {
@@ -134,6 +134,7 @@ class MethodReferenceToLambdaConversion(context: NewJ2kConverterContext) : Recur
is JKMultiverseMethodSymbol -> target.hasModifierProperty(PsiModifier.STATIC)
is JKUniverseMethodSymbol -> target.parent?.parent?.safeAs<JKClass>()?.classKind == JKClass.ClassKind.COMPANION
is JKUnresolvedMethod -> false
is KtClassImplicitConstructorSymbol -> false
}
private val JKMethodSymbol.parameterNames: List<String>?
@@ -143,6 +144,7 @@ class MethodReferenceToLambdaConversion(context: NewJ2kConverterContext) : Recur
is JKMultiverseMethodSymbol -> target.parameters.map { it.name ?: return null }
is JKUniverseMethodSymbol -> target.parameters.map { it.name.value }
is JKUnresolvedMethod -> null
is KtClassImplicitConstructorSymbol -> null
}
}
@@ -101,3 +101,14 @@ class JKUnresolvedMethod(
get() = emptyList()
}
class KtClassImplicitConstructorSymbol(
override val target: KtLightMethod,
override val typeFactory: JKTypeFactory
) : JKMethodSymbol(), JKMultiverseSymbol<KtLightMethod> {
override val receiverType: JKType?
get() = null
override val parameterTypes: List<JKType>?
get() = emptyList()
override val returnType: JKType?
get() = target.returnType?.let(typeFactory::fromPsiType)
}
@@ -0,0 +1,2 @@
open class EmptyTest {
}
@@ -0,0 +1,5 @@
public class TestJ extends EmptyTest {
public TestJ() {
super();
}
}
@@ -0,0 +1 @@
class TestJ : EmptyTest()
@@ -4636,6 +4636,11 @@ public class NewJavaToKotlinConverterSingleFileTestGenerated extends AbstractNew
runTest("nj2k/testData/newJ2k/superExpression/classAextendsB.java");
}
@TestMetadata("kotlinSuperClassWithImplicitConstructor.java")
public void testKotlinSuperClassWithImplicitConstructor() throws Exception {
runTest("nj2k/testData/newJ2k/superExpression/kotlinSuperClassWithImplicitConstructor.java");
}
@TestMetadata("superStatement.java")
public void testSuperStatement() throws Exception {
runTest("nj2k/testData/newJ2k/superExpression/superStatement.java");
@@ -5197,6 +5202,11 @@ public class NewJavaToKotlinConverterSingleFileTestGenerated extends AbstractNew
runTest("nj2k/testData/newJ2k/types/capturedWildcardTypeAsLambdaParameter.java");
}
@TestMetadata("recursiveType.java")
public void testRecursiveType() throws Exception {
runTest("nj2k/testData/newJ2k/types/recursiveType.java");
}
@TestMetadata("unusedCapturedWildcardTypeInSAM.java")
public void testUnusedCapturedWildcardTypeInSAM() throws Exception {
runTest("nj2k/testData/newJ2k/types/unusedCapturedWildcardTypeInSAM.java");