KtLightMethod: Wrap return type so it resolves to light method's type parameter as opposed to delegate's
Affects java type inference in IDEA #KT-12090 Fixed #KT-11095 Fixed
This commit is contained in:
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.asJava
|
||||
import com.intellij.core.JavaCoreBundle
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import com.intellij.psi.*
|
||||
import com.intellij.psi.impl.compiled.ClsTypeElementImpl
|
||||
import com.intellij.psi.impl.light.LightMethod
|
||||
import com.intellij.psi.scope.PsiScopeProcessor
|
||||
import com.intellij.psi.util.*
|
||||
@@ -40,6 +41,10 @@ sealed class KtLightMethodImpl(
|
||||
override val kotlinOrigin: KtDeclaration? get() = lightMethodOrigin?.originalElement as? KtDeclaration
|
||||
|
||||
private val lightIdentifier by lazy(LazyThreadSafetyMode.PUBLICATION) { KtLightIdentifier(this, kotlinOrigin as? KtNamedDeclaration) }
|
||||
private val returnTypeElem by lazy(LazyThreadSafetyMode.PUBLICATION) {
|
||||
val delegateTypeElement = clsDelegate.returnTypeElement as? ClsTypeElementImpl
|
||||
delegateTypeElement?.let { ClsTypeElementImpl(this, it.canonicalText, /*ClsTypeElementImpl.VARIANCE_NONE */ 0.toChar()) }
|
||||
}
|
||||
|
||||
override fun getContainingClass(): KtLightClass = super.getContainingClass() as KtLightClass
|
||||
|
||||
@@ -178,6 +183,12 @@ sealed class KtLightMethodImpl(
|
||||
override fun getDefaultValue() = clsDelegate.defaultValue
|
||||
}
|
||||
|
||||
// override getReturnType() so return type resolves to type parameters of this method not delegate's
|
||||
// which is relied upon by java type inference
|
||||
override fun getReturnTypeElement(): PsiTypeElement? = returnTypeElem
|
||||
|
||||
override fun getReturnType() = returnTypeElement?.type
|
||||
|
||||
companion object Factory {
|
||||
fun create(
|
||||
delegate: PsiMethod, origin: LightMemberOrigin?, containingClass: KtLightClass
|
||||
|
||||
Reference in New Issue
Block a user