Fix KtUltraLightMethod::getParameterList

There's already a correct override in KtLightMethodImpl
Otherwise the tests is failing because clsDelegate.parameterList
has a wrong parent
This commit is contained in:
Denis Zharkov
2018-10-30 17:56:00 +03:00
parent 3814c7687b
commit 875e9d2a36
8 changed files with 52 additions and 3 deletions
@@ -102,6 +102,7 @@ class KtUltraLightClass(classOrObject: KtClassOrObject, private val support: Ult
// the following logic should be in the platform (super), overrides can be removed once that happens
override fun getInterfaces(): Array<PsiClass> = PsiClassImplUtil.getInterfaces(this)
override fun getSuperClass(): PsiClass? = PsiClassImplUtil.getSuperClass(this)
override fun getSupers(): Array<PsiClass> = PsiClassImplUtil.getSupers(this)
override fun getSuperTypes(): Array<PsiClassType> = PsiClassImplUtil.getSuperTypes(this)
@@ -559,9 +560,13 @@ internal class KtUltraLightMethod(
containingClass: KtUltraLightClass
) : KtLightMethodImpl({ delegate }, LightMemberOriginForDeclaration(originalElement, JvmDeclarationOriginKind.OTHER), containingClass) {
// These two overrides are necessary because ones from KtLightMethodImpl suppose that clsDelegate.returnTypeElement is valid
// While here we only set return type for LightMethodBuilder (see org.jetbrains.kotlin.asJava.classes.KtUltraLightClass.asJavaMethod)
override fun getReturnTypeElement(): PsiTypeElement? = null
override fun getReturnType(): PsiType? = clsDelegate.returnType
override fun getParameterList(): PsiParameterList = clsDelegate.parameterList
override fun buildParametersForList(): List<PsiParameter> = clsDelegate.parameterList.parameters.toList()
// should be in super
override fun isVarArgs() = PsiImplUtil.isVarArgs(this)
@@ -53,10 +53,19 @@ open class KtLightMethodImpl protected constructor(
private val paramsList: PsiParameterList by lazyPub {
KtLightParameterList(this, dummyDelegate?.parameterList?.parametersCount ?: clsDelegate.parameterList.parametersCount) {
clsDelegate.parameterList.parameters.mapIndexed { index, clsParameter -> KtLightParameter(clsParameter, index, this@KtLightMethodImpl) }
buildParametersForList()
}
}
protected open fun buildParametersForList(): List<PsiParameter> =
clsDelegate.parameterList.parameters.mapIndexed { index, clsParameter ->
KtLightParameter(
clsParameter,
index,
this@KtLightMethodImpl
)
}
private val typeParamsList: PsiTypeParameterList? by lazyPub { buildTypeParameterList() }
protected open fun buildTypeParameterList(): PsiTypeParameterList? {
@@ -253,4 +262,4 @@ val KtLightMethod.isGetter: Boolean
get() = isAccessor(true)
val KtLightMethod.isSetter: Boolean
get() = isAccessor(false)
get() = isAccessor(false)
@@ -0,0 +1,11 @@
package test;
public class MyFunctionType {
public void foo() {
MyFunction<CharSequence, Integer> function1 = (CharSequence x) -> x.length();
bar(x -> x.length());
bar(CharSequence::length);
}
public void bar(MyFunction<CharSequence, Integer> x) {}
}
@@ -0,0 +1,7 @@
package test
public interface MyFunction<in P1, out R> : Function<R> {
public operator fun invoke(p1: P1): R
}
@@ -0,0 +1,2 @@
// LANGUAGE_LEVEL 1.8
// WITH_RUNTIME
@@ -124,6 +124,11 @@ public class JavaAgainstKotlinBinariesCheckerTestGenerated extends AbstractJavaA
runTest("idea/testData/kotlinAndJavaChecker/javaAgainstKotlin/KotlinAnnotations.kt");
}
@TestMetadata("MyFunctionType.kt")
public void testMyFunctionType() throws Exception {
runTest("idea/testData/kotlinAndJavaChecker/javaAgainstKotlin/MyFunctionType.kt");
}
@TestMetadata("ReturnInnerClasses.kt")
public void testReturnInnerClasses() throws Exception {
runTest("idea/testData/kotlinAndJavaChecker/javaAgainstKotlin/ReturnInnerClasses.kt");
@@ -126,6 +126,11 @@ public class JavaAgainstKotlinSourceCheckerTestGenerated extends AbstractJavaAga
runTest("idea/testData/kotlinAndJavaChecker/javaAgainstKotlin/KotlinAnnotations.kt");
}
@TestMetadata("MyFunctionType.kt")
public void testMyFunctionType() throws Exception {
runTest("idea/testData/kotlinAndJavaChecker/javaAgainstKotlin/MyFunctionType.kt");
}
@TestMetadata("ReturnInnerClasses.kt")
public void testReturnInnerClasses() throws Exception {
runTest("idea/testData/kotlinAndJavaChecker/javaAgainstKotlin/ReturnInnerClasses.kt");
@@ -126,6 +126,11 @@ public class JavaAgainstKotlinSourceCheckerWithUltraLightTestGenerated extends A
runTest("idea/testData/kotlinAndJavaChecker/javaAgainstKotlin/KotlinAnnotations.kt");
}
@TestMetadata("MyFunctionType.kt")
public void testMyFunctionType() throws Exception {
runTest("idea/testData/kotlinAndJavaChecker/javaAgainstKotlin/MyFunctionType.kt");
}
@TestMetadata("ReturnInnerClasses.kt")
public void testReturnInnerClasses() throws Exception {
runTest("idea/testData/kotlinAndJavaChecker/javaAgainstKotlin/ReturnInnerClasses.kt");