[AA] Add synthetic properties scopes to scope context for position

This commit is contained in:
aleksandrina-streltsova
2023-06-24 19:53:22 +03:00
committed by teamcity
parent 5d8e23e971
commit 116de97f54
25 changed files with 672 additions and 48 deletions
@@ -45,6 +45,7 @@ import org.jetbrains.kotlin.fir.scopes.impl.*
import org.jetbrains.kotlin.fir.symbols.impl.*
import org.jetbrains.kotlin.fir.symbols.lazyResolveToPhase
import org.jetbrains.kotlin.fir.symbols.lazyResolveToPhaseWithCallableMembers
import org.jetbrains.kotlin.fir.types.ConeKotlinType
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.KtElement
@@ -160,16 +161,17 @@ internal class KtFirScopeProvider(
return KtCompositeScope.create(subScopes, token)
}
override fun getTypeScope(type: KtType): KtTypeScope? = getFirTypeScope(type)?.let { convertToKtTypeScope(it) }
override fun getTypeScope(type: KtType): KtTypeScope? {
check(type is KtFirType) { "KtFirScopeProvider can only work with KtFirType, but ${type::class} was provided" }
return getFirTypeScope(type)
?.withSyntheticPropertiesScopeOrSelf(type.coneType)
?.let { convertToKtTypeScope(it) }
}
override fun getSyntheticJavaPropertiesScope(type: KtType): KtTypeScope? {
check(type is KtFirType) { "KtFirScopeProvider can only work with KtFirType, but ${type::class} was provided" }
val firTypeScope = getFirTypeScope(type) ?: return null
return FirSyntheticPropertiesScope.createIfSyntheticNamesProviderIsDefined(
firResolveSession.useSiteFirSession,
type.coneType,
firTypeScope
)?.let { convertToKtTypeScope(it) }
val typeScope = getFirTypeScope(type) ?: return null
return getFirSyntheticPropertiesScope(type.coneType, typeScope)?.let { convertToKtTypeScope(it) }
}
override fun getImportingScopeContext(file: KtFile): KtScopeContext {
@@ -209,7 +211,9 @@ internal class KtFirScopeProvider(
}
val firScopes = towerDataElementsIndexed.flatMap { (index, towerDataElement) ->
val availableScopes = towerDataElement.getAvailableScopes().flatMap { flattenFirScope(it) }
val availableScopes = towerDataElement
.getAvailableScopes { coneType -> withSyntheticPropertiesScopeOrSelf(coneType) }
.flatMap { flattenFirScope(it) }
availableScopes.map { IndexedValue(index, it) }
}
val ktScopesWithKinds = createScopesWithKind(firScopes)
@@ -245,7 +249,7 @@ internal class KtFirScopeProvider(
is FirNameAwareOnlyClassifiersScope -> getScopeKind(firScope.delegate, indexInTower)
is FirLocalScope -> KtScopeKind.LocalScope(indexInTower)
is FirTypeScope -> KtScopeKind.SimpleTypeScope(indexInTower)
is FirTypeScope -> KtScopeKind.TypeScope(indexInTower)
is FirTypeParameterScope -> KtScopeKind.TypeParameterScope(indexInTower)
is FirPackageMemberScope -> KtScopeKind.PackageMemberScope(indexInTower)
@@ -275,14 +279,23 @@ internal class KtFirScopeProvider(
}
}
private fun getFirTypeScope(type: KtType): FirTypeScope? {
check(type is KtFirType) { "KtFirScopeProvider can only work with KtFirType, but ${type::class} was provided" }
return type.coneType.scope(
private fun getFirTypeScope(type: KtFirType): FirTypeScope? = type.coneType.scope(
firResolveSession.useSiteFirSession,
getScopeSession(),
FakeOverrideTypeCalculator.Forced,
requiredMembersPhase = FirResolvePhase.STATUS,
)
private fun getFirSyntheticPropertiesScope(coneType: ConeKotlinType, typeScope: FirTypeScope): FirSyntheticPropertiesScope? =
FirSyntheticPropertiesScope.createIfSyntheticNamesProviderIsDefined(
firResolveSession.useSiteFirSession,
getScopeSession(),
FakeOverrideTypeCalculator.Forced,
requiredMembersPhase = FirResolvePhase.STATUS,
coneType,
typeScope
)
private fun FirTypeScope.withSyntheticPropertiesScopeOrSelf(coneType: ConeKotlinType): FirTypeScope {
val syntheticPropertiesScope = getFirSyntheticPropertiesScope(coneType, this) ?: return this
return FirTypeScopeWithSyntheticProperties(typeScope = this, syntheticPropertiesScope)
}
private fun buildJavaEnhancementDeclaredMemberScope(
@@ -310,6 +323,43 @@ internal class KtFirScopeProvider(
}
}
private class FirTypeScopeWithSyntheticProperties(
val typeScope: FirTypeScope,
val syntheticPropertiesScope: FirSyntheticPropertiesScope,
) : FirTypeScope() {
override fun getCallableNames(): Set<Name> = typeScope.getCallableNames() + syntheticPropertiesScope.getCallableNames()
override fun getClassifierNames(): Set<Name> = typeScope.getClassifierNames()
override fun mayContainName(name: Name): Boolean = typeScope.mayContainName(name) || syntheticPropertiesScope.mayContainName(name)
override val scopeOwnerLookupNames: List<String> get() = typeScope.scopeOwnerLookupNames
override fun processDirectOverriddenFunctionsWithBaseScope(
functionSymbol: FirNamedFunctionSymbol,
processor: (FirNamedFunctionSymbol, FirTypeScope) -> ProcessorAction,
): ProcessorAction = typeScope.processDirectOverriddenFunctionsWithBaseScope(functionSymbol, processor)
override fun processDirectOverriddenPropertiesWithBaseScope(
propertySymbol: FirPropertySymbol,
processor: (FirPropertySymbol, FirTypeScope) -> ProcessorAction,
): ProcessorAction = typeScope.processDirectOverriddenPropertiesWithBaseScope(propertySymbol, processor)
override fun processClassifiersByNameWithSubstitution(name: Name, processor: (FirClassifierSymbol<*>, ConeSubstitutor) -> Unit) {
typeScope.processClassifiersByNameWithSubstitution(name, processor)
}
override fun processFunctionsByName(name: Name, processor: (FirNamedFunctionSymbol) -> Unit) {
typeScope.processFunctionsByName(name, processor)
}
override fun processPropertiesByName(name: Name, processor: (FirVariableSymbol<*>) -> Unit) {
typeScope.processPropertiesByName(name, processor)
syntheticPropertiesScope.processPropertiesByName(name, processor)
}
override fun processDeclaredConstructors(processor: (FirConstructorSymbol) -> Unit) {
typeScope.processDeclaredConstructors(processor)
}
}
private class EnumEntryContainingNamesAwareScope(private val originalScope: FirContainingNamesAwareScope) : FirContainingNamesAwareScope() {
override fun getCallableNames(): Set<Name> = originalScope.getCallableNames()
override fun getClassifierNames(): Set<Name> = originalScope.getClassifierNames()
@@ -75,4 +75,10 @@ public class FirIdeDependentAnalysisSourceModuleScopeContextForPositionTestGener
public void testSimpleScopeContextForPosition() throws Exception {
runTest("analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/simpleScopeContextForPosition.kt");
}
@Test
@TestMetadata("syntheticPropertiesScope.kt")
public void testSyntheticPropertiesScope() throws Exception {
runTest("analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/syntheticPropertiesScope.kt");
}
}
@@ -81,4 +81,10 @@ public class FirIdeDependentAnalysisSourceModuleTypeScopeTestGenerated extends A
public void testTypeParamList() throws Exception {
runTest("analysis/analysis-api/testData/components/scopeProvider/typeScope/typeParamList.kt");
}
@Test
@TestMetadata("typeWithSyntheticProperties.kt")
public void testTypeWithSyntheticProperties() throws Exception {
runTest("analysis/analysis-api/testData/components/scopeProvider/typeScope/typeWithSyntheticProperties.kt");
}
}
@@ -75,4 +75,10 @@ public class FirIdeNormalAnalysisSourceModuleScopeContextForPositionTestGenerate
public void testSimpleScopeContextForPosition() throws Exception {
runTest("analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/simpleScopeContextForPosition.kt");
}
@Test
@TestMetadata("syntheticPropertiesScope.kt")
public void testSyntheticPropertiesScope() throws Exception {
runTest("analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/syntheticPropertiesScope.kt");
}
}
@@ -81,4 +81,10 @@ public class FirIdeNormalAnalysisSourceModuleTypeScopeTestGenerated extends Abst
public void testTypeParamList() throws Exception {
runTest("analysis/analysis-api/testData/components/scopeProvider/typeScope/typeParamList.kt");
}
@Test
@TestMetadata("typeWithSyntheticProperties.kt")
public void testTypeWithSyntheticProperties() throws Exception {
runTest("analysis/analysis-api/testData/components/scopeProvider/typeScope/typeWithSyntheticProperties.kt");
}
}
@@ -75,4 +75,10 @@ public class FirStandaloneNormalAnalysisSourceModuleScopeContextForPositionTestG
public void testSimpleScopeContextForPosition() throws Exception {
runTest("analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/simpleScopeContextForPosition.kt");
}
@Test
@TestMetadata("syntheticPropertiesScope.kt")
public void testSyntheticPropertiesScope() throws Exception {
runTest("analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/syntheticPropertiesScope.kt");
}
}
@@ -81,4 +81,10 @@ public class FirStandaloneNormalAnalysisSourceModuleTypeScopeTestGenerated exten
public void testTypeParamList() throws Exception {
runTest("analysis/analysis-api/testData/components/scopeProvider/typeScope/typeParamList.kt");
}
@Test
@TestMetadata("typeWithSyntheticProperties.kt")
public void testTypeWithSyntheticProperties() throws Exception {
runTest("analysis/analysis-api/testData/components/scopeProvider/typeScope/typeWithSyntheticProperties.kt");
}
}
@@ -90,7 +90,7 @@ public interface KtScopeProviderMixIn : KtAnalysisSessionMixIn {
* Inside the `LIST_KT_ELEMENT.getKtType().getTypeScope()` would contain the `get(i: Int): String` method with substituted type `T = String`
*
* @return type scope for the given type if given `KtType` is not error type, `null` otherwise.
* Returned [KtTypeScope] doesn't include synthetic Java properties. To get such properties use [getSyntheticJavaPropertiesScope].
* Returned [KtTypeScope] includes synthetic Java properties.
*
* @see KtTypeScope
* @see KtTypeProviderMixIn.getKtType
@@ -105,11 +105,10 @@ public interface KtScopeProviderMixIn : KtAnalysisSessionMixIn {
withValidityAssertion { analysisSession.scopeProvider.getSyntheticJavaPropertiesScope(this) }
/**
* Scopes in returned [KtScopeContext] don't include synthetic Java properties.
* To get such properties use [getSyntheticJavaPropertiesScope].
*
* For each scope in [KtScopeContext] an index is calculated. The indexes are relative to position, and they are only known for
* scopes obtained with [getScopeContextForPosition].
*
* Scopes with [KtScopeKind.TypeScope] include synthetic Java properties.
*/
public fun KtFile.getScopeContextForPosition(positionInFakeFile: KtElement): KtScopeContext =
withValidityAssertion { analysisSession.scopeProvider.getScopeContextForPosition(this, positionInFakeFile) }
@@ -174,14 +173,10 @@ public sealed class KtScopeKind {
public class LocalScope(override val indexInTower: Int) : KtScopeKind()
public sealed class TypeScope : KtScopeKind()
/**
* Represents [KtTypeScope], which doesn't include synthetic Java properties of corresponding type.
* Represents [KtScope] for type, which include synthetic Java properties of corresponding type.
*/
public class SimpleTypeScope(override val indexInTower: Int) : TypeScope()
public class SyntheticJavaPropertiesScope(override val indexInTower: Int) : TypeScope()
public class TypeScope(override val indexInTower: Int) : KtScopeKind()
public sealed class NonLocalScope : KtScopeKind()
@@ -6,7 +6,7 @@ implicit receivers:
scopes:
LocalScope, index = 0, empty
SimpleTypeScope, index = 1
TypeScope, index = 1
classifiers: 0
callables: 4
fun memberInContext()
@@ -9,7 +9,7 @@ implicit receivers:
scopes:
LocalScope, index = 0, empty
SimpleTypeScope, index = 1
TypeScope, index = 1
classifiers: 0
callables: 4
KtFunctionSymbol:
@@ -11,7 +11,7 @@ scopes:
LocalScope, index = 1, empty
SimpleTypeScope, index = 2
TypeScope, index = 2
classifiers: 1
companion object
callables: 11
@@ -40,7 +40,7 @@ scopes:
companion object
callables: 0
SimpleTypeScope, index = 5
TypeScope, index = 5
classifiers: 0
callables: 3
fun equals(other: kotlin.Any?): kotlin.Boolean
@@ -17,7 +17,7 @@ scopes:
LocalScope, index = 1, empty
SimpleTypeScope, index = 2
TypeScope, index = 2
classifiers: 1
KtNamedClassOrObjectSymbol:
annotationsList: []
@@ -642,7 +642,7 @@ scopes:
visibility: Public
callables: 0
SimpleTypeScope, index = 5
TypeScope, index = 5
classifiers: 0
callables: 3
KtFunctionSymbol:
@@ -7,13 +7,13 @@ implicit receivers:
owner symbol: KtFirAnonymousFunctionSymbol
scopes:
SimpleTypeScope, index = 0, empty
TypeScope, index = 0, empty
LocalScope, index = 1, empty
LocalScope, index = 2, empty
SimpleTypeScope, index = 3
TypeScope, index = 3
classifiers: 0
callables: 5
fun add(e: T)
@@ -16,13 +16,13 @@ implicit receivers:
owner symbol: KtFirAnonymousFunctionSymbol
scopes:
SimpleTypeScope, index = 0, empty
TypeScope, index = 0, empty
LocalScope, index = 1, empty
LocalScope, index = 2, empty
SimpleTypeScope, index = 3
TypeScope, index = 3
classifiers: 0
callables: 5
KtFunctionSymbol:
@@ -11,7 +11,7 @@ scopes:
LocalScope, index = 1, empty
SimpleTypeScope, index = 2
TypeScope, index = 2
classifiers: 0
callables: 5
val propertyInY: kotlin.Int
@@ -28,7 +28,7 @@ scopes:
LocalScope, index = 1, empty
SimpleTypeScope, index = 2
TypeScope, index = 2
classifiers: 0
callables: 5
KtKotlinPropertySymbol:
@@ -10,7 +10,7 @@ implicit receivers:
owner symbol: KtFirNamedClassOrObjectSymbol
scopes:
SimpleTypeScope, index = 0
TypeScope, index = 0
classifiers: 0
callables: 4
fun memberInA()
@@ -22,7 +22,7 @@ scopes:
LocalScope, index = 2, empty
SimpleTypeScope, index = 3
TypeScope, index = 3
classifiers: 0
callables: 4
fun memberInB()
@@ -58,7 +58,7 @@ scopes:
T
callables: 0
SimpleTypeScope, index = 10
TypeScope, index = 10
classifiers: 2
class NestedInC
class NestedInJavaClass
@@ -19,7 +19,7 @@ implicit receivers:
owner symbol: KtFirNamedClassOrObjectSymbol
scopes:
SimpleTypeScope, index = 0
TypeScope, index = 0
classifiers: 0
callables: 4
KtFunctionSymbol:
@@ -156,7 +156,7 @@ scopes:
LocalScope, index = 2, empty
SimpleTypeScope, index = 3
TypeScope, index = 3
classifiers: 0
callables: 4
KtFunctionSymbol:
@@ -416,7 +416,7 @@ scopes:
variance: INVARIANT
callables: 0
SimpleTypeScope, index = 10
TypeScope, index = 10
classifiers: 2
KtNamedClassOrObjectSymbol:
annotationsList: []
@@ -0,0 +1,11 @@
// FILE: JavaClass.java
public class JavaClass {
public Integer getValue() {
return 1;
}
}
// FILE: main.kt
fun JavaClass.test() {
<expr>e</expr>
}
@@ -0,0 +1,37 @@
element: e
implicit receivers:
type: JavaClass
owner symbol: KtFirFunctionSymbol
scopes:
LocalScope, index = 0, empty
TypeScope, index = 1
classifiers: 0
callables: 5
fun getValue(): kotlin.Int?
fun equals(other: kotlin.Any?): kotlin.Boolean
fun hashCode(): kotlin.Int
fun toString(): kotlin.String
val value: kotlin.Int?
get()
LocalScope, index = 2, empty
ExplicitSimpleImportingScope, index = 3, empty
PackageMemberScope, index = 4
classifiers: 0
callables: 1
fun JavaClass.test()
DefaultSimpleImportingScope, index = 5
DefaultSimpleImportingScope, index = 6
ExplicitStarImportingScope, index = 7, empty
DefaultSimpleImportingScope, index = 8
DefaultStarImportingScope, index = 9
@@ -0,0 +1,243 @@
element: e
implicit receivers:
type: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: JavaClass
owner symbol: KtFirFunctionSymbol
scopes:
LocalScope, index = 0, empty
TypeScope, index = 1
classifiers: 0
callables: 5
KtFunctionSymbol:
annotationsList: []
callableIdIfNonLocal: /JavaClass.getValue
contextReceivers: []
contractEffects: []
hasStableParameterNames: false
isBuiltinFunctionInvoke: false
isExtension: false
isExternal: false
isInfix: false
isInline: false
isOperator: false
isOverride: false
isStatic: false
isSuspend: false
modality: OPEN
name: getValue
origin: JAVA
receiverParameter: null
returnType: KtFlexibleType:
annotationsList: []
type: kotlin/Int!
symbolKind: CLASS_MEMBER
typeParameters: []
valueParameters: []
visibility: Public
KtFunctionSymbol:
annotationsList: []
callableIdIfNonLocal: kotlin/Any.equals
contextReceivers: []
contractEffects: []
hasStableParameterNames: true
isBuiltinFunctionInvoke: false
isExtension: false
isExternal: false
isInfix: false
isInline: false
isOperator: true
isOverride: false
isStatic: false
isSuspend: false
modality: OPEN
name: equals
origin: LIBRARY
receiverParameter: null
returnType: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: kotlin/Boolean
symbolKind: CLASS_MEMBER
typeParameters: []
valueParameters: [
KtValueParameterSymbol:
annotationsList: []
callableIdIfNonLocal: null
contextReceivers: []
generatedPrimaryConstructorProperty: null
hasDefaultValue: false
isCrossinline: false
isExtension: false
isImplicitLambdaParameter: false
isNoinline: false
isVararg: false
name: other
origin: LIBRARY
receiverParameter: null
returnType: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: kotlin/Any?
symbolKind: LOCAL
typeParameters: []
]
visibility: Public
KtFunctionSymbol:
annotationsList: []
callableIdIfNonLocal: kotlin/Any.hashCode
contextReceivers: []
contractEffects: []
hasStableParameterNames: true
isBuiltinFunctionInvoke: false
isExtension: false
isExternal: false
isInfix: false
isInline: false
isOperator: false
isOverride: false
isStatic: false
isSuspend: false
modality: OPEN
name: hashCode
origin: LIBRARY
receiverParameter: null
returnType: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: kotlin/Int
symbolKind: CLASS_MEMBER
typeParameters: []
valueParameters: []
visibility: Public
KtFunctionSymbol:
annotationsList: []
callableIdIfNonLocal: kotlin/Any.toString
contextReceivers: []
contractEffects: []
hasStableParameterNames: true
isBuiltinFunctionInvoke: false
isExtension: false
isExternal: false
isInfix: false
isInline: false
isOperator: false
isOverride: false
isStatic: false
isSuspend: false
modality: OPEN
name: toString
origin: LIBRARY
receiverParameter: null
returnType: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: kotlin/String
symbolKind: CLASS_MEMBER
typeParameters: []
valueParameters: []
visibility: Public
KtSyntheticJavaPropertySymbol:
annotationsList: []
backingFieldSymbol: null
callableIdIfNonLocal: /JavaClass.value
contextReceivers: []
getter: KtPropertyGetterSymbol:
annotationsList: []
callableIdIfNonLocal: /JavaClass.getValue
contextReceivers: []
hasBody: false
hasStableParameterNames: true
isDefault: false
isExtension: false
isInline: false
isOverride: false
modality: OPEN
origin: JAVA_SYNTHETIC_PROPERTY
receiverParameter: null
returnType: KtFlexibleType:
annotationsList: []
type: kotlin/Int!
symbolKind: ACCESSOR
typeParameters: []
valueParameters: []
visibility: Public
hasBackingField: true
hasGetter: true
hasSetter: false
initializer: null
isDelegatedProperty: false
isExtension: false
isFromPrimaryConstructor: false
isOverride: false
isStatic: false
isVal: true
javaGetterSymbol: KtFunctionSymbol(/JavaClass.getValue)
javaSetterSymbol: null
modality: OPEN
name: value
origin: JAVA_SYNTHETIC_PROPERTY
receiverParameter: null
returnType: KtFlexibleType:
annotationsList: []
type: kotlin/Int!
setter: null
symbolKind: CLASS_MEMBER
typeParameters: []
visibility: Public
LocalScope, index = 2, empty
ExplicitSimpleImportingScope, index = 3, empty
PackageMemberScope, index = 4
classifiers: 0
callables: 1
KtFunctionSymbol:
annotationsList: []
callableIdIfNonLocal: /test
contextReceivers: []
contractEffects: []
hasStableParameterNames: true
isBuiltinFunctionInvoke: false
isExtension: true
isExternal: false
isInfix: false
isInline: false
isOperator: false
isOverride: false
isStatic: false
isSuspend: false
modality: FINAL
name: test
origin: SOURCE
receiverParameter: KtReceiverParameterSymbol:
annotationsList: []
origin: SOURCE
owningCallableSymbol: KtFunctionSymbol(/test)
type: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: JavaClass
returnType: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: kotlin/Unit
symbolKind: TOP_LEVEL
typeParameters: []
valueParameters: []
visibility: Public
DefaultSimpleImportingScope, index = 5
DefaultSimpleImportingScope, index = 6
ExplicitStarImportingScope, index = 7, empty
DefaultSimpleImportingScope, index = 8
DefaultStarImportingScope, index = 9
@@ -0,0 +1,13 @@
// FILE: JavaClass.java
public class JavaClass {
public Integer getValue() {
return 1;
}
}
// FILE: main.kt
class A : JavaClass()
fun test(a: A) {
<expr>a</expr>
}
@@ -0,0 +1,15 @@
KtTypeScope:
fun getValue(): kotlin.Int!
fun equals(other: kotlin.Any?): kotlin.Boolean
fun hashCode(): kotlin.Int
fun toString(): kotlin.String
val value: kotlin.Int!
Declaration Scope:
fun getValue(): kotlin.Int?
fun equals(other: kotlin.Any?): kotlin.Boolean
fun hashCode(): kotlin.Int
fun toString(): kotlin.String
val value: kotlin.Int?
get()
@@ -0,0 +1,220 @@
expression: a
KtType: A
KtTypeScope:
KtFunctionLikeSignature:
receiverType = null
returnType = kotlin.Int!
symbol = /JavaClass.getValue(<dispatch receiver>: JavaClass): kotlin.Int!
valueParameters = []
callableIdIfNonLocal = /JavaClass.getValue
KtFunctionLikeSignature:
receiverType = null
returnType = kotlin.Boolean
symbol = kotlin/Any.equals(<dispatch receiver>: kotlin.Any, other: kotlin.Any?): kotlin.Boolean
valueParameters = [
KtVariableLikeSignature:
name = other
receiverType = null
returnType = kotlin.Any?
symbol = other: kotlin.Any?
callableIdIfNonLocal = null
]
callableIdIfNonLocal = kotlin/Any.equals
KtFunctionLikeSignature:
receiverType = null
returnType = kotlin.Int
symbol = kotlin/Any.hashCode(<dispatch receiver>: kotlin.Any): kotlin.Int
valueParameters = []
callableIdIfNonLocal = kotlin/Any.hashCode
KtFunctionLikeSignature:
receiverType = null
returnType = kotlin.String
symbol = kotlin/Any.toString(<dispatch receiver>: kotlin.Any): kotlin.String
valueParameters = []
callableIdIfNonLocal = kotlin/Any.toString
KtVariableLikeSignature:
name = value
receiverType = null
returnType = kotlin.Int!
symbol = val value: kotlin.Int!
callableIdIfNonLocal = /JavaClass.value
Declaration Scope:
KtFunctionSymbol:
annotationsList: []
callableIdIfNonLocal: /JavaClass.getValue
contextReceivers: []
contractEffects: []
hasStableParameterNames: false
isBuiltinFunctionInvoke: false
isExtension: false
isExternal: false
isInfix: false
isInline: false
isOperator: false
isOverride: false
isStatic: false
isSuspend: false
modality: OPEN
name: getValue
origin: JAVA
receiverParameter: null
returnType: KtFlexibleType:
annotationsList: []
type: kotlin/Int!
symbolKind: CLASS_MEMBER
typeParameters: []
valueParameters: []
visibility: Public
KtFunctionSymbol:
annotationsList: []
callableIdIfNonLocal: kotlin/Any.equals
contextReceivers: []
contractEffects: []
hasStableParameterNames: true
isBuiltinFunctionInvoke: false
isExtension: false
isExternal: false
isInfix: false
isInline: false
isOperator: true
isOverride: false
isStatic: false
isSuspend: false
modality: OPEN
name: equals
origin: LIBRARY
receiverParameter: null
returnType: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: kotlin/Boolean
symbolKind: CLASS_MEMBER
typeParameters: []
valueParameters: [
KtValueParameterSymbol:
annotationsList: []
callableIdIfNonLocal: null
contextReceivers: []
generatedPrimaryConstructorProperty: null
hasDefaultValue: false
isCrossinline: false
isExtension: false
isImplicitLambdaParameter: false
isNoinline: false
isVararg: false
name: other
origin: LIBRARY
receiverParameter: null
returnType: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: kotlin/Any?
symbolKind: LOCAL
typeParameters: []
]
visibility: Public
KtFunctionSymbol:
annotationsList: []
callableIdIfNonLocal: kotlin/Any.hashCode
contextReceivers: []
contractEffects: []
hasStableParameterNames: true
isBuiltinFunctionInvoke: false
isExtension: false
isExternal: false
isInfix: false
isInline: false
isOperator: false
isOverride: false
isStatic: false
isSuspend: false
modality: OPEN
name: hashCode
origin: LIBRARY
receiverParameter: null
returnType: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: kotlin/Int
symbolKind: CLASS_MEMBER
typeParameters: []
valueParameters: []
visibility: Public
KtFunctionSymbol:
annotationsList: []
callableIdIfNonLocal: kotlin/Any.toString
contextReceivers: []
contractEffects: []
hasStableParameterNames: true
isBuiltinFunctionInvoke: false
isExtension: false
isExternal: false
isInfix: false
isInline: false
isOperator: false
isOverride: false
isStatic: false
isSuspend: false
modality: OPEN
name: toString
origin: LIBRARY
receiverParameter: null
returnType: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: kotlin/String
symbolKind: CLASS_MEMBER
typeParameters: []
valueParameters: []
visibility: Public
KtSyntheticJavaPropertySymbol:
annotationsList: []
backingFieldSymbol: null
callableIdIfNonLocal: /JavaClass.value
contextReceivers: []
getter: KtPropertyGetterSymbol:
annotationsList: []
callableIdIfNonLocal: /JavaClass.getValue
contextReceivers: []
hasBody: false
hasStableParameterNames: true
isDefault: false
isExtension: false
isInline: false
isOverride: false
modality: OPEN
origin: JAVA_SYNTHETIC_PROPERTY
receiverParameter: null
returnType: KtFlexibleType:
annotationsList: []
type: kotlin/Int!
symbolKind: ACCESSOR
typeParameters: []
valueParameters: []
visibility: Public
hasBackingField: true
hasGetter: true
hasSetter: false
initializer: null
isDelegatedProperty: false
isExtension: false
isFromPrimaryConstructor: false
isOverride: false
isStatic: false
isVal: true
javaGetterSymbol: KtFunctionSymbol(/JavaClass.getValue)
javaSetterSymbol: null
modality: OPEN
name: value
origin: JAVA_SYNTHETIC_PROPERTY
receiverParameter: null
returnType: KtFlexibleType:
annotationsList: []
type: kotlin/Int!
setter: null
symbolKind: CLASS_MEMBER
typeParameters: []
visibility: Public
@@ -269,18 +269,22 @@ class FirTowerDataElement(
*
* Note that a scope for a companion object is an implicit scope.
*/
fun getAvailableScopes(): List<FirScope> = when {
fun getAvailableScopes(
processTypeScope: FirTypeScope.(ConeKotlinType) -> FirTypeScope = { this },
): List<FirScope> = when {
scope != null -> listOf(scope)
implicitReceiver != null -> listOf(implicitReceiver.getImplicitScope())
contextReceiverGroup != null -> contextReceiverGroup.map { it.getImplicitScope() }
implicitReceiver != null -> listOf(implicitReceiver.getImplicitScope(processTypeScope))
contextReceiverGroup != null -> contextReceiverGroup.map { it.getImplicitScope(processTypeScope) }
else -> error("Tower data element is expected to have either scope or implicit receivers.")
}
private fun ImplicitReceiverValue<*>.getImplicitScope(): FirScope {
private fun ImplicitReceiverValue<*>.getImplicitScope(
processTypeScope: FirTypeScope.(ConeKotlinType) -> FirTypeScope,
): FirScope {
return when (type.fullyExpandedType(useSiteSession)) {
is ConeErrorType,
is ConeStubType -> FirTypeScope.Empty
else -> implicitScope ?: error("Scope for type ${type::class.simpleName} is null.")
else -> implicitScope?.processTypeScope(type) ?: error("Scope for type ${type::class.simpleName} is null.")
}
}
}