[FIR IDE] Fix callableIdIfNonLocal for accessors in AAPI/FE10

Before the behavior was rather random and erroneous. Now the callable id
is also 'null' for Kotlin property accessors, and accessor method id
for synthetic Java properties.
This commit is contained in:
Yan Zhulanow
2021-10-29 01:29:07 +09:00
parent 4f7dc1122f
commit 94ca387405
7 changed files with 27 additions and 22 deletions
@@ -56,7 +56,7 @@ class KtFe10DescDefaultPropertyGetterSymbol(
get() = withValidityAssertion { true } get() = withValidityAssertion { true }
override val callableIdIfNonLocal: CallableId? override val callableIdIfNonLocal: CallableId?
get() = withValidityAssertion { null } get() = withValidityAssertion { propertyDescriptor.getterCallableIdIfNotLocal }
override val annotatedType: KtTypeAndAnnotations override val annotatedType: KtTypeAndAnnotations
get() = withValidityAssertion { propertyDescriptor.type.toKtTypeAndAnnotations(analysisContext) } get() = withValidityAssertion { propertyDescriptor.type.toKtTypeAndAnnotations(analysisContext) }
@@ -53,7 +53,7 @@ class KtFe10DescDefaultPropertySetterSymbol(
get() = withValidityAssertion { true } get() = withValidityAssertion { true }
override val callableIdIfNonLocal: CallableId? override val callableIdIfNonLocal: CallableId?
get() = withValidityAssertion { null } get() = withValidityAssertion { propertyDescriptor.setterCallableIdIfNotLocal }
override val annotatedType: KtTypeAndAnnotations override val annotatedType: KtTypeAndAnnotations
get() = withValidityAssertion { analysisContext.builtIns.unitType.toKtTypeAndAnnotations(analysisContext) } get() = withValidityAssertion { analysisContext.builtIns.unitType.toKtTypeAndAnnotations(analysisContext) }
@@ -16,7 +16,6 @@ import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
import org.jetbrains.kotlin.analysis.api.types.KtType import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.withValidityAssertion import org.jetbrains.kotlin.analysis.api.withValidityAssertion
import org.jetbrains.kotlin.descriptors.PropertyGetterDescriptor import org.jetbrains.kotlin.descriptors.PropertyGetterDescriptor
import org.jetbrains.kotlin.descriptors.SyntheticPropertyDescriptor
import org.jetbrains.kotlin.descriptors.hasBody import org.jetbrains.kotlin.descriptors.hasBody
import org.jetbrains.kotlin.name.CallableId import org.jetbrains.kotlin.name.CallableId
import org.jetbrains.kotlin.resolve.calls.inference.returnTypeOrNothing import org.jetbrains.kotlin.resolve.calls.inference.returnTypeOrNothing
@@ -44,14 +43,7 @@ internal class KtFe10DescPropertyGetterSymbol(
get() = withValidityAssertion { descriptor.ktHasStableParameterNames } get() = withValidityAssertion { descriptor.ktHasStableParameterNames }
override val callableIdIfNonLocal: CallableId? override val callableIdIfNonLocal: CallableId?
get() = withValidityAssertion { get() = withValidityAssertion { descriptor.correspondingProperty.getterCallableIdIfNotLocal }
val propertyDescriptor = descriptor.correspondingProperty
return if (propertyDescriptor is SyntheticPropertyDescriptor) {
propertyDescriptor.getMethod.callableIdIfNotLocal
} else {
null
}
}
override val annotatedType: KtTypeAndAnnotations override val annotatedType: KtTypeAndAnnotations
get() = withValidityAssertion { descriptor.returnTypeOrNothing.toKtTypeAndAnnotations(analysisContext) } get() = withValidityAssertion { descriptor.returnTypeOrNothing.toKtTypeAndAnnotations(analysisContext) }
@@ -16,7 +16,6 @@ import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
import org.jetbrains.kotlin.analysis.api.types.KtType import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.withValidityAssertion import org.jetbrains.kotlin.analysis.api.withValidityAssertion
import org.jetbrains.kotlin.descriptors.PropertySetterDescriptor import org.jetbrains.kotlin.descriptors.PropertySetterDescriptor
import org.jetbrains.kotlin.descriptors.SyntheticPropertyDescriptor
import org.jetbrains.kotlin.descriptors.hasBody import org.jetbrains.kotlin.descriptors.hasBody
import org.jetbrains.kotlin.name.CallableId import org.jetbrains.kotlin.name.CallableId
@@ -46,14 +45,7 @@ internal class KtFe10DescPropertySetterSymbol(
get() = withValidityAssertion { descriptor.ktHasStableParameterNames } get() = withValidityAssertion { descriptor.ktHasStableParameterNames }
override val callableIdIfNonLocal: CallableId? override val callableIdIfNonLocal: CallableId?
get() = withValidityAssertion { get() = withValidityAssertion { descriptor.correspondingProperty.setterCallableIdIfNotLocal }
val propertyDescriptor = descriptor.correspondingProperty
return if (propertyDescriptor is SyntheticPropertyDescriptor) {
propertyDescriptor.getMethod.callableIdIfNotLocal
} else {
null
}
}
override val parameter: KtValueParameterSymbol override val parameter: KtValueParameterSymbol
get() = withValidityAssertion { KtFe10DescValueParameterSymbol(descriptor.valueParameters.single(), analysisContext) } get() = withValidityAssertion { KtFe10DescValueParameterSymbol(descriptor.valueParameters.single(), analysisContext) }
@@ -304,6 +304,27 @@ internal fun CallableMemberDescriptor.calculateCallableId(allowLocal: Boolean):
} }
} }
internal val PropertyDescriptor.getterCallableIdIfNotLocal: CallableId?
get() {
if (this is SyntheticPropertyDescriptor) {
return getMethod.callableIdIfNotLocal
}
return null
}
internal val PropertyDescriptor.setterCallableIdIfNotLocal: CallableId?
get() {
if (this is SyntheticPropertyDescriptor) {
val setMethod = this.setMethod
if (setMethod != null) {
return setMethod.callableIdIfNotLocal
}
}
return null
}
internal fun getSymbolDescriptor(symbol: KtSymbol): DeclarationDescriptor? { internal fun getSymbolDescriptor(symbol: KtSymbol): DeclarationDescriptor? {
return when (symbol) { return when (symbol) {
is KtFe10DescSymbol<*> -> symbol.descriptor is KtFe10DescSymbol<*> -> symbol.descriptor
@@ -64,7 +64,7 @@ internal class KtFe10PsiPropertyGetterSymbol(
get() = withValidityAssertion { true } get() = withValidityAssertion { true }
override val callableIdIfNonLocal: CallableId? override val callableIdIfNonLocal: CallableId?
get() = withValidityAssertion { psi.property.callableIdIfNonLocal } get() = withValidityAssertion { null }
override val annotatedType: KtTypeAndAnnotations override val annotatedType: KtTypeAndAnnotations
get() = withValidityAssertion { get() = withValidityAssertion {
@@ -65,7 +65,7 @@ internal class KtFe10PsiPropertySetterSymbol(
get() = withValidityAssertion { true } get() = withValidityAssertion { true }
override val callableIdIfNonLocal: CallableId? override val callableIdIfNonLocal: CallableId?
get() = TODO("Not yet implemented") get() = withValidityAssertion { null }
override val annotatedType: KtTypeAndAnnotations override val annotatedType: KtTypeAndAnnotations
get() = withValidityAssertion { get() = withValidityAssertion {