Minor. Extract KtUltraLightMethodForSourceDeclaration
This commit is contained in:
+35
-19
@@ -17,30 +17,25 @@ import org.jetbrains.kotlin.asJava.elements.KtLightMethodImpl
|
||||
import org.jetbrains.kotlin.asJava.elements.KtLightSimpleModifierList
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.codegen.FunctionCodegen
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOriginKind
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
internal class KtUltraLightMethod(
|
||||
internal abstract class KtUltraLightMethod(
|
||||
internal val delegate: LightMethodBuilder,
|
||||
originalElement: KtDeclaration,
|
||||
private val support: UltraLightSupport,
|
||||
closestDeclarationForOrigin: KtDeclaration?,
|
||||
protected val support: UltraLightSupport,
|
||||
containingClass: KtUltraLightClass
|
||||
) : KtLightMethodImpl(
|
||||
{ delegate },
|
||||
LightMemberOriginForDeclaration(
|
||||
originalElement, JvmDeclarationOriginKind.OTHER
|
||||
),
|
||||
closestDeclarationForOrigin?.let {
|
||||
LightMemberOriginForDeclaration(it, JvmDeclarationOriginKind.OTHER)
|
||||
},
|
||||
containingClass
|
||||
), KtUltraLightElementWithNullabilityAnnotation<KtDeclaration, PsiMethod> {
|
||||
|
||||
override val kotlinTypeForNullabilityAnnotation: KotlinType?
|
||||
get() = kotlinOrigin?.getKotlinType()
|
||||
|
||||
override val psiTypeForNullabilityAnnotation: PsiType?
|
||||
get() = returnType
|
||||
|
||||
@@ -55,16 +50,11 @@ internal class KtUltraLightMethod(
|
||||
// should be in super
|
||||
override fun isVarArgs() = PsiImplUtil.isVarArgs(this)
|
||||
|
||||
override fun buildTypeParameterList(): PsiTypeParameterList {
|
||||
val origin = kotlinOrigin
|
||||
return if (origin is KtFunction || origin is KtProperty)
|
||||
buildTypeParameterList(origin as KtTypeParameterListOwner, this, support)
|
||||
else LightTypeParameterListBuilder(manager, language)
|
||||
}
|
||||
abstract override fun buildTypeParameterList(): PsiTypeParameterList
|
||||
|
||||
private val _throwsList: PsiReferenceList by lazyPub {
|
||||
val list = KotlinLightReferenceListBuilder(manager, language, PsiReferenceList.Role.THROWS_LIST)
|
||||
(kotlinOrigin?.resolve() as? FunctionDescriptor)?.let {
|
||||
computeDescriptor()?.let {
|
||||
for (ex in FunctionCodegen.getThrownExceptions(it)) {
|
||||
list.addReference(ex.fqNameSafe.asString())
|
||||
}
|
||||
@@ -75,6 +65,32 @@ internal class KtUltraLightMethod(
|
||||
override fun getHierarchicalMethodSignature() = PsiSuperMethodImplUtil.getHierarchicalMethodSignature(this)
|
||||
|
||||
override fun getThrowsList(): PsiReferenceList = _throwsList
|
||||
|
||||
abstract fun computeDescriptor(): FunctionDescriptor?
|
||||
}
|
||||
|
||||
internal class KtUltraLightMethodForSourceDeclaration(
|
||||
delegate: LightMethodBuilder,
|
||||
declaration: KtDeclaration,
|
||||
support: UltraLightSupport,
|
||||
containingClass: KtUltraLightClass
|
||||
) : KtUltraLightMethod(
|
||||
delegate,
|
||||
declaration,
|
||||
support, containingClass
|
||||
) {
|
||||
override val kotlinTypeForNullabilityAnnotation: KotlinType?
|
||||
get() = kotlinOrigin?.getKotlinType()
|
||||
|
||||
override fun buildTypeParameterList(): PsiTypeParameterList {
|
||||
val origin = kotlinOrigin
|
||||
return if (origin is KtFunction || origin is KtProperty)
|
||||
buildTypeParameterList(origin as KtTypeParameterListOwner, this, support)
|
||||
else LightTypeParameterListBuilder(manager, language)
|
||||
}
|
||||
|
||||
override fun computeDescriptor() = kotlinOrigin?.resolve() as? FunctionDescriptor
|
||||
}
|
||||
}
|
||||
|
||||
internal abstract class KtUltraLightParameter(
|
||||
|
||||
@@ -331,12 +331,13 @@ open class KtUltraLightClass(classOrObject: KtClassOrObject, internal val suppor
|
||||
else -> PsiModifier.PUBLIC
|
||||
}
|
||||
|
||||
private fun noArgConstructor(visibility: String, declaration: KtDeclaration): KtUltraLightMethod = KtUltraLightMethod(
|
||||
LightMethodBuilder(manager, language, name.orEmpty()).setConstructor(true).addModifier(visibility),
|
||||
declaration,
|
||||
support,
|
||||
this
|
||||
)
|
||||
private fun noArgConstructor(visibility: String, declaration: KtDeclaration): KtUltraLightMethod =
|
||||
KtUltraLightMethodForSourceDeclaration(
|
||||
LightMethodBuilder(manager, language, name.orEmpty()).setConstructor(true).addModifier(visibility),
|
||||
declaration,
|
||||
support,
|
||||
this
|
||||
)
|
||||
|
||||
private fun isHiddenByDeprecation(declaration: KtDeclaration): Boolean {
|
||||
val deprecated = support.findAnnotation(declaration, FqName("kotlin.Deprecated"))?.second
|
||||
@@ -377,7 +378,7 @@ open class KtUltraLightClass(classOrObject: KtClassOrObject, internal val suppor
|
||||
else computeMethodName(ktFunction, ktFunction.name ?: SpecialNames.NO_NAME_PROVIDED.asString())
|
||||
|
||||
val method = lightMethod(name.orEmpty(), ktFunction, forceStatic, forcePrivate)
|
||||
val wrapper = KtUltraLightMethod(method, ktFunction, support, this)
|
||||
val wrapper = KtUltraLightMethodForSourceDeclaration(method, ktFunction, support, this)
|
||||
addReceiverParameter(ktFunction, wrapper)
|
||||
|
||||
|
||||
@@ -547,7 +548,7 @@ open class KtUltraLightClass(classOrObject: KtClassOrObject, internal val suppor
|
||||
if (needsAccessor(ktGetter)) {
|
||||
val getterName = computeMethodName(ktGetter ?: declaration, JvmAbi.getterName(propertyName))
|
||||
val getterPrototype = lightMethod(getterName, ktGetter ?: declaration, onlyJvmStatic)
|
||||
val getterWrapper = KtUltraLightMethod(getterPrototype, declaration, support, this)
|
||||
val getterWrapper = KtUltraLightMethodForSourceDeclaration(getterPrototype, declaration, support, this)
|
||||
val getterType: PsiType by lazyPub { methodReturnType(declaration, getterWrapper) }
|
||||
getterPrototype.setMethodReturnType { getterType }
|
||||
addReceiverParameter(declaration, getterWrapper)
|
||||
@@ -558,7 +559,7 @@ open class KtUltraLightClass(classOrObject: KtClassOrObject, internal val suppor
|
||||
val setterName = computeMethodName(ktSetter ?: declaration, JvmAbi.setterName(propertyName))
|
||||
val setterPrototype = lightMethod(setterName, ktSetter ?: declaration, onlyJvmStatic)
|
||||
.setMethodReturnType(PsiType.VOID)
|
||||
val setterWrapper = KtUltraLightMethod(setterPrototype, declaration, support, this)
|
||||
val setterWrapper = KtUltraLightMethodForSourceDeclaration(setterPrototype, declaration, support, this)
|
||||
addReceiverParameter(declaration, setterWrapper)
|
||||
val setterParameter = ktSetter?.parameter
|
||||
setterPrototype.addParameter(
|
||||
|
||||
Reference in New Issue
Block a user