[AA] introduce api to create symbol pointer from psi

^KT-54051
This commit is contained in:
Dmitrii Gridin
2022-11-10 14:25:53 +01:00
committed by Space Team
parent c6987744be
commit db23cbe29e
2 changed files with 40 additions and 8 deletions
@@ -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.
*/
@@ -26,7 +26,6 @@ import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl
import org.jetbrains.kotlin.descriptors.impl.SyntheticFieldDescriptor
import org.jetbrains.kotlin.load.kotlin.toSourceElement
import org.jetbrains.kotlin.psi.KtPropertyAccessor
import org.jetbrains.kotlin.psi.psiUtil.createSmartPointer
import org.jetbrains.kotlin.resolve.source.getPsi
internal class KtFe10DescSyntheticFieldSymbol(
@@ -8,12 +8,8 @@ package org.jetbrains.kotlin.analysis.api.symbols.pointers
import com.intellij.psi.SmartPsiElementPointer
import org.jetbrains.annotations.TestOnly
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbolOrigin
import org.jetbrains.kotlin.psi.KtDeclaration
import org.jetbrains.kotlin.psi.KtElement
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.psi.KtObjectLiteralExpression
import org.jetbrains.kotlin.analysis.api.symbols.*
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.createSmartPointer
import kotlin.reflect.KClass
@@ -97,3 +93,40 @@ public class KtPsiBasedSymbolPointer<S : KtSymbol> private constructor(
private var disablePsiPointer: Boolean = false
}
}
public fun KtElement.symbolPointer(): KtSymbolPointer<KtSymbol> = KtPsiBasedSymbolPointer(this, KtSymbol::class)
public inline fun <reified S : KtSymbol> KtElement.symbolPointerOfType(): KtSymbolPointer<S> = KtPsiBasedSymbolPointer(this, S::class)
public fun KtFile.symbolPointer(): KtSymbolPointer<KtFileSymbol> = KtPsiBasedSymbolPointer(this, KtFileSymbol::class)
public fun KtParameter.symbolPointer(): KtSymbolPointer<KtVariableLikeSymbol> = KtPsiBasedSymbolPointer(this, KtVariableLikeSymbol::class)
public fun KtTypeAlias.symbolPointer(): KtSymbolPointer<KtTypeAliasSymbol> = KtPsiBasedSymbolPointer(this, KtTypeAliasSymbol::class)
public fun KtEnumEntry.symbolPointer(): KtSymbolPointer<KtEnumEntrySymbol> = KtPsiBasedSymbolPointer(this, KtEnumEntrySymbol::class)
public fun KtProperty.symbolPointer(): KtSymbolPointer<KtVariableSymbol> = KtPsiBasedSymbolPointer(this, KtVariableSymbol::class)
public fun KtNamedFunction.symbolPointer(): KtSymbolPointer<KtFunctionLikeSymbol> {
return KtPsiBasedSymbolPointer(this, KtFunctionLikeSymbol::class)
}
public fun KtConstructor<*>.symbolPointer(): KtSymbolPointer<KtConstructorSymbol> {
return KtPsiBasedSymbolPointer(this, KtConstructorSymbol::class)
}
public fun KtTypeParameter.symbolPointer(): KtSymbolPointer<KtTypeParameterSymbol> {
return KtPsiBasedSymbolPointer(this, KtTypeParameterSymbol::class)
}
public fun KtFunctionLiteral.symbolPointer(): KtSymbolPointer<KtAnonymousFunctionSymbol> {
return KtPsiBasedSymbolPointer(this, KtAnonymousFunctionSymbol::class)
}
public fun KtObjectLiteralExpression.symbolPointer(): KtSymbolPointer<KtAnonymousObjectSymbol> {
return KtPsiBasedSymbolPointer(this, KtAnonymousObjectSymbol::class)
}
public fun KtClassOrObject.symbolPointer(): KtSymbolPointer<KtClassOrObjectSymbol> {
return KtPsiBasedSymbolPointer(this, KtClassOrObjectSymbol::class)
}
public fun KtPropertyAccessor.symbolPointer(): KtSymbolPointer<KtPropertyAccessorSymbol> {
return KtPsiBasedSymbolPointer(this, KtPropertyAccessorSymbol::class)
}