[FIR IDE] Fix callableIdIfNonLocal in AAPI/FE10
Before, implementations of 'callableIdIfNonLocal' in Fe10KtSymbols returned CallableIds even for local declarations. This commit fixes this behavior. This commit fixes KtFe10SymbolByPsiTestGenerated.testLocalDeclarations().
This commit is contained in:
+3
-2
@@ -13,7 +13,8 @@ import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.KtF
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.KtFe10DescPropertyGetterSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.KtFe10DescPropertySetterSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.KtFe10DescValueParameterSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.base.callableId
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.base.calculateCallableId
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.base.callableIdIfNotLocal
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.base.toKtCallableSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.diagnostics.KtNonBoundToPsiErrorDiagnostic
|
||||
import org.jetbrains.kotlin.analysis.api.impl.base.components.AbstractKtCallResolver
|
||||
@@ -141,7 +142,7 @@ internal class KtFe10CallResolver(
|
||||
val variableSymbol = variableDescriptor.toKtCallableSymbol(analysisContext) as? KtVariableLikeSymbol ?: return null
|
||||
|
||||
val substitutor = KtSubstitutor.Empty(token)
|
||||
return if (resolvedCall.functionCall.resultingDescriptor.callableId in kotlinFunctionInvokeCallableIds) {
|
||||
return if (resolvedCall.functionCall.resultingDescriptor.callableIdIfNotLocal in kotlinFunctionInvokeCallableIds) {
|
||||
KtFunctionalTypeVariableCall(variableSymbol, argumentMapping, getTarget(callableSymbol), substitutor, token)
|
||||
} else {
|
||||
KtVariableWithInvokeFunctionCall(variableSymbol, argumentMapping, getTarget(callableSymbol), substitutor, token)
|
||||
|
||||
+2
-2
@@ -55,8 +55,8 @@ internal class KtFe10DescConstructorSymbol(
|
||||
return pointerByPsi
|
||||
}
|
||||
|
||||
val callableId = descriptor.callableId
|
||||
if (callableId != null && !callableId.isLocal) {
|
||||
val callableId = descriptor.callableIdIfNotLocal
|
||||
if (callableId != null) {
|
||||
val signature = descriptor.getSymbolPointerSignature(analysisContext)
|
||||
return KtFe10DescFunctionLikeSymbolPointer(callableId, signature)
|
||||
}
|
||||
|
||||
+3
-3
@@ -64,7 +64,7 @@ internal class KtFe10DescFunctionSymbol(
|
||||
get() = withValidityAssertion { descriptor.ktHasStableParameterNames }
|
||||
|
||||
override val callableIdIfNonLocal: CallableId?
|
||||
get() = withValidityAssertion { descriptor.callableId }
|
||||
get() = withValidityAssertion { descriptor.callableIdIfNotLocal }
|
||||
|
||||
override val annotatedType: KtTypeAndAnnotations
|
||||
get() = withValidityAssertion { descriptor.returnTypeOrNothing.toKtTypeAndAnnotations(analysisContext) }
|
||||
@@ -87,8 +87,8 @@ internal class KtFe10DescFunctionSymbol(
|
||||
return pointerByPsi
|
||||
}
|
||||
|
||||
val callableId = descriptor.callableId
|
||||
if (callableId != null && !callableId.isLocal) {
|
||||
val callableId = descriptor.callableIdIfNotLocal
|
||||
if (callableId != null) {
|
||||
val signature = descriptor.getSymbolPointerSignature(analysisContext)
|
||||
return KtFe10DescFunctionLikeSymbolPointer(callableId, signature)
|
||||
}
|
||||
|
||||
+2
-2
@@ -7,7 +7,7 @@ package org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.Fe10AnalysisContext
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.base.KtFe10DescMemberSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.base.callableId
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.base.callableIdIfNotLocal
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.base.toKtTypeAndAnnotations
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.pointers.KtFe10NeverRestoringSymbolPointer
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtJavaFieldSymbol
|
||||
@@ -34,7 +34,7 @@ internal class KtFe10DescJavaFieldSymbol(
|
||||
get() = withValidityAssertion { !descriptor.isVar }
|
||||
|
||||
override val callableIdIfNonLocal: CallableId?
|
||||
get() = withValidityAssertion { descriptor.callableId }
|
||||
get() = withValidityAssertion { descriptor.callableIdIfNotLocal }
|
||||
|
||||
override val annotatedType: KtTypeAndAnnotations
|
||||
get() = withValidityAssertion { descriptor.returnType.toKtTypeAndAnnotations(analysisContext) }
|
||||
|
||||
+1
-1
@@ -64,7 +64,7 @@ internal class KtFe10DescKotlinPropertySymbol(
|
||||
get() = withValidityAssertion { descriptor.setter != null }
|
||||
|
||||
override val callableIdIfNonLocal: CallableId?
|
||||
get() = withValidityAssertion { descriptor.callableId }
|
||||
get() = withValidityAssertion { descriptor.callableIdIfNotLocal }
|
||||
|
||||
override val initializer: KtConstantValue?
|
||||
get() = withValidityAssertion { descriptor.compileTimeInitializer?.toKtConstantValue() }
|
||||
|
||||
+1
-1
@@ -47,7 +47,7 @@ internal class KtFe10DescPropertyGetterSymbol(
|
||||
get() = withValidityAssertion {
|
||||
val propertyDescriptor = descriptor.correspondingProperty
|
||||
return if (propertyDescriptor is SyntheticPropertyDescriptor) {
|
||||
propertyDescriptor.getMethod.callableId
|
||||
propertyDescriptor.getMethod.callableIdIfNotLocal
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@ internal class KtFe10DescPropertySetterSymbol(
|
||||
get() = withValidityAssertion {
|
||||
val propertyDescriptor = descriptor.correspondingProperty
|
||||
return if (propertyDescriptor is SyntheticPropertyDescriptor) {
|
||||
propertyDescriptor.getMethod.callableId
|
||||
propertyDescriptor.getMethod.callableIdIfNotLocal
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@ internal class KtFe10DescSamConstructorSymbol(
|
||||
get() = withValidityAssertion { descriptor.ktHasStableParameterNames }
|
||||
|
||||
override val callableIdIfNonLocal: CallableId?
|
||||
get() = withValidityAssertion { descriptor.callableId }
|
||||
get() = withValidityAssertion { descriptor.callableIdIfNotLocal }
|
||||
|
||||
override val annotatedType: KtTypeAndAnnotations
|
||||
get() = withValidityAssertion { descriptor.returnTypeOrNothing.toKtTypeAndAnnotations(analysisContext) }
|
||||
|
||||
+1
-1
@@ -78,7 +78,7 @@ internal class KtFe10DescSyntheticJavaPropertySymbol(
|
||||
get() = withValidityAssertion { descriptor.compileTimeInitializer?.toKtConstantValue() }
|
||||
|
||||
override val callableIdIfNonLocal: CallableId?
|
||||
get() = withValidityAssertion { descriptor.callableId }
|
||||
get() = withValidityAssertion { descriptor.callableIdIfNotLocal }
|
||||
|
||||
override val annotatedType: KtTypeAndAnnotations
|
||||
get() = withValidityAssertion { descriptor.type.toKtTypeAndAnnotations(analysisContext) }
|
||||
|
||||
+1
-1
@@ -78,7 +78,7 @@ internal class KtFe10DescSyntheticJavaPropertySymbolForOverride(
|
||||
get() = withValidityAssertion { descriptor.compileTimeInitializer?.toKtConstantValue() }
|
||||
|
||||
override val callableIdIfNonLocal: CallableId?
|
||||
get() = withValidityAssertion { descriptor.callableId }
|
||||
get() = withValidityAssertion { descriptor.callableIdIfNotLocal }
|
||||
|
||||
override val annotatedType: KtTypeAndAnnotations
|
||||
get() = withValidityAssertion { descriptor.type.toKtTypeAndAnnotations(analysisContext) }
|
||||
|
||||
+27
-19
@@ -235,31 +235,39 @@ internal fun ConstantValue<*>.toKtConstantValue(): KtConstantValue {
|
||||
}
|
||||
}
|
||||
|
||||
internal val CallableMemberDescriptor.callableId: CallableId?
|
||||
get() {
|
||||
var current: DeclarationDescriptor = containingDeclaration
|
||||
internal val CallableMemberDescriptor.callableIdIfNotLocal: CallableId?
|
||||
get() = calculateCallableId(allowLocal = false)
|
||||
|
||||
val localName = mutableListOf<String>()
|
||||
val className = mutableListOf<String>()
|
||||
internal fun CallableMemberDescriptor.calculateCallableId(allowLocal: Boolean): CallableId? {
|
||||
var current: DeclarationDescriptor = containingDeclaration
|
||||
|
||||
while (true) {
|
||||
when (current) {
|
||||
is PackageFragmentDescriptor -> {
|
||||
return CallableId(
|
||||
packageName = current.fqName,
|
||||
className = if (className.isNotEmpty()) FqName.fromSegments(className.asReversed()) else null,
|
||||
callableName = name,
|
||||
pathToLocal = if (localName.isNotEmpty()) FqName.fromSegments(localName.asReversed()) else null
|
||||
)
|
||||
}
|
||||
is ClassDescriptor -> className += current.name.asString()
|
||||
is PropertyAccessorDescriptor -> {} // Filter out property accessors
|
||||
is CallableDescriptor -> localName += current.name.asString()
|
||||
val localName = mutableListOf<String>()
|
||||
val className = mutableListOf<String>()
|
||||
|
||||
while (true) {
|
||||
when (current) {
|
||||
is PackageFragmentDescriptor -> {
|
||||
return CallableId(
|
||||
packageName = current.fqName,
|
||||
className = if (className.isNotEmpty()) FqName.fromSegments(className.asReversed()) else null,
|
||||
callableName = name,
|
||||
pathToLocal = if (localName.isNotEmpty()) FqName.fromSegments(localName.asReversed()) else null
|
||||
)
|
||||
}
|
||||
is ClassDescriptor -> className += current.name.asString()
|
||||
is PropertyAccessorDescriptor -> {} // Filter out property accessors
|
||||
is CallableDescriptor -> {
|
||||
if (!allowLocal) {
|
||||
return null
|
||||
}
|
||||
|
||||
current = current.containingDeclaration ?: return null
|
||||
localName += current.name.asString()
|
||||
}
|
||||
}
|
||||
|
||||
current = current.containingDeclaration ?: return null
|
||||
}
|
||||
}
|
||||
|
||||
internal fun getSymbolDescriptor(symbol: KtSymbol): DeclarationDescriptor? {
|
||||
return when (symbol) {
|
||||
|
||||
+2
-2
@@ -11,7 +11,7 @@ import org.jetbrains.kotlin.analysis.api.descriptors.KtFe10AnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.base.toKtTypeAndAnnotations
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.pointers.KtFe10NeverRestoringSymbolPointer
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.psiBased.base.KtFe10PsiSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.psiBased.base.callableId
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.psiBased.base.callableIdIfNonLocal
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.psiBased.base.createErrorTypeAndAnnotations
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.utils.cached
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtEnumEntrySymbol
|
||||
@@ -44,7 +44,7 @@ internal class KtFe10PsiEnumEntrySymbol(
|
||||
}
|
||||
|
||||
override val callableIdIfNonLocal: CallableId?
|
||||
get() = withValidityAssertion { psi.callableId }
|
||||
get() = withValidityAssertion { psi.callableIdIfNonLocal }
|
||||
|
||||
override val annotatedType: KtTypeAndAnnotations
|
||||
get() = withValidityAssertion {
|
||||
|
||||
+1
-1
@@ -73,7 +73,7 @@ internal class KtFe10PsiFunctionSymbol(
|
||||
get() = withValidityAssertion { true }
|
||||
|
||||
override val callableIdIfNonLocal: CallableId?
|
||||
get() = withValidityAssertion { psi.callableId }
|
||||
get() = withValidityAssertion { psi.callableIdIfNonLocal }
|
||||
|
||||
override val annotatedType: KtTypeAndAnnotations
|
||||
get() = withValidityAssertion { descriptor?.returnType?.toKtTypeAndAnnotations(analysisContext) ?: createErrorTypeAndAnnotations() }
|
||||
|
||||
+1
-1
@@ -96,7 +96,7 @@ internal class KtFe10PsiKotlinPropertySymbol(
|
||||
get() = withValidityAssertion { !psi.isVar }
|
||||
|
||||
override val callableIdIfNonLocal: CallableId?
|
||||
get() = withValidityAssertion { psi.callableId }
|
||||
get() = withValidityAssertion { psi.callableIdIfNonLocal }
|
||||
|
||||
override val annotatedType: KtTypeAndAnnotations
|
||||
get() = withValidityAssertion { descriptor?.type?.toKtTypeAndAnnotations(analysisContext) ?: createErrorTypeAndAnnotations() }
|
||||
|
||||
+1
-1
@@ -64,7 +64,7 @@ internal class KtFe10PsiPropertyGetterSymbol(
|
||||
get() = withValidityAssertion { true }
|
||||
|
||||
override val callableIdIfNonLocal: CallableId?
|
||||
get() = withValidityAssertion { psi.property.callableId }
|
||||
get() = withValidityAssertion { psi.property.callableIdIfNonLocal }
|
||||
|
||||
override val annotatedType: KtTypeAndAnnotations
|
||||
get() = withValidityAssertion {
|
||||
|
||||
+31
-20
@@ -68,34 +68,45 @@ internal val KtElement.ktSymbolKind: KtSymbolKind
|
||||
else -> KtSymbolKind.LOCAL
|
||||
}
|
||||
|
||||
internal val KtDeclaration.callableId: CallableId?
|
||||
get() {
|
||||
val selfName = this.name ?: return null
|
||||
val containingFile = this.containingKtFile
|
||||
internal val KtDeclaration.callableIdIfNonLocal: CallableId?
|
||||
get() = calculateCallableId(allowLocal = false)
|
||||
|
||||
var current = this.getElementParentDeclaration()
|
||||
internal fun KtDeclaration.calculateCallableId(allowLocal: Boolean): CallableId? {
|
||||
val selfName = this.name ?: return null
|
||||
val containingFile = this.containingKtFile
|
||||
|
||||
val localName = mutableListOf<String>()
|
||||
val className = mutableListOf<String>()
|
||||
var current = this.getElementParentDeclaration()
|
||||
|
||||
while (current != null) {
|
||||
when (current) {
|
||||
is KtClassOrObject -> className += current.name ?: return null
|
||||
is KtPropertyAccessor -> {} // Filter out property accessors
|
||||
is KtCallableDeclaration -> localName += current.name ?: return null
|
||||
val localName = mutableListOf<String>()
|
||||
val className = mutableListOf<String>()
|
||||
|
||||
while (current != null) {
|
||||
when (current) {
|
||||
is KtClassOrObject -> {
|
||||
className += current.name ?: return null
|
||||
}
|
||||
is KtPropertyAccessor -> {
|
||||
// Filter out property accessors
|
||||
}
|
||||
is KtCallableDeclaration -> {
|
||||
if (!allowLocal) {
|
||||
return null
|
||||
}
|
||||
localName += current.name ?: return null
|
||||
}
|
||||
|
||||
current = current.getElementParentDeclaration()
|
||||
}
|
||||
|
||||
return CallableId(
|
||||
packageName = containingFile.packageFqName,
|
||||
className = if (className.isNotEmpty()) FqName.fromSegments(className.asReversed()) else null,
|
||||
callableName = Name.identifier(selfName),
|
||||
pathToLocal = if (localName.isNotEmpty()) FqName.fromSegments(localName.asReversed()) else null
|
||||
)
|
||||
current = current.getElementParentDeclaration()
|
||||
}
|
||||
|
||||
return CallableId(
|
||||
packageName = containingFile.packageFqName,
|
||||
className = if (className.isNotEmpty()) FqName.fromSegments(className.asReversed()) else null,
|
||||
callableName = Name.identifier(selfName),
|
||||
pathToLocal = if (localName.isNotEmpty()) FqName.fromSegments(localName.asReversed()) else null
|
||||
)
|
||||
}
|
||||
|
||||
internal fun PsiElement.getResolutionScope(bindingContext: BindingContext): LexicalScope? {
|
||||
for (parent in parentsWithSelf) {
|
||||
if (parent is KtElement) {
|
||||
|
||||
Reference in New Issue
Block a user