[AA] KtSymbolPointer: introduce pointsToTheSameSymbolAs method
^KT-55191
This commit is contained in:
committed by
Space Team
parent
19a0a1fcd8
commit
13917887e0
+8
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.KtFe10AnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.KtFe10DescEnumEntrySymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtEnumEntrySymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
@@ -33,4 +34,9 @@ class KtFe10DescEnumEntrySymbolPointer(private val classId: ClassId, private val
|
||||
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
override fun pointsToTheSameSymbolAs(other: KtSymbolPointer<KtSymbol>): Boolean = this === other ||
|
||||
other is KtFe10DescEnumEntrySymbolPointer &&
|
||||
other.classId == classId &&
|
||||
other.entryName == entryName
|
||||
}
|
||||
|
||||
+8
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.analysis.api.descriptors.KtFe10AnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.base.getSymbolPointerSignature
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.base.toKtCallableSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtFunctionLikeSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.findClassAcrossModuleDependencies
|
||||
@@ -44,4 +45,9 @@ class KtFe10DescFunctionLikeSymbolPointer<T : KtFunctionLikeSymbol>(
|
||||
.firstOrNull { it.getSymbolPointerSignature() == signature }
|
||||
?.toKtCallableSymbol(analysisContext) as? T
|
||||
}
|
||||
}
|
||||
|
||||
override fun pointsToTheSameSymbolAs(other: KtSymbolPointer<KtSymbol>): Boolean = this === other ||
|
||||
other is KtFe10DescFunctionLikeSymbolPointer &&
|
||||
other.callableId == callableId &&
|
||||
other.signature == signature
|
||||
}
|
||||
|
||||
+7
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.KtFe10AnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.KtFe10DescNamedClassOrObjectSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtNamedClassOrObjectSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
||||
import org.jetbrains.kotlin.descriptors.findClassAcrossModuleDependencies
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
@@ -22,4 +23,8 @@ class KtFe10DescNamedClassOrObjectSymbolSymbol(private val classId: ClassId) : K
|
||||
val descriptor = analysisContext.resolveSession.moduleDescriptor.findClassAcrossModuleDependencies(classId) ?: return null
|
||||
return KtFe10DescNamedClassOrObjectSymbol(descriptor, analysisContext)
|
||||
}
|
||||
}
|
||||
|
||||
override fun pointsToTheSameSymbolAs(other: KtSymbolPointer<KtSymbol>): Boolean = this === other ||
|
||||
other is KtFe10DescNamedClassOrObjectSymbolSymbol &&
|
||||
other.classId == classId
|
||||
}
|
||||
|
||||
+7
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.KtFe10AnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.KtFe10DescSamConstructorSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSamConstructorSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
||||
import org.jetbrains.kotlin.descriptors.findClassAcrossModuleDependencies
|
||||
import org.jetbrains.kotlin.load.java.sam.JvmSamConversionOracle
|
||||
@@ -36,4 +37,8 @@ class KtFe10DescSamConstructorSymbolPointer(private val classId: ClassId) : KtSy
|
||||
|
||||
return KtFe10DescSamConstructorSymbol(constructorDescriptor, analysisContext)
|
||||
}
|
||||
}
|
||||
|
||||
override fun pointsToTheSameSymbolAs(other: KtSymbolPointer<KtSymbol>): Boolean = this === other ||
|
||||
other is KtFe10DescSamConstructorSymbolPointer &&
|
||||
other.classId == classId
|
||||
}
|
||||
|
||||
+7
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.KtF
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.base.getSymbolDescriptor
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtBackingFieldSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtPropertyAccessorSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtPsiBasedSymbolPointer
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
||||
import org.jetbrains.kotlin.descriptors.PropertyAccessorDescriptor
|
||||
@@ -31,4 +32,8 @@ class KtFe10DescSyntheticFieldSymbolPointer(
|
||||
val syntheticFieldDescriptor = SyntheticFieldDescriptor(accessorDescriptor, accessorDescriptor.correspondingProperty.source)
|
||||
return KtFe10DescSyntheticFieldSymbol(syntheticFieldDescriptor, analysisContext)
|
||||
}
|
||||
}
|
||||
|
||||
override fun pointsToTheSameSymbolAs(other: KtSymbolPointer<KtSymbol>): Boolean = this === other ||
|
||||
other is KtFe10DescSyntheticFieldSymbolPointer &&
|
||||
other.psiPointer.pointsToTheSameSymbolAs(psiPointer)
|
||||
}
|
||||
|
||||
+7
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.KtFe10AnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.KtFe10PackageSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtPackageSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
|
||||
@@ -18,4 +19,8 @@ internal class KtFe10PackageSymbolPointer(private val packageName: FqName) : KtS
|
||||
check(analysisSession is KtFe10AnalysisSession)
|
||||
return KtFe10PackageSymbol(packageName, analysisSession.analysisContext)
|
||||
}
|
||||
}
|
||||
|
||||
override fun pointsToTheSameSymbolAs(other: KtSymbolPointer<KtSymbol>): Boolean = this === other ||
|
||||
other is KtFe10PackageSymbolPointer &&
|
||||
other.packageName == packageName
|
||||
}
|
||||
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.analysis.api.descriptors.symbols.pointers
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtPropertySetterSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtValueParameterSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtPsiBasedSymbolPointer
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
||||
|
||||
class KtFe10PsiDefaultSetterParameterSymbolPointer(
|
||||
private val propertySymbolPointer: KtPsiBasedSymbolPointer<KtPropertySetterSymbol>,
|
||||
) : KtSymbolPointer<KtValueParameterSymbol>() {
|
||||
@Deprecated("Consider using org.jetbrains.kotlin.analysis.api.KtAnalysisSession.restoreSymbol")
|
||||
override fun restoreSymbol(analysisSession: KtAnalysisSession): KtValueParameterSymbol? {
|
||||
val property = with(analysisSession) { propertySymbolPointer.restoreSymbol() }
|
||||
return property?.parameter
|
||||
}
|
||||
|
||||
override fun pointsToTheSameSymbolAs(other: KtSymbolPointer<KtSymbol>): Boolean = this === other ||
|
||||
other is KtFe10PsiDefaultSetterParameterSymbolPointer &&
|
||||
other.propertySymbolPointer.pointsToTheSameSymbolAs(propertySymbolPointer)
|
||||
}
|
||||
+4
-4
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.analysis.api.descriptors.symbols.calculateHashCode
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.base.toKtType
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.isEqualTo
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.pointers.KtFe10NeverRestoringSymbolPointer
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.pointers.KtFe10PsiDefaultSetterParameterSymbolPointer
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.psiBased.base.createErrorType
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.utils.cached
|
||||
import org.jetbrains.kotlin.analysis.api.impl.base.annotations.KtEmptyAnnotationsList
|
||||
@@ -24,7 +25,6 @@ import org.jetbrains.kotlin.analysis.api.symbols.KtSymbolOrigin
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtValueParameterSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtPsiBasedSymbolPointer
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.symbolPointerDelegator
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtType
|
||||
import org.jetbrains.kotlin.descriptors.VariableDescriptor
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
@@ -72,9 +72,9 @@ internal class KtFe10PsiDefaultSetterParameterSymbol(
|
||||
|
||||
context(KtAnalysisSession)
|
||||
override fun createPointer(): KtSymbolPointer<KtValueParameterSymbol> = withValidityAssertion {
|
||||
KtPsiBasedSymbolPointer.createForSymbolFromPsi<KtPropertySetterSymbol>(accessorPsi)?.let { symbolPointer ->
|
||||
symbolPointerDelegator(symbolPointer) { it.parameter }
|
||||
} ?: KtFe10NeverRestoringSymbolPointer()
|
||||
KtPsiBasedSymbolPointer.createForSymbolFromPsi<KtPropertySetterSymbol>(accessorPsi)
|
||||
?.let(::KtFe10PsiDefaultSetterParameterSymbolPointer)
|
||||
?: KtFe10NeverRestoringSymbolPointer()
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean = isEqualTo(other)
|
||||
|
||||
+3
-12
@@ -13,10 +13,7 @@ import org.jetbrains.kotlin.analysis.api.base.KtContextReceiver
|
||||
import org.jetbrains.kotlin.analysis.api.fir.KtSymbolByFirBuilder
|
||||
import org.jetbrains.kotlin.analysis.api.fir.annotations.KtFirAnnotationListForDeclaration
|
||||
import org.jetbrains.kotlin.analysis.api.fir.findPsi
|
||||
import org.jetbrains.kotlin.analysis.api.fir.symbols.pointers.FirCallableSignature
|
||||
import org.jetbrains.kotlin.analysis.api.fir.symbols.pointers.KtFirMemberPropertySymbolPointer
|
||||
import org.jetbrains.kotlin.analysis.api.fir.symbols.pointers.KtFirTopLevelPropertySymbolPointer
|
||||
import org.jetbrains.kotlin.analysis.api.fir.symbols.pointers.requireOwnerPointer
|
||||
import org.jetbrains.kotlin.analysis.api.fir.symbols.pointers.*
|
||||
import org.jetbrains.kotlin.analysis.api.fir.utils.cached
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeToken
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
@@ -25,7 +22,6 @@ import org.jetbrains.kotlin.analysis.api.symbols.markers.KtSymbolKind
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtPsiBasedSymbolPointer
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.UnsupportedSymbolKind
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.symbolPointerDelegator
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtType
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.LLFirResolveSession
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
@@ -128,13 +124,7 @@ internal class KtFirKotlinPropertySymbol(
|
||||
context(KtAnalysisSession)
|
||||
override fun createPointer(): KtSymbolPointer<KtKotlinPropertySymbol> = withValidityAssertion {
|
||||
KtPsiBasedSymbolPointer.createForSymbolFromSource<KtVariableLikeSymbol>(this)?.let { psiPointer ->
|
||||
return symbolPointerDelegator(psiPointer) {
|
||||
when (it) {
|
||||
is KtKotlinPropertySymbol -> it
|
||||
is KtValueParameterSymbol -> it.generatedPrimaryConstructorProperty
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
return KtFirPsiBasedPropertySymbolPointer(psiPointer)
|
||||
}
|
||||
|
||||
return when (val kind = symbolKind) {
|
||||
@@ -158,3 +148,4 @@ internal class KtFirKotlinPropertySymbol(
|
||||
override fun equals(other: Any?): Boolean = symbolEquals(other)
|
||||
override fun hashCode(): Int = symbolHashCode()
|
||||
}
|
||||
|
||||
|
||||
+2
-8
@@ -12,7 +12,7 @@ import com.intellij.psi.PsiManager
|
||||
import com.intellij.psi.impl.file.PsiPackageImpl
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.fir.KtFirAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.fir.symbols.pointers.KtFirPackageSymbolPointer
|
||||
import org.jetbrains.kotlin.analysis.api.fir.utils.cached
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeOwner
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeToken
|
||||
@@ -20,7 +20,6 @@ import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtPackageSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbolOrigin
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.symbolPointer
|
||||
import org.jetbrains.kotlin.analysis.providers.createPackageProvider
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
|
||||
@@ -38,12 +37,7 @@ class KtFirPackageSymbol(
|
||||
get() = withValidityAssertion { KtSymbolOrigin.SOURCE } // TODO
|
||||
|
||||
context(KtAnalysisSession)
|
||||
override fun createPointer(): KtSymbolPointer<KtPackageSymbol> = withValidityAssertion {
|
||||
symbolPointer { session ->
|
||||
check(session is KtFirAnalysisSession)
|
||||
session.firSymbolBuilder.createPackageSymbolIfOneExists(fqName)
|
||||
}
|
||||
}
|
||||
override fun createPointer(): KtSymbolPointer<KtPackageSymbol> = KtFirPackageSymbolPointer(fqName)
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
|
||||
+5
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.analysis.api.fir.KtFirAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.fir.symbols.KtFirKotlinPropertySymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtBackingFieldSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtKotlinPropertySymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
||||
|
||||
internal class KtFirBackingFieldSymbolPointer(
|
||||
@@ -25,4 +26,8 @@ internal class KtFirBackingFieldSymbolPointer(
|
||||
check(propertySymbol is KtFirKotlinPropertySymbol)
|
||||
return analysisSession.firSymbolBuilder.variableLikeBuilder.buildBackingFieldSymbolByProperty(propertySymbol.firSymbol)
|
||||
}
|
||||
|
||||
override fun pointsToTheSameSymbolAs(other: KtSymbolPointer<KtSymbol>): Boolean = this === other ||
|
||||
other is KtFirBackingFieldSymbolPointer &&
|
||||
other.propertySymbolPointer.pointsToTheSameSymbolAs(propertySymbolPointer)
|
||||
}
|
||||
|
||||
+6
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.analysis.api.fir.symbols.pointers
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.fir.KtFirAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtClassLikeSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import kotlin.reflect.KClass
|
||||
@@ -25,4 +26,9 @@ internal class KtFirClassLikeSymbolPointer<T : KtClassLikeSymbol>(
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return classLikeSymbol as T
|
||||
}
|
||||
|
||||
override fun pointsToTheSameSymbolAs(other: KtSymbolPointer<KtSymbol>): Boolean = other === this ||
|
||||
other is KtFirClassLikeSymbolPointer &&
|
||||
other.classId == classId &&
|
||||
other.expectedClass == expectedClass
|
||||
}
|
||||
|
||||
+7
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.analysis.api.fir.symbols.pointers
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.fir.KtFirAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtConstructorSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtSymbolWithMembers
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
@@ -29,4 +30,10 @@ internal class KtFirConstructorSymbolPointer(
|
||||
if (firConstructor.isPrimary != isPrimary) return null
|
||||
return firSymbolBuilder.functionLikeBuilder.buildConstructorSymbol(firConstructor.symbol)
|
||||
}
|
||||
|
||||
override fun pointsToTheSameSymbolAs(other: KtSymbolPointer<KtSymbol>): Boolean = other === this ||
|
||||
other is KtFirConstructorSymbolPointer &&
|
||||
other.signature == signature &&
|
||||
other.isPrimary == isPrimary &&
|
||||
hasTheSameOwner(other)
|
||||
}
|
||||
|
||||
+5
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.analysis.api.fir.KtFirAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.fir.utils.firSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtAnonymousObjectSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtEnumEntrySymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnonymousObjectExpression
|
||||
|
||||
@@ -26,4 +27,8 @@ internal class KtFirEnumEntryInitializerSymbolPointer(
|
||||
val initializer = owner?.firSymbol?.fir?.initializer as? FirAnonymousObjectExpression ?: return null
|
||||
return analysisSession.firSymbolBuilder.classifierBuilder.buildAnonymousObjectSymbol(initializer.anonymousObject.symbol)
|
||||
}
|
||||
|
||||
override fun pointsToTheSameSymbolAs(other: KtSymbolPointer<KtSymbol>): Boolean = this === other ||
|
||||
other is KtFirEnumEntryInitializerSymbolPointer &&
|
||||
other.ownerPointer.pointsToTheSameSymbolAs(ownerPointer)
|
||||
}
|
||||
|
||||
+7
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.analysis.api.fir.KtFirAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.fir.utils.firSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtClassOrObjectSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtEnumEntrySymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.fir.declarations.FirEnumEntry
|
||||
@@ -37,5 +38,9 @@ internal class KtFirEnumEntrySymbolPointer(
|
||||
declarations.firstOrNull { member ->
|
||||
member is FirEnumEntry && member.name == name
|
||||
} as FirEnumEntry?
|
||||
}
|
||||
|
||||
override fun pointsToTheSameSymbolAs(other: KtSymbolPointer<KtSymbol>): Boolean = other === this ||
|
||||
other is KtFirEnumEntrySymbolPointer &&
|
||||
other.name == name &&
|
||||
other.ownerPointer.pointsToTheSameSymbolAs(ownerPointer)
|
||||
}
|
||||
|
||||
+6
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.analysis.api.fir.symbols.pointers
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.fir.KtFirAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtJavaFieldSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtSymbolWithMembers
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
@@ -27,4 +28,9 @@ internal class KtFirJavaFieldSymbolPointer(
|
||||
val javaField = candidates.getProperties(fieldName).mapNotNull { it.fir as? FirJavaField }.singleOrNull() ?: return null
|
||||
return firSymbolBuilder.variableLikeBuilder.buildFieldSymbol(javaField.symbol)
|
||||
}
|
||||
|
||||
override fun pointsToTheSameSymbolAs(other: KtSymbolPointer<KtSymbol>): Boolean = this === other ||
|
||||
other is KtFirJavaFieldSymbolPointer &&
|
||||
other.fieldName == fieldName &&
|
||||
hasTheSameOwner(other)
|
||||
}
|
||||
|
||||
+7
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.analysis.api.fir.symbols.pointers
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.fir.KtFirAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSyntheticJavaPropertySymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtSymbolWithMembers
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
||||
@@ -49,4 +50,10 @@ internal class KtFirJavaSyntheticPropertySymbolPointer(
|
||||
baseScope
|
||||
}
|
||||
}
|
||||
|
||||
override fun pointsToTheSameSymbolAs(other: KtSymbolPointer<KtSymbol>): Boolean = this === other ||
|
||||
other is KtFirJavaSyntheticPropertySymbolPointer &&
|
||||
other.propertyName == propertyName &&
|
||||
other.isSynthetic == isSynthetic &&
|
||||
hasTheSameOwner(other)
|
||||
}
|
||||
|
||||
+7
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.analysis.api.fir.symbols.pointers
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.fir.KtFirAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtFunctionSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtSymbolWithMembers
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
@@ -29,4 +30,10 @@ internal class KtFirMemberFunctionSymbolPointer(
|
||||
} ?: return null
|
||||
return firSymbolBuilder.functionLikeBuilder.buildFunctionSymbol(firFunction.symbol)
|
||||
}
|
||||
|
||||
override fun pointsToTheSameSymbolAs(other: KtSymbolPointer<KtSymbol>): Boolean = this === other ||
|
||||
other is KtFirMemberFunctionSymbolPointer &&
|
||||
other.name == name &&
|
||||
other.signature == signature &&
|
||||
hasTheSameOwner(other)
|
||||
}
|
||||
|
||||
+7
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.analysis.api.fir.symbols.pointers
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.fir.KtFirAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtKotlinPropertySymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtSymbolWithMembers
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
@@ -30,4 +31,10 @@ internal class KtFirMemberPropertySymbolPointer(
|
||||
|
||||
return firSymbolBuilder.variableLikeBuilder.buildVariableSymbol(firProperty.symbol) as? KtKotlinPropertySymbol
|
||||
}
|
||||
|
||||
override fun pointsToTheSameSymbolAs(other: KtSymbolPointer<KtSymbol>): Boolean = this === other ||
|
||||
other is KtFirMemberPropertySymbolPointer &&
|
||||
other.name == name &&
|
||||
other.signature == signature &&
|
||||
hasTheSameOwner(other)
|
||||
}
|
||||
|
||||
+4
@@ -51,6 +51,10 @@ internal abstract class KtFirMemberSymbolPointer<S : KtSymbol>(
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
abstract override fun pointsToTheSameSymbolAs(other: KtSymbolPointer<KtSymbol>): Boolean
|
||||
protected fun hasTheSameOwner(other: KtFirMemberSymbolPointer<*>): Boolean =
|
||||
other.isStatic == isStatic && other.ownerPointer.pointsToTheSameSymbolAs(ownerPointer)
|
||||
}
|
||||
|
||||
context(KtAnalysisSession)
|
||||
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.analysis.api.fir.symbols.pointers
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.fir.KtFirAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtPackageSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
|
||||
class KtFirPackageSymbolPointer(private val fqName: FqName) : KtSymbolPointer<KtPackageSymbol>() {
|
||||
@Deprecated("Consider using org.jetbrains.kotlin.analysis.api.KtAnalysisSession.restoreSymbol")
|
||||
override fun restoreSymbol(analysisSession: KtAnalysisSession): KtPackageSymbol? {
|
||||
check(analysisSession is KtFirAnalysisSession)
|
||||
return analysisSession.firSymbolBuilder.createPackageSymbolIfOneExists(fqName)
|
||||
}
|
||||
|
||||
override fun pointsToTheSameSymbolAs(other: KtSymbolPointer<KtSymbol>): Boolean = this === other ||
|
||||
other is KtFirPackageSymbolPointer &&
|
||||
other.fqName == fqName
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.analysis.api.fir.symbols.pointers
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtKotlinPropertySymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtValueParameterSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtVariableLikeSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtPsiBasedSymbolPointer
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
||||
|
||||
class KtFirPsiBasedPropertySymbolPointer(
|
||||
private val variableSymbolPointer: KtPsiBasedSymbolPointer<KtVariableLikeSymbol>,
|
||||
) : KtSymbolPointer<KtKotlinPropertySymbol>() {
|
||||
@Deprecated("Consider using org.jetbrains.kotlin.analysis.api.KtAnalysisSession.restoreSymbol")
|
||||
override fun restoreSymbol(analysisSession: KtAnalysisSession): KtKotlinPropertySymbol? =
|
||||
when (val variable = with(analysisSession) { variableSymbolPointer.restoreSymbol() }) {
|
||||
is KtKotlinPropertySymbol -> variable
|
||||
is KtValueParameterSymbol -> variable.generatedPrimaryConstructorProperty
|
||||
else -> null
|
||||
}
|
||||
|
||||
override fun pointsToTheSameSymbolAs(other: KtSymbolPointer<KtSymbol>): Boolean = this === other ||
|
||||
other is KtFirPsiBasedPropertySymbolPointer &&
|
||||
other.variableSymbolPointer.pointsToTheSameSymbolAs(variableSymbolPointer)
|
||||
}
|
||||
+5
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.analysis.api.fir.KtFirAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.fir.utils.firSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtCallableSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtReceiverParameterSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
||||
|
||||
internal class KtFirReceiverParameterSymbolPointer(
|
||||
@@ -24,4 +25,8 @@ internal class KtFirReceiverParameterSymbolPointer(
|
||||
|
||||
return analysisSession.firSymbolBuilder.callableBuilder.buildExtensionReceiverSymbol(callableSymbol.firSymbol)
|
||||
}
|
||||
|
||||
override fun pointsToTheSameSymbolAs(other: KtSymbolPointer<KtSymbol>): Boolean = this === other ||
|
||||
other is KtFirReceiverParameterSymbolPointer &&
|
||||
other.ownerPointer.pointsToTheSameSymbolAs(ownerPointer)
|
||||
}
|
||||
|
||||
+6
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.analysis.api.fir.symbols.pointers
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.fir.KtFirAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSamConstructorSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
||||
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
@@ -24,4 +25,8 @@ internal class KtFirSamConstructorSymbolPointer(
|
||||
return classSymbol.getSamConstructor()
|
||||
}
|
||||
}
|
||||
|
||||
override fun pointsToTheSameSymbolAs(other: KtSymbolPointer<KtSymbol>): Boolean = this === other ||
|
||||
other is KtFirSamConstructorSymbolPointer &&
|
||||
other.ownerClassId == ownerClassId
|
||||
}
|
||||
|
||||
+5
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.analysis.api.fir.symbols.pointers
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.fir.KtFirAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtCallableSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
|
||||
@@ -30,6 +31,9 @@ internal abstract class KtTopLevelCallableSymbolPointer<S : KtCallableSymbol>(
|
||||
candidates: Collection<FirCallableSymbol<*>>,
|
||||
firSession: FirSession
|
||||
): S?
|
||||
|
||||
abstract override fun pointsToTheSameSymbolAs(other: KtSymbolPointer<KtSymbol>): Boolean
|
||||
protected fun hasTheSameOwner(other: KtTopLevelCallableSymbolPointer<*>): Boolean = other.callableId == callableId
|
||||
}
|
||||
|
||||
private fun KtFirAnalysisSession.getCallableSymbols(callableId: CallableId) =
|
||||
|
||||
+8
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@@ -7,6 +7,8 @@ package org.jetbrains.kotlin.analysis.api.fir.symbols.pointers
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.fir.KtFirAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtFunctionSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
|
||||
@@ -23,4 +25,9 @@ internal class KtFirTopLevelFunctionSymbolPointer(
|
||||
val firFunction = candidates.findDeclarationWithSignatureBySymbols<FirSimpleFunction>(signature) ?: return null
|
||||
return firSymbolBuilder.functionLikeBuilder.buildFunctionSymbol(firFunction.symbol)
|
||||
}
|
||||
|
||||
override fun pointsToTheSameSymbolAs(other: KtSymbolPointer<KtSymbol>): Boolean = this === other ||
|
||||
other is KtFirTopLevelFunctionSymbolPointer &&
|
||||
other.signature == signature &&
|
||||
hasTheSameOwner(other)
|
||||
}
|
||||
|
||||
+7
@@ -7,6 +7,8 @@ package org.jetbrains.kotlin.analysis.api.fir.symbols.pointers
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.fir.KtFirAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtKotlinPropertySymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirProperty
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
|
||||
@@ -21,4 +23,9 @@ internal class KtFirTopLevelPropertySymbolPointer(callableId: CallableId, privat
|
||||
val firProperty = candidates.findDeclarationWithSignatureBySymbols<FirProperty>(signature) ?: return null
|
||||
return firSymbolBuilder.variableLikeBuilder.buildPropertySymbol(firProperty.symbol) as? KtKotlinPropertySymbol
|
||||
}
|
||||
|
||||
override fun pointsToTheSameSymbolAs(other: KtSymbolPointer<KtSymbol>): Boolean = this === other ||
|
||||
other is KtFirTopLevelPropertySymbolPointer &&
|
||||
other.signature == signature &&
|
||||
hasTheSameOwner(other)
|
||||
}
|
||||
|
||||
+7
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.analysis.api.fir.symbols.pointers
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.fir.KtFirAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.fir.utils.firSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtTypeParameterSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtSymbolWithTypeParameters
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
||||
@@ -29,4 +30,10 @@ internal class KtFirTypeParameterSymbolPointer(
|
||||
val firTypeParameterSymbol = ownerSymbol.firSymbol.typeParameterSymbols?.getOrNull(index)?.takeIf { it.name == name } ?: return null
|
||||
return analysisSession.firSymbolBuilder.classifierBuilder.buildTypeParameterSymbol(firTypeParameterSymbol)
|
||||
}
|
||||
|
||||
override fun pointsToTheSameSymbolAs(other: KtSymbolPointer<KtSymbol>): Boolean = this === other ||
|
||||
other is KtFirTypeParameterSymbolPointer &&
|
||||
other.index == index &&
|
||||
other.name == name &&
|
||||
other.ownerPointer.pointsToTheSameSymbolAs(ownerPointer)
|
||||
}
|
||||
|
||||
+6
@@ -29,4 +29,10 @@ internal class KtFirValueParameterSymbolPointer(
|
||||
val firValueParameterSymbol = function.valueParameters.getOrNull(index)?.symbol?.takeIf { it.name == name } ?: return null
|
||||
return analysisSession.firSymbolBuilder.variableLikeBuilder.buildValueParameterSymbol(firValueParameterSymbol)
|
||||
}
|
||||
|
||||
override fun pointsToTheSameSymbolAs(other: KtSymbolPointer<KtSymbol>): Boolean = this === other ||
|
||||
other is KtFirValueParameterSymbolPointer &&
|
||||
other.index == index &&
|
||||
other.name == name &&
|
||||
other.ownerPointer.pointsToTheSameSymbolAs(ownerPointer)
|
||||
}
|
||||
|
||||
+6
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.analysis.api.KtAnalysisApiInternals
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtPropertyAccessorSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtPropertySymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
||||
|
||||
@KtAnalysisApiInternals
|
||||
@@ -24,4 +25,9 @@ class KtPropertyAccessorSymbolPointer(
|
||||
|
||||
return if (isGetter) propertySymbol.getter else propertySymbol.setter
|
||||
}
|
||||
|
||||
override fun pointsToTheSameSymbolAs(other: KtSymbolPointer<KtSymbol>): Boolean = this === other ||
|
||||
other is KtPropertyAccessorSymbolPointer &&
|
||||
other.isGetter == isGetter &&
|
||||
other.propertySymbolPointer.pointsToTheSameSymbolAs(propertySymbolPointer)
|
||||
}
|
||||
|
||||
+4
@@ -22,4 +22,8 @@ class KtValueParameterFromDefaultSetterSymbolPointer(
|
||||
|
||||
return ownerSymbol?.setter?.parameter
|
||||
}
|
||||
|
||||
override fun pointsToTheSameSymbolAs(other: KtSymbolPointer<KtSymbol>): Boolean = this === other ||
|
||||
other is KtValueParameterFromDefaultSetterSymbolPointer &&
|
||||
other.ownerPointer.pointsToTheSameSymbolAs(ownerPointer)
|
||||
}
|
||||
|
||||
+76
-16
@@ -62,24 +62,27 @@ abstract class AbstractSymbolTest : AbstractAnalysisApiSingleFileTest() {
|
||||
|
||||
fun KtAnalysisSession.safePointer(ktSymbol: KtSymbol): PointerWrapper? {
|
||||
val regularPointer = ktSymbol.runCatching {
|
||||
KtPsiBasedSymbolPointer.withDisabledPsiBasedPointers(disable = false) { ktSymbol.createPointer() }
|
||||
createPointerForTest(disablePsiBasedSymbols = false)
|
||||
}.let {
|
||||
if (directiveToIgnoreSymbolRestore == null) it.getOrThrow() else it.getOrNull()
|
||||
} ?: return null
|
||||
|
||||
val nonPsiPointer = kotlin.runCatching {
|
||||
if (ktSymbol is KtFileSymbol) return@runCatching null
|
||||
|
||||
KtPsiBasedSymbolPointer.withDisabledPsiBasedPointers(disable = true) { ktSymbol.createPointer() }
|
||||
assertSymbolPointer(regularPointer, testServices)
|
||||
val nonPsiPointer = ktSymbol.runCatching {
|
||||
if (this is KtFileSymbol) return@runCatching null
|
||||
createPointerForTest(disablePsiBasedSymbols = true)
|
||||
}
|
||||
|
||||
return PointerWrapper(
|
||||
regularPointer = regularPointer,
|
||||
pointerWithoutPsiAnchor = if (directiveToIgnoreSymbolRestore == null && directiveToIgnoreNonPsiSymbolRestore == null)
|
||||
nonPsiPointer.getOrThrow()
|
||||
else
|
||||
nonPsiPointer.getOrNull(),
|
||||
)
|
||||
val pointerWithoutPsiAnchor = if (directiveToIgnoreSymbolRestore == null && directiveToIgnoreNonPsiSymbolRestore == null)
|
||||
nonPsiPointer.getOrThrow()
|
||||
else
|
||||
nonPsiPointer.getOrNull()
|
||||
|
||||
if (pointerWithoutPsiAnchor != null) {
|
||||
assertSymbolPointer(pointerWithoutPsiAnchor, testServices)
|
||||
}
|
||||
|
||||
return PointerWrapper(regularPointer = regularPointer, pointerWithoutPsiAnchor = pointerWithoutPsiAnchor)
|
||||
}
|
||||
|
||||
val pointersWithRendered = executeOnPooledThreadInReadAction {
|
||||
@@ -130,7 +133,7 @@ abstract class AbstractSymbolTest : AbstractAnalysisApiSingleFileTest() {
|
||||
|
||||
restoreSymbolsInOtherReadActionAndCompareResults(
|
||||
directiveToIgnore = directiveToIgnoreSymbolRestore,
|
||||
pointerAccessor = PointerWrapper::regularPointer,
|
||||
isRegularPointers = true,
|
||||
ktFile = ktFile,
|
||||
pointersWithRendered = pointersWithRendered.pointers,
|
||||
testServices = testServices,
|
||||
@@ -139,7 +142,7 @@ abstract class AbstractSymbolTest : AbstractAnalysisApiSingleFileTest() {
|
||||
if (directiveToIgnoreSymbolRestore == null) {
|
||||
restoreSymbolsInOtherReadActionAndCompareResults(
|
||||
directiveToIgnore = directiveToIgnoreNonPsiSymbolRestore,
|
||||
pointerAccessor = PointerWrapper::pointerWithoutPsiAnchor,
|
||||
isRegularPointers = false,
|
||||
ktFile = ktFile,
|
||||
pointersWithRendered = pointersWithRendered.pointers,
|
||||
testServices = testServices,
|
||||
@@ -147,6 +150,16 @@ abstract class AbstractSymbolTest : AbstractAnalysisApiSingleFileTest() {
|
||||
}
|
||||
}
|
||||
|
||||
context(KtAnalysisSession)
|
||||
private fun KtSymbol.createPointerForTest(disablePsiBasedSymbols: Boolean): KtSymbolPointer<*> =
|
||||
KtPsiBasedSymbolPointer.withDisabledPsiBasedPointers(disable = disablePsiBasedSymbols) { createPointer() }
|
||||
|
||||
private fun assertSymbolPointer(pointer: KtSymbolPointer<*>, testServices: TestServices) {
|
||||
testServices.assertions.assertTrue(value = pointer.pointsToTheSameSymbolAs(pointer)) {
|
||||
"The symbol is not equal to itself: ${pointer::class}"
|
||||
}
|
||||
}
|
||||
|
||||
private fun RegisteredDirectives.doNotCheckSymbolRestoreDirective(): Directive? = findSpecificDirective(
|
||||
commonDirective = DO_NOT_CHECK_SYMBOL_RESTORE,
|
||||
k1Directive = DO_NOT_CHECK_SYMBOL_RESTORE_K1,
|
||||
@@ -187,17 +200,25 @@ abstract class AbstractSymbolTest : AbstractAnalysisApiSingleFileTest() {
|
||||
|
||||
private fun restoreSymbolsInOtherReadActionAndCompareResults(
|
||||
directiveToIgnore: Directive?,
|
||||
pointerAccessor: (PointerWrapper) -> KtSymbolPointer<KtSymbol>?,
|
||||
isRegularPointers: Boolean,
|
||||
ktFile: KtFile,
|
||||
pointersWithRendered: List<PointerWithRenderedSymbol>,
|
||||
testServices: TestServices,
|
||||
) {
|
||||
var failed = false
|
||||
val restoredPointers = mutableListOf<KtSymbolPointer<*>>()
|
||||
try {
|
||||
val restored = analyseForTest(ktFile) {
|
||||
pointersWithRendered.mapNotNull { (pointerWrapper, expectedRender, shouldBeRendered) ->
|
||||
val pointer = pointerWrapper?.let(pointerAccessor) ?: error("Symbol pointer for $expectedRender was not created")
|
||||
val pointer = if (isRegularPointers) {
|
||||
pointerWrapper?.regularPointer
|
||||
} else {
|
||||
pointerWrapper?.pointerWithoutPsiAnchor
|
||||
} ?: error("Symbol pointer for $expectedRender was not created")
|
||||
|
||||
val restored = pointer.restoreSymbol() ?: error("Symbol $expectedRender was not restored")
|
||||
restoredPointers += pointer
|
||||
|
||||
val actualRender = renderSymbolForComparison(restored)
|
||||
if (shouldBeRendered) {
|
||||
actualRender
|
||||
@@ -215,6 +236,10 @@ abstract class AbstractSymbolTest : AbstractAnalysisApiSingleFileTest() {
|
||||
failed = true
|
||||
}
|
||||
|
||||
if (!failed) {
|
||||
compareRestoredSymbols(restoredPointers, testServices, ktFile, isRegularPointers)
|
||||
}
|
||||
|
||||
if (failed || directiveToIgnore == null) return
|
||||
|
||||
testServices.assertions.assertEqualsToTestDataFileSibling(
|
||||
@@ -225,6 +250,41 @@ abstract class AbstractSymbolTest : AbstractAnalysisApiSingleFileTest() {
|
||||
fail("Redundant // ${directiveToIgnore.name} directive")
|
||||
}
|
||||
|
||||
private fun compareRestoredSymbols(
|
||||
restoredPointers: List<KtSymbolPointer<*>>,
|
||||
testServices: TestServices,
|
||||
ktFile: KtFile,
|
||||
isRegularPointers: Boolean,
|
||||
) {
|
||||
if (restoredPointers.isEmpty()) return
|
||||
|
||||
analyseForTest(ktFile) {
|
||||
val symbolsToPointersMap = restoredPointers.groupByTo(mutableMapOf()) {
|
||||
it.restoreSymbol() ?: error("Unexpectedly non-restored symbol pointer: ${it::class}")
|
||||
}
|
||||
|
||||
val pointersToCheck = symbolsToPointersMap.map { (key, value) ->
|
||||
value += if (isRegularPointers) {
|
||||
key.createPointerForTest(disablePsiBasedSymbols = false)
|
||||
} else {
|
||||
key.createPointerForTest(disablePsiBasedSymbols = true)
|
||||
}
|
||||
|
||||
value
|
||||
}
|
||||
|
||||
for (pointers in pointersToCheck) {
|
||||
for (firstPointer in pointers) {
|
||||
for (secondPointer in pointers) {
|
||||
testServices.assertions.assertTrue(firstPointer.pointsToTheSameSymbolAs(secondPointer)) {
|
||||
"${firstPointer::class} is not the same as ${secondPointer::class}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected open fun KtAnalysisSession.renderSymbolForComparison(symbol: KtSymbol): String {
|
||||
return with(DebugSymbolRenderer(renderExtra = true)) { render(symbol) }
|
||||
}
|
||||
|
||||
+5
@@ -37,6 +37,11 @@ public class KtPsiBasedSymbolPointer<S : KtSymbol> private constructor(
|
||||
return symbol as S
|
||||
}
|
||||
|
||||
override fun pointsToTheSameSymbolAs(other: KtSymbolPointer<KtSymbol>): Boolean = this === other ||
|
||||
other is KtPsiBasedSymbolPointer &&
|
||||
other.expectedClass == expectedClass &&
|
||||
other.psiPointer == psiPointer
|
||||
|
||||
public constructor(psi: KtElement, expectedClass: KClass<S>) : this(psi.createSmartPointer(), expectedClass)
|
||||
|
||||
public companion object {
|
||||
|
||||
+6
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@@ -31,6 +31,11 @@ public abstract class KtSymbolPointer<out S : KtSymbol> {
|
||||
*/
|
||||
@Deprecated("Consider using org.jetbrains.kotlin.analysis.api.KtAnalysisSession.restoreSymbol")
|
||||
public abstract fun restoreSymbol(analysisSession: KtAnalysisSession): S?
|
||||
|
||||
/**
|
||||
* @return **true** if [other] pointer should be restored to the same symbol
|
||||
*/
|
||||
public open fun pointsToTheSameSymbolAs(other: KtSymbolPointer<KtSymbol>): Boolean = this === other
|
||||
}
|
||||
|
||||
public inline fun <S : KtSymbol> symbolPointer(crossinline getSymbol: (KtAnalysisSession) -> S?): KtSymbolPointer<S> =
|
||||
|
||||
Reference in New Issue
Block a user