[SLC] migrate SymbolLightParameterForReceiver to KtReceiverParameterSymbol
^KT-54051
This commit is contained in:
committed by
Space Team
parent
e7b1206466
commit
37729c0353
+2
-3
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -14,7 +14,6 @@ import org.jetbrains.kotlin.analysis.api.descriptors.symbols.isEqualTo
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
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
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtType
|
||||
import org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor
|
||||
@@ -32,7 +31,7 @@ class KtFe10ReceiverParameterSymbol(
|
||||
override val owningCallableSymbol: KtCallableSymbol
|
||||
get() = withValidityAssertion { _descriptor.containingDeclaration.toKtSymbol(analysisContext) as KtCallableSymbol }
|
||||
|
||||
override fun createPointer(): KtSymbolPointer<KtSymbol> = withValidityAssertion {
|
||||
override fun createPointer(): KtSymbolPointer<KtReceiverParameterSymbol> = withValidityAssertion {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
|
||||
+2
@@ -38,4 +38,6 @@ public abstract class KtReceiverParameterSymbol : KtAnnotatedSymbol {
|
||||
* In terms of the example above -- this is link to the function foo.
|
||||
*/
|
||||
public abstract val owningCallableSymbol: KtCallableSymbol
|
||||
|
||||
abstract override fun createPointer(): KtSymbolPointer<KtReceiverParameterSymbol>
|
||||
}
|
||||
+21
-32
@@ -12,32 +12,27 @@ import com.intellij.psi.PsiType
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.annotations
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtCallableSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtReceiverParameterSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtNamedSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.receiverType
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtType
|
||||
import org.jetbrains.kotlin.asJava.classes.lazyPub
|
||||
import org.jetbrains.kotlin.codegen.AsmUtil
|
||||
import org.jetbrains.kotlin.light.classes.symbol.*
|
||||
import org.jetbrains.kotlin.light.classes.symbol.annotations.SymbolLightAnnotationForAnnotationCall
|
||||
import org.jetbrains.kotlin.light.classes.symbol.annotations.computeNullabilityAnnotation
|
||||
import org.jetbrains.kotlin.light.classes.symbol.classes.analyzeForLightClasses
|
||||
import org.jetbrains.kotlin.light.classes.symbol.compareSymbolPointers
|
||||
import org.jetbrains.kotlin.light.classes.symbol.methods.SymbolLightMethodBase
|
||||
import org.jetbrains.kotlin.light.classes.symbol.modifierLists.SymbolLightClassModifierList
|
||||
import org.jetbrains.kotlin.light.classes.symbol.nonExistentType
|
||||
import org.jetbrains.kotlin.light.classes.symbol.nullabilityType
|
||||
import org.jetbrains.kotlin.light.classes.symbol.restoreSymbolOrThrowIfDisposed
|
||||
import org.jetbrains.kotlin.psi.KtParameter
|
||||
|
||||
internal class SymbolLightParameterForReceiver private constructor(
|
||||
private val callableSymbolWithReceiverPointer: KtSymbolPointer<KtCallableSymbol>,
|
||||
private val receiverPointer: KtSymbolPointer<KtReceiverParameterSymbol>,
|
||||
methodName: String,
|
||||
method: SymbolLightMethodBase
|
||||
method: SymbolLightMethodBase,
|
||||
) : SymbolLightParameterBase(method) {
|
||||
private inline fun <T> withReceiverType(crossinline action: context(KtAnalysisSession) (KtType) -> T): T {
|
||||
private inline fun <T> withReceiverSymbol(crossinline action: context(KtAnalysisSession) (KtReceiverParameterSymbol) -> T): T {
|
||||
return analyzeForLightClasses(ktModule) {
|
||||
val callableSymbol = callableSymbolWithReceiverPointer.restoreSymbolOrThrowIfDisposed()
|
||||
action(this, requireNotNull(callableSymbol.receiverType))
|
||||
action(this, receiverPointer.restoreSymbolOrThrowIfDisposed())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,17 +40,15 @@ internal class SymbolLightParameterForReceiver private constructor(
|
||||
fun tryGet(
|
||||
callableSymbolPointer: KtSymbolPointer<KtCallableSymbol>,
|
||||
method: SymbolLightMethodBase
|
||||
): SymbolLightParameterForReceiver? {
|
||||
val methodName = analyzeForLightClasses(method.ktModule) {
|
||||
val callableSymbol = callableSymbolPointer.restoreSymbolOrThrowIfDisposed()
|
||||
if (callableSymbol !is KtNamedSymbol) return@analyzeForLightClasses null
|
||||
if (!callableSymbol.isExtension || callableSymbol.receiverType == null) return@analyzeForLightClasses null
|
||||
callableSymbol.name.asString()
|
||||
} ?: return null
|
||||
): SymbolLightParameterForReceiver? = analyzeForLightClasses(method.ktModule) {
|
||||
val callableSymbol = callableSymbolPointer.restoreSymbolOrThrowIfDisposed()
|
||||
if (callableSymbol !is KtNamedSymbol) return@analyzeForLightClasses null
|
||||
if (!callableSymbol.isExtension) return@analyzeForLightClasses null
|
||||
val receiverSymbol = callableSymbol.receiverParameter ?: return@analyzeForLightClasses null
|
||||
|
||||
return SymbolLightParameterForReceiver(
|
||||
callableSymbolWithReceiverPointer = callableSymbolPointer,
|
||||
methodName = methodName,
|
||||
SymbolLightParameterForReceiver(
|
||||
receiverPointer = receiverSymbol.createPointer(),
|
||||
methodName = callableSymbol.name.asString(),
|
||||
method = method,
|
||||
)
|
||||
}
|
||||
@@ -75,10 +68,10 @@ internal class SymbolLightParameterForReceiver private constructor(
|
||||
override val kotlinOrigin: KtParameter? = null
|
||||
|
||||
private val _annotations: List<PsiAnnotation> by lazyPub {
|
||||
withReceiverType { receiverType ->
|
||||
withReceiverSymbol { receiver ->
|
||||
buildList {
|
||||
receiverType.nullabilityType.computeNullabilityAnnotation(this@SymbolLightParameterForReceiver)?.let { add(it) }
|
||||
receiverType.annotations.mapTo(this) {
|
||||
receiver.type.nullabilityType.computeNullabilityAnnotation(this@SymbolLightParameterForReceiver)?.let(::add)
|
||||
receiver.annotations.mapTo(this) {
|
||||
SymbolLightAnnotationForAnnotationCall(it, this@SymbolLightParameterForReceiver)
|
||||
}
|
||||
}
|
||||
@@ -92,8 +85,8 @@ internal class SymbolLightParameterForReceiver private constructor(
|
||||
}
|
||||
|
||||
private val _type: PsiType by lazy {
|
||||
withReceiverType { receiverType ->
|
||||
receiverType.asPsiType(this@SymbolLightParameterForReceiver)
|
||||
withReceiverSymbol { receiver ->
|
||||
receiver.type.asPsiType(this@SymbolLightParameterForReceiver)
|
||||
} ?: nonExistentType()
|
||||
}
|
||||
|
||||
@@ -102,13 +95,9 @@ internal class SymbolLightParameterForReceiver private constructor(
|
||||
override fun equals(other: Any?): Boolean = this === other ||
|
||||
other is SymbolLightParameterForReceiver &&
|
||||
ktModule == other.ktModule &&
|
||||
compareSymbolPointers(ktModule, callableSymbolWithReceiverPointer, other.callableSymbolWithReceiverPointer)
|
||||
compareSymbolPointers(ktModule, receiverPointer, other.receiverPointer)
|
||||
|
||||
override fun hashCode(): Int = _name.hashCode()
|
||||
|
||||
override fun isValid(): Boolean = super.isValid() && analyzeForLightClasses(ktModule) {
|
||||
callableSymbolWithReceiverPointer.restoreSymbol()?.receiverType != null
|
||||
}
|
||||
override fun isValid(): Boolean = super.isValid() && receiverPointer.isValid(ktModule)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@ public final class Test /* Test*/ {
|
||||
|
||||
public final void fooF(@MyAnnotation7() @org.jetbrains.annotations.NotNull() int);// fooF(int)
|
||||
|
||||
public final void fooWithNullableReceiver(@MyAnnotation7() @org.jetbrains.annotations.Nullable() java.lang.Integer, long);// fooWithNullableReceiver(java.lang.Integer, long)
|
||||
|
||||
public final void setFooP(@MyAnnotation7() @org.jetbrains.annotations.NotNull() int, @org.jetbrains.annotations.NotNull() kotlin.Unit);// setFooP(int, kotlin.Unit)
|
||||
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ public final class Test /* Test*/ {
|
||||
|
||||
public final void fooF(@MyAnnotation7() int);// fooF(int)
|
||||
|
||||
public final void fooWithNullableReceiver(@MyAnnotation7() @org.jetbrains.annotations.Nullable() java.lang.Integer, long);// fooWithNullableReceiver(java.lang.Integer, long)
|
||||
|
||||
public final void setFooP(@MyAnnotation7() int, @org.jetbrains.annotations.NotNull() kotlin.Unit);// setFooP(int, kotlin.Unit)
|
||||
|
||||
}
|
||||
@@ -8,10 +8,13 @@ annotation class MyAnnotation6
|
||||
@Target(AnnotationTarget.VALUE_PARAMETER)
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class MyAnnotation7
|
||||
@Target(AnnotationTarget.TYPE)
|
||||
annotation class MyAnnotation8
|
||||
|
||||
class Test(@get:MyAnnotation @set:MyAnnotation2 @setparam:MyAnnotation3 @property:MyAnnotation4 @field:MyAnnotation5 @param:MyAnnotation6 var bar: String) {
|
||||
fun @receiver:MyAnnotation7 Int.fooF() = Unit
|
||||
var @receiver:MyAnnotation7 Int.fooP
|
||||
fun @receiver:MyAnnotation7 @MyAnnotation8 Int.fooF() = Unit
|
||||
fun @receiver:MyAnnotation7 @MyAnnotation8 Int?.fooWithNullableReceiver(l: Long) = Unit
|
||||
var @receiver:MyAnnotation7 @MyAnnotation8 Int.fooP
|
||||
get() = Unit
|
||||
set(value) {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user