[SLC] drop KtAnalysisSession from SymbolLightMethod
^KT-54051
This commit is contained in:
committed by
Space Team
parent
7297c0b941
commit
08ca1e81a3
+1
-1
@@ -114,7 +114,7 @@ internal fun KtAnnotatedSymbol.computeAnnotations(
|
||||
|
||||
val result = mutableListOf<PsiAnnotation>()
|
||||
|
||||
if (parent is SymbolLightMethod) {
|
||||
if (parent is SymbolLightMethod<*>) {
|
||||
if (parent.isDelegated || parent.isOverride()) {
|
||||
result.add(SymbolLightSimpleAnnotation(java.lang.Override::class.java.name, parent))
|
||||
}
|
||||
|
||||
+1
@@ -84,6 +84,7 @@ internal fun SymbolLightClassForClassOrObject.createConstructors(
|
||||
|
||||
for (constructor in constructors) {
|
||||
if (constructor.isHiddenOrSynthetic()) continue
|
||||
|
||||
result.add(
|
||||
SymbolLightConstructor(
|
||||
constructorSymbol = constructor,
|
||||
|
||||
+1
-19
@@ -7,13 +7,11 @@ package org.jetbrains.kotlin.light.classes.symbol.methods
|
||||
|
||||
import com.intellij.psi.*
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.isValid
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtConstructorSymbol
|
||||
import org.jetbrains.kotlin.asJava.builder.LightMemberOrigin
|
||||
import org.jetbrains.kotlin.asJava.classes.lazyPub
|
||||
import org.jetbrains.kotlin.light.classes.symbol.NullabilityType
|
||||
import org.jetbrains.kotlin.light.classes.symbol.annotations.computeAnnotations
|
||||
import org.jetbrains.kotlin.light.classes.symbol.annotations.hasDeprecatedAnnotation
|
||||
import org.jetbrains.kotlin.light.classes.symbol.classes.SymbolLightClassBase
|
||||
import org.jetbrains.kotlin.light.classes.symbol.classes.SymbolLightClassForEnumEntry
|
||||
import org.jetbrains.kotlin.light.classes.symbol.modifierLists.SymbolLightMemberModifierList
|
||||
@@ -27,7 +25,7 @@ internal class SymbolLightConstructor(
|
||||
containingClass: SymbolLightClassBase,
|
||||
methodIndex: Int,
|
||||
argumentsSkipMask: BitSet? = null,
|
||||
) : SymbolLightMethod(
|
||||
) : SymbolLightMethod<KtConstructorSymbol>(
|
||||
functionSymbol = constructorSymbol,
|
||||
lightMemberOrigin = lightMemberOrigin,
|
||||
containingClass = containingClass,
|
||||
@@ -53,12 +51,6 @@ internal class SymbolLightConstructor(
|
||||
)
|
||||
}
|
||||
|
||||
private val _isDeprecated: Boolean by lazyPub {
|
||||
constructorSymbol.hasDeprecatedAnnotation()
|
||||
}
|
||||
|
||||
override fun isDeprecated(): Boolean = _isDeprecated
|
||||
|
||||
private val _modifiers: Set<String> by lazyPub {
|
||||
// FIR treats an enum entry as an anonymous object w/ its own ctor (not default one).
|
||||
// On the other hand, FE 1.0 doesn't add anything; then ULC adds default ctor w/ package local visibility.
|
||||
@@ -77,14 +69,4 @@ internal class SymbolLightConstructor(
|
||||
override fun getModifierList(): PsiModifierList = _modifierList
|
||||
|
||||
override fun getReturnType(): PsiType? = null
|
||||
|
||||
override fun equals(other: Any?): Boolean =
|
||||
this === other ||
|
||||
(other is SymbolLightConstructor &&
|
||||
kotlinOrigin == other.kotlinOrigin &&
|
||||
constructorSymbol == other.constructorSymbol)
|
||||
|
||||
override fun hashCode(): Int = kotlinOrigin.hashCode()
|
||||
|
||||
override fun isValid(): Boolean = super.isValid() && constructorSymbol.isValid()
|
||||
}
|
||||
|
||||
+82
-27
@@ -8,71 +8,126 @@ package org.jetbrains.kotlin.light.classes.symbol.methods
|
||||
import com.intellij.psi.PsiIdentifier
|
||||
import com.intellij.psi.PsiParameterList
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.isValid
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtFunctionLikeSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtFunctionSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.psiSafe
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.sourcePsiSafe
|
||||
import org.jetbrains.kotlin.asJava.builder.LightMemberOrigin
|
||||
import org.jetbrains.kotlin.asJava.classes.lazyPub
|
||||
import org.jetbrains.kotlin.light.classes.symbol.SymbolLightIdentifier
|
||||
import org.jetbrains.kotlin.asJava.elements.KtLightIdentifier
|
||||
import org.jetbrains.kotlin.light.classes.symbol.annotations.hasDeprecatedAnnotation
|
||||
import org.jetbrains.kotlin.light.classes.symbol.classes.SymbolLightClassBase
|
||||
import org.jetbrains.kotlin.light.classes.symbol.classes.analyzeForLightClasses
|
||||
import org.jetbrains.kotlin.light.classes.symbol.parameters.SymbolLightParameter
|
||||
import org.jetbrains.kotlin.light.classes.symbol.parameters.SymbolLightParameterList
|
||||
import org.jetbrains.kotlin.light.classes.symbol.parameters.SymbolLightSuspendContinuationParameter
|
||||
import org.jetbrains.kotlin.light.classes.symbol.restoreSymbolOrThrowIfDisposed
|
||||
import org.jetbrains.kotlin.psi.KtCallableDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import java.util.*
|
||||
|
||||
context(KtAnalysisSession)
|
||||
internal abstract class SymbolLightMethod(
|
||||
private val functionSymbol: KtFunctionLikeSymbol,
|
||||
internal abstract class SymbolLightMethod<FType : KtFunctionLikeSymbol>(
|
||||
functionSymbol: FType,
|
||||
lightMemberOrigin: LightMemberOrigin?,
|
||||
containingClass: SymbolLightClassBase,
|
||||
methodIndex: Int,
|
||||
argumentsSkipMask: BitSet? = null
|
||||
private val argumentsSkipMask: BitSet? = null,
|
||||
) : SymbolLightMethodBase(
|
||||
lightMemberOrigin,
|
||||
containingClass,
|
||||
methodIndex,
|
||||
) {
|
||||
private var _isVarArgs: Boolean = functionSymbol.valueParameters.any { it.isVararg }
|
||||
protected val functionDeclaration: KtCallableDeclaration? = functionSymbol.sourcePsiSafe()
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
protected val functionSymbolPointer: KtSymbolPointer<FType> = functionSymbol.createPointer() as KtSymbolPointer<FType>
|
||||
|
||||
protected fun <T> withFunctionSymbol(action: KtAnalysisSession.(FType) -> T): T = analyzeForLightClasses(ktModule) {
|
||||
action(functionSymbolPointer.restoreSymbolOrThrowIfDisposed())
|
||||
}
|
||||
|
||||
private val _isVarArgs: Boolean by lazy {
|
||||
functionDeclaration?.valueParameters?.any { it.isVarArg } ?: withFunctionSymbol { functionSymbol ->
|
||||
functionSymbol.valueParameters.any { it.isVararg }
|
||||
}
|
||||
}
|
||||
|
||||
override fun isVarArgs(): Boolean = _isVarArgs
|
||||
|
||||
private val _parametersList by lazyPub {
|
||||
SymbolLightParameterList(this, functionSymbol) { builder ->
|
||||
functionSymbol.valueParameters.mapIndexed { index, parameter ->
|
||||
val needToSkip = argumentsSkipMask?.get(index) == true
|
||||
if (!needToSkip) {
|
||||
withFunctionSymbol { functionSymbol ->
|
||||
SymbolLightParameterList(this@SymbolLightMethod, functionSymbol) { builder ->
|
||||
functionSymbol.valueParameters.mapIndexed { index, parameter ->
|
||||
val needToSkip = argumentsSkipMask?.get(index) == true
|
||||
if (!needToSkip) {
|
||||
builder.addParameter(
|
||||
SymbolLightParameter(
|
||||
parameterSymbol = parameter,
|
||||
containingMethod = this@SymbolLightMethod
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if ((functionSymbol as? KtFunctionSymbol)?.isSuspend == true) {
|
||||
builder.addParameter(
|
||||
SymbolLightParameter(
|
||||
parameterSymbol = parameter,
|
||||
containingMethod = this@SymbolLightMethod
|
||||
SymbolLightSuspendContinuationParameter(
|
||||
functionSymbol = functionSymbol,
|
||||
containingMethod = this@SymbolLightMethod,
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
if ((functionSymbol as? KtFunctionSymbol)?.isSuspend == true) {
|
||||
builder.addParameter(
|
||||
SymbolLightSuspendContinuationParameter(
|
||||
functionSymbol = functionSymbol,
|
||||
containingMethod = this@SymbolLightMethod
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val _identifier: PsiIdentifier by lazyPub {
|
||||
SymbolLightIdentifier(this, functionSymbol)
|
||||
private val _identifier: PsiIdentifier by lazy {
|
||||
KtLightIdentifier(this@SymbolLightMethod, functionDeclaration)
|
||||
}
|
||||
|
||||
private val _isDeprecated: Boolean by lazyPub {
|
||||
withFunctionSymbol { functionSymbol ->
|
||||
functionSymbol.hasDeprecatedAnnotation()
|
||||
}
|
||||
}
|
||||
|
||||
override fun isDeprecated(): Boolean = _isDeprecated
|
||||
|
||||
override fun getNameIdentifier(): PsiIdentifier = _identifier
|
||||
|
||||
override fun getParameterList(): PsiParameterList = _parametersList
|
||||
|
||||
override val kotlinOrigin: KtDeclaration? =
|
||||
lightMemberOrigin?.originalElement ?: functionSymbol.psi as? KtDeclaration
|
||||
functionDeclaration ?: lightMemberOrigin?.originalElement ?: functionSymbol.psiSafe<KtDeclaration>()
|
||||
|
||||
override fun isValid(): Boolean = super.isValid() && functionSymbol.isValid()
|
||||
override fun isValid(): Boolean = super.isValid() && functionDeclaration?.isValid ?: analyzeForLightClasses(ktModule) {
|
||||
functionSymbolPointer.restoreSymbol() != null
|
||||
}
|
||||
|
||||
override fun isOverride(): Boolean = functionSymbol.getDirectlyOverriddenSymbols().isNotEmpty()
|
||||
override fun isOverride(): Boolean = withFunctionSymbol { it.getDirectlyOverriddenSymbols().isNotEmpty() }
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (other !is SymbolLightMethod<*>) return false
|
||||
|
||||
if (functionDeclaration != null) {
|
||||
return functionDeclaration == other.functionDeclaration && fieldsEquals(other)
|
||||
}
|
||||
|
||||
return other.functionDeclaration == null &&
|
||||
fieldsEquals(other) &&
|
||||
containingClass == other.containingClass &&
|
||||
analyzeForLightClasses(ktModule) {
|
||||
functionSymbolPointer.restoreSymbol() == other.functionSymbolPointer.restoreSymbol()
|
||||
}
|
||||
}
|
||||
|
||||
private fun fieldsEquals(other: SymbolLightMethod<*>): Boolean {
|
||||
return methodIndex == other.methodIndex &&
|
||||
ktModule == other.ktModule &&
|
||||
argumentsSkipMask == other.argumentsSkipMask
|
||||
}
|
||||
|
||||
override fun hashCode(): Int = kotlinOrigin.hashCode()
|
||||
}
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ import org.jetbrains.kotlin.utils.addToStdlib.ifTrue
|
||||
internal abstract class SymbolLightMethodBase(
|
||||
lightMemberOrigin: LightMemberOrigin?,
|
||||
containingClass: SymbolLightClassBase,
|
||||
private val methodIndex: Int,
|
||||
protected val methodIndex: Int,
|
||||
) : SymbolLightMemberBase<PsiMethod>(lightMemberOrigin, containingClass), KtLightMethod {
|
||||
override fun getBody(): PsiCodeBlock? = null
|
||||
|
||||
|
||||
+1
-15
@@ -7,7 +7,6 @@ package org.jetbrains.kotlin.light.classes.symbol.methods
|
||||
|
||||
import com.intellij.psi.*
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.isValid
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtFunctionSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtTypeMappingMode
|
||||
import org.jetbrains.kotlin.asJava.builder.LightMemberOrigin
|
||||
@@ -32,7 +31,7 @@ internal class SymbolLightSimpleMethod(
|
||||
private val isTopLevel: Boolean,
|
||||
argumentsSkipMask: BitSet? = null,
|
||||
private val suppressStatic: Boolean = false
|
||||
) : SymbolLightMethod(
|
||||
) : SymbolLightMethod<KtFunctionSymbol>(
|
||||
functionSymbol = functionSymbol,
|
||||
lightMemberOrigin = lightMemberOrigin,
|
||||
containingClass = containingClass,
|
||||
@@ -123,12 +122,6 @@ internal class SymbolLightSimpleMethod(
|
||||
return modifiers
|
||||
}
|
||||
|
||||
private val _isDeprecated: Boolean by lazyPub {
|
||||
functionSymbol.hasDeprecatedAnnotation()
|
||||
}
|
||||
|
||||
override fun isDeprecated(): Boolean = _isDeprecated
|
||||
|
||||
private val _modifierList: PsiModifierList by lazyPub {
|
||||
val modifiers = computeModifiers()
|
||||
val annotations = computeAnnotations(modifiers.contains(PsiModifier.PRIVATE))
|
||||
@@ -163,11 +156,4 @@ internal class SymbolLightSimpleMethod(
|
||||
}
|
||||
|
||||
override fun getReturnType(): PsiType = _returnedType
|
||||
|
||||
override fun equals(other: Any?): Boolean =
|
||||
this === other || (other is SymbolLightSimpleMethod && functionSymbol == other.functionSymbol)
|
||||
|
||||
override fun hashCode(): Int = functionSymbol.hashCode()
|
||||
|
||||
override fun isValid(): Boolean = super.isValid() && functionSymbol.isValid()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user