KtUltraLightMethod now use null for MemberIndex
This commit is contained in:
@@ -268,7 +268,9 @@ open class KtUltraLightClass(classOrObject: KtClassOrObject, internal val suppor
|
|||||||
private fun propertyParameters() = classOrObject.primaryConstructorParameters.filter { it.hasValOrVar() }
|
private fun propertyParameters() = classOrObject.primaryConstructorParameters.filter { it.hasValOrVar() }
|
||||||
|
|
||||||
private val _ownMethods: List<KtLightMethod> by lazyPub {
|
private val _ownMethods: List<KtLightMethod> by lazyPub {
|
||||||
|
|
||||||
val result = arrayListOf<KtLightMethod>()
|
val result = arrayListOf<KtLightMethod>()
|
||||||
|
|
||||||
for (declaration in this.classOrObject.declarations.filterNot { isHiddenByDeprecation(it) }) {
|
for (declaration in this.classOrObject.declarations.filterNot { isHiddenByDeprecation(it) }) {
|
||||||
if (declaration.hasModifier(PRIVATE_KEYWORD) && isInterface) continue
|
if (declaration.hasModifier(PRIVATE_KEYWORD) && isInterface) continue
|
||||||
when (declaration) {
|
when (declaration) {
|
||||||
@@ -276,12 +278,15 @@ open class KtUltraLightClass(classOrObject: KtClassOrObject, internal val suppor
|
|||||||
is KtProperty -> result.addAll(propertyAccessors(declaration, declaration.isVar, false))
|
is KtProperty -> result.addAll(propertyAccessors(declaration, declaration.isVar, false))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (parameter in propertyParameters()) {
|
for (parameter in propertyParameters()) {
|
||||||
result.addAll(propertyAccessors(parameter, parameter.isMutable, false))
|
result.addAll(propertyAccessors(parameter, parameter.isMutable, false))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isInterface) {
|
if (!isInterface) {
|
||||||
result.addAll(createConstructors())
|
result.addAll(createConstructors())
|
||||||
}
|
}
|
||||||
|
|
||||||
this.classOrObject.companionObjects.firstOrNull()?.let { companion ->
|
this.classOrObject.companionObjects.firstOrNull()?.let { companion ->
|
||||||
for (declaration in companion.declarations.filterNot { isHiddenByDeprecation(it) }) {
|
for (declaration in companion.declarations.filterNot { isHiddenByDeprecation(it) }) {
|
||||||
when (declaration) {
|
when (declaration) {
|
||||||
@@ -338,7 +343,10 @@ open class KtUltraLightClass(classOrObject: KtClassOrObject, internal val suppor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addDelegatesToInterfaceMethods(superTypeEntry: KtDelegatedSuperTypeEntry, result: MutableList<KtLightMethod>) {
|
private fun addDelegatesToInterfaceMethods(
|
||||||
|
superTypeEntry: KtDelegatedSuperTypeEntry,
|
||||||
|
result: MutableList<KtLightMethod>
|
||||||
|
) {
|
||||||
val classDescriptor = classOrObject.resolve() as? ClassDescriptor ?: return
|
val classDescriptor = classOrObject.resolve() as? ClassDescriptor ?: return
|
||||||
val typeReference = superTypeEntry.typeReference ?: return
|
val typeReference = superTypeEntry.typeReference ?: return
|
||||||
val bindingContext = typeReference.analyze()
|
val bindingContext = typeReference.analyze()
|
||||||
@@ -348,7 +356,10 @@ open class KtUltraLightClass(classOrObject: KtClassOrObject, internal val suppor
|
|||||||
|
|
||||||
for (delegate in DelegationResolver.getDelegates(classDescriptor, superClassDescriptor, delegationType).keys) {
|
for (delegate in DelegationResolver.getDelegates(classDescriptor, superClassDescriptor, delegationType).keys) {
|
||||||
when (delegate) {
|
when (delegate) {
|
||||||
is PropertyDescriptor -> delegate.accessors.mapTo(result, this::createGeneratedMethodFromDescriptor)
|
|
||||||
|
is PropertyDescriptor -> delegate.accessors.mapTo(result) {
|
||||||
|
createGeneratedMethodFromDescriptor(it)
|
||||||
|
}
|
||||||
is FunctionDescriptor -> result.add(createGeneratedMethodFromDescriptor(delegate))
|
is FunctionDescriptor -> result.add(createGeneratedMethodFromDescriptor(delegate))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -376,7 +387,8 @@ open class KtUltraLightClass(classOrObject: KtClassOrObject, internal val suppor
|
|||||||
!classOrObject.hasModifier(SEALED_KEYWORD) &&
|
!classOrObject.hasModifier(SEALED_KEYWORD) &&
|
||||||
primary.valueParameters.isNotEmpty() &&
|
primary.valueParameters.isNotEmpty() &&
|
||||||
primary.valueParameters.all { it.defaultValue != null } &&
|
primary.valueParameters.all { it.defaultValue != null } &&
|
||||||
classOrObject.allConstructors.none { it.valueParameters.isEmpty() }
|
classOrObject.allConstructors.none { it.valueParameters.isEmpty() } &&
|
||||||
|
!primary.hasAnnotation(JVM_OVERLOADS_FQ_NAME)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun defaultConstructor(): KtUltraLightMethod {
|
private fun defaultConstructor(): KtUltraLightMethod {
|
||||||
@@ -412,19 +424,31 @@ open class KtUltraLightClass(classOrObject: KtClassOrObject, internal val suppor
|
|||||||
|
|
||||||
override fun getOwnMethods(): List<KtLightMethod> = if (tooComplex) super.getOwnMethods() else _ownMethods
|
override fun getOwnMethods(): List<KtLightMethod> = if (tooComplex) super.getOwnMethods() else _ownMethods
|
||||||
|
|
||||||
private fun asJavaMethods(ktFunction: KtFunction, forceStatic: Boolean, forcePrivate: Boolean = false): Collection<KtLightMethod> {
|
private fun asJavaMethods(
|
||||||
|
ktFunction: KtFunction,
|
||||||
|
forceStatic: Boolean,
|
||||||
|
forcePrivate: Boolean = false
|
||||||
|
): Collection<KtLightMethod> {
|
||||||
|
|
||||||
if (ktFunction.hasAnnotation(JVM_SYNTHETIC_ANNOTATION_FQ_NAME)) return emptyList()
|
if (ktFunction.hasAnnotation(JVM_SYNTHETIC_ANNOTATION_FQ_NAME)) return emptyList()
|
||||||
|
|
||||||
val basicMethod = asJavaMethod(ktFunction, forceStatic, forcePrivate)
|
val basicMethod = asJavaMethod(ktFunction, forceStatic, forcePrivate)
|
||||||
|
|
||||||
if (!ktFunction.hasAnnotation(JVM_OVERLOADS_FQ_NAME)) return listOf(basicMethod)
|
val result = mutableListOf(basicMethod)
|
||||||
|
|
||||||
val result = mutableListOf<KtLightMethod>()
|
if (ktFunction.hasAnnotation(JVM_OVERLOADS_FQ_NAME)) {
|
||||||
val numberOfDefaultParameters = ktFunction.valueParameters.count(KtParameter::hasDefaultValue)
|
val numberOfDefaultParameters = ktFunction.valueParameters.count(KtParameter::hasDefaultValue)
|
||||||
for (numberOfDefaultParametersToAdd in 0 until numberOfDefaultParameters) {
|
for (numberOfDefaultParametersToAdd in numberOfDefaultParameters - 1 downTo 0) {
|
||||||
result.add(asJavaMethod(ktFunction, forceStatic, forcePrivate, numberOfDefaultParametersToAdd))
|
result.add(
|
||||||
|
asJavaMethod(
|
||||||
|
ktFunction,
|
||||||
|
forceStatic,
|
||||||
|
forcePrivate,
|
||||||
|
numberOfDefaultParametersToAdd = numberOfDefaultParametersToAdd
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
result.add(basicMethod)
|
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@@ -605,7 +629,12 @@ open class KtUltraLightClass(classOrObject: KtClassOrObject, internal val suppor
|
|||||||
return f.hasModifier(INTERNAL_KEYWORD)
|
return f.hasModifier(INTERNAL_KEYWORD)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun propertyAccessors(declaration: KtCallableDeclaration, mutable: Boolean, onlyJvmStatic: Boolean): List<KtLightMethod> {
|
private fun propertyAccessors(
|
||||||
|
declaration: KtCallableDeclaration,
|
||||||
|
mutable: Boolean,
|
||||||
|
onlyJvmStatic: Boolean
|
||||||
|
): List<KtLightMethod> {
|
||||||
|
|
||||||
val propertyName = declaration.name ?: return emptyList()
|
val propertyName = declaration.name ?: return emptyList()
|
||||||
if (declaration.isConstOrJvmField()) return emptyList()
|
if (declaration.isConstOrJvmField()) return emptyList()
|
||||||
|
|
||||||
|
|||||||
+10
-1
@@ -12,6 +12,7 @@ import com.intellij.psi.impl.light.LightMethodBuilder
|
|||||||
import com.intellij.psi.impl.light.LightTypeParameterListBuilder
|
import com.intellij.psi.impl.light.LightTypeParameterListBuilder
|
||||||
import com.intellij.psi.util.MethodSignatureBackedByPsiMethod
|
import com.intellij.psi.util.MethodSignatureBackedByPsiMethod
|
||||||
import org.jetbrains.kotlin.asJava.builder.LightMemberOriginForDeclaration
|
import org.jetbrains.kotlin.asJava.builder.LightMemberOriginForDeclaration
|
||||||
|
import org.jetbrains.kotlin.asJava.builder.MemberIndex
|
||||||
import org.jetbrains.kotlin.asJava.elements.KtLightAbstractAnnotation
|
import org.jetbrains.kotlin.asJava.elements.KtLightAbstractAnnotation
|
||||||
import org.jetbrains.kotlin.asJava.elements.KtLightMethodImpl
|
import org.jetbrains.kotlin.asJava.elements.KtLightMethodImpl
|
||||||
import org.jetbrains.kotlin.codegen.FunctionCodegen
|
import org.jetbrains.kotlin.codegen.FunctionCodegen
|
||||||
@@ -37,6 +38,8 @@ internal abstract class KtUltraLightMethod(
|
|||||||
containingClass
|
containingClass
|
||||||
), KtUltraLightElementWithNullabilityAnnotation<KtDeclaration, PsiMethod> {
|
), KtUltraLightElementWithNullabilityAnnotation<KtDeclaration, PsiMethod> {
|
||||||
|
|
||||||
|
override val memberIndex: MemberIndex? = null
|
||||||
|
|
||||||
override val psiTypeForNullabilityAnnotation: PsiType?
|
override val psiTypeForNullabilityAnnotation: PsiType?
|
||||||
get() = returnType
|
get() = returnType
|
||||||
|
|
||||||
@@ -88,6 +91,10 @@ internal abstract class KtUltraLightMethod(
|
|||||||
override fun getThrowsList(): PsiReferenceList = _throwsList
|
override fun getThrowsList(): PsiReferenceList = _throwsList
|
||||||
|
|
||||||
abstract fun computeDescriptor(): FunctionDescriptor?
|
abstract fun computeDescriptor(): FunctionDescriptor?
|
||||||
|
|
||||||
|
override fun equals(other: Any?): Boolean = this === other
|
||||||
|
|
||||||
|
override fun hashCode(): Int = name.hashCode()
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class KtUltraLightMethodForSourceDeclaration(
|
internal class KtUltraLightMethodForSourceDeclaration(
|
||||||
@@ -98,7 +105,8 @@ internal class KtUltraLightMethodForSourceDeclaration(
|
|||||||
) : KtUltraLightMethod(
|
) : KtUltraLightMethod(
|
||||||
delegate,
|
delegate,
|
||||||
declaration,
|
declaration,
|
||||||
support, containingClass
|
support,
|
||||||
|
containingClass
|
||||||
) {
|
) {
|
||||||
override val kotlinTypeForNullabilityAnnotation: KotlinType?
|
override val kotlinTypeForNullabilityAnnotation: KotlinType?
|
||||||
get() = kotlinOrigin?.getKotlinType()
|
get() = kotlinOrigin?.getKotlinType()
|
||||||
@@ -125,6 +133,7 @@ internal class KtUltraLightMethodForDescriptor(
|
|||||||
support,
|
support,
|
||||||
containingClass
|
containingClass
|
||||||
) {
|
) {
|
||||||
|
|
||||||
override fun buildTypeParameterList() = buildTypeParameterList(descriptor, this, support)
|
override fun buildTypeParameterList() = buildTypeParameterList(descriptor, this, support)
|
||||||
|
|
||||||
override fun computeDescriptor() = descriptor
|
override fun computeDescriptor() = descriptor
|
||||||
|
|||||||
+3
-3
@@ -152,7 +152,7 @@ open class KtLightMethodImpl protected constructor(
|
|||||||
return typeParameters.all { processor.execute(it, state) }
|
return typeParameters.all { processor.execute(it, state) }
|
||||||
}
|
}
|
||||||
|
|
||||||
private val _memberIndex: MemberIndex?
|
protected open val memberIndex: MemberIndex?
|
||||||
get() = (dummyDelegate ?: clsDelegate).memberIndex
|
get() = (dummyDelegate ?: clsDelegate).memberIndex
|
||||||
|
|
||||||
/* comparing origin and member index should be enough to determine equality:
|
/* comparing origin and member index should be enough to determine equality:
|
||||||
@@ -165,9 +165,9 @@ open class KtLightMethodImpl protected constructor(
|
|||||||
this.name == other.name &&
|
this.name == other.name &&
|
||||||
this.containingClass == other.containingClass &&
|
this.containingClass == other.containingClass &&
|
||||||
this.lightMemberOrigin == other.lightMemberOrigin &&
|
this.lightMemberOrigin == other.lightMemberOrigin &&
|
||||||
this._memberIndex == other._memberIndex)
|
this.memberIndex == other.memberIndex)
|
||||||
|
|
||||||
override fun hashCode(): Int = ((getName().hashCode() * 31 + (lightMemberOrigin?.hashCode() ?: 0)) * 31 + containingClass.hashCode()) * 31 + (_memberIndex?.hashCode() ?: 0)
|
override fun hashCode(): Int = ((getName().hashCode() * 31 + (lightMemberOrigin?.hashCode() ?: 0)) * 31 + containingClass.hashCode()) * 31 + (memberIndex?.hashCode() ?: 0)
|
||||||
|
|
||||||
override fun getDefaultValue() = (clsDelegate as? PsiAnnotationMethod)?.defaultValue
|
override fun getDefaultValue() = (clsDelegate as? PsiAnnotationMethod)?.defaultValue
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user