[Analysis API] add info about context receivers to the Analysis API
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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.base
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeOwner
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtType
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
/**
|
||||
* A context receiver of function/property type which are directly specified in the code
|
||||
*
|
||||
* E.g, for the following code
|
||||
* ```
|
||||
* context(a@Int)
|
||||
* fun foo(){}
|
||||
* ```
|
||||
*
|
||||
* the context receiver is `KtContextReceiver(type=KtClassType(Int), label="a")`
|
||||
*/
|
||||
public abstract class KtContextReceiver : KtLifetimeOwner {
|
||||
/**
|
||||
* Type of the context receiver
|
||||
*
|
||||
* @see KtContextReceiver
|
||||
*/
|
||||
public abstract val type: KtType
|
||||
|
||||
/**
|
||||
* Additional label for the context receivers in the format `label@Type`, if label is not present, return `null`
|
||||
*
|
||||
* @see KtContextReceiver
|
||||
*/
|
||||
public abstract val label: Name?
|
||||
}
|
||||
|
||||
/**
|
||||
* Something which can have a [KtContextReceiver] declared. This may be a callable symbol or a class symbol
|
||||
*/
|
||||
public interface KtContextReceiversOwner : KtLifetimeOwner {
|
||||
/**
|
||||
* List of [KtContextReceiver] directly declared in the source code
|
||||
*/
|
||||
public val contextReceivers: List<KtContextReceiver>
|
||||
}
|
||||
+12
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.analysis.api.KtConstantInitializerValue
|
||||
import org.jetbrains.kotlin.analysis.api.KtInitializerValue
|
||||
import org.jetbrains.kotlin.analysis.api.KtNonConstantInitializerValue
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.*
|
||||
import org.jetbrains.kotlin.analysis.api.base.KtContextReceiver
|
||||
import org.jetbrains.kotlin.analysis.api.components.KtSymbolContainingDeclarationProviderMixIn
|
||||
import org.jetbrains.kotlin.analysis.api.components.KtSymbolInfoProviderMixIn
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtNamedSymbol
|
||||
@@ -203,6 +204,7 @@ public object DebugSymbolRenderer {
|
||||
is KtAnnotationValue -> renderAnnotationValue(value)
|
||||
is KtNamedAnnotationValue -> renderNamedConstantValue(value)
|
||||
is KtInitializerValue -> renderKtInitializerValue(value)
|
||||
is KtContextReceiver -> rendeContextReceiver(value)
|
||||
is KtAnnotationApplication -> renderAnnotationApplication(value)
|
||||
is KtAnnotationsList -> renderAnnotationsList(value)
|
||||
is KtModule -> renderKtModule(value)
|
||||
@@ -224,6 +226,16 @@ public object DebugSymbolRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
private fun PrettyPrinter.rendeContextReceiver(receiver: KtContextReceiver) {
|
||||
append("ContextReceiver(")
|
||||
receiver.label?.let { label ->
|
||||
renderValue(label)
|
||||
append("@")
|
||||
}
|
||||
renderType(receiver.type)
|
||||
append(")")
|
||||
}
|
||||
|
||||
private fun PrettyPrinter.renderKtModule(ktModule: KtModule) {
|
||||
val ktModuleClass = ktModule::class.allSuperclasses.filter { it in ktModuleSubclasses }.first()
|
||||
append("${ktModuleClass.simpleName} \"${ktModule.moduleDescription}\"")
|
||||
|
||||
+2
-1
@@ -5,13 +5,14 @@
|
||||
|
||||
package org.jetbrains.kotlin.analysis.api.symbols
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.base.KtContextReceiversOwner
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtPossibleMemberSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtSymbolWithKind
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtType
|
||||
import org.jetbrains.kotlin.name.CallableId
|
||||
|
||||
public sealed class KtCallableSymbol : KtSymbolWithKind, KtPossibleMemberSymbol, KtDeclarationSymbol {
|
||||
public sealed class KtCallableSymbol : KtSymbolWithKind, KtPossibleMemberSymbol, KtDeclarationSymbol, KtContextReceiversOwner {
|
||||
public abstract val callableIdIfNonLocal: CallableId?
|
||||
public abstract val returnType: KtType
|
||||
|
||||
|
||||
+3
-1
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.analysis.api.symbols
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.base.KtContextReceiversOwner
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.*
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
||||
@@ -74,7 +75,8 @@ public abstract class KtAnonymousObjectSymbol : KtClassOrObjectSymbol() {
|
||||
public abstract class KtNamedClassOrObjectSymbol : KtClassOrObjectSymbol(),
|
||||
KtSymbolWithModality,
|
||||
KtSymbolWithVisibility,
|
||||
KtNamedSymbol {
|
||||
KtNamedSymbol,
|
||||
KtContextReceiversOwner {
|
||||
|
||||
public abstract val isInner: Boolean
|
||||
public abstract val isData: Boolean
|
||||
|
||||
+2
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.analysis.api.symbols
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.base.KtContextReceiver
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.*
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
||||
@@ -74,6 +75,7 @@ public abstract class KtConstructorSymbol : KtFunctionLikeSymbol(),
|
||||
final override val symbolKind: KtSymbolKind get() = withValidityAssertion { KtSymbolKind.CLASS_MEMBER }
|
||||
final override val isExtension: Boolean get() = withValidityAssertion { false }
|
||||
final override val receiverType: KtType? get() = withValidityAssertion { null }
|
||||
final override val contextReceivers: List<KtContextReceiver> get() = withValidityAssertion { emptyList() }
|
||||
|
||||
abstract override fun createPointer(): KtSymbolPointer<KtConstructorSymbol>
|
||||
}
|
||||
|
||||
+3
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.analysis.api.symbols
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.base.KtContextReceiver
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.*
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
||||
@@ -20,6 +21,8 @@ public sealed class KtPropertyAccessorSymbol : KtFunctionLikeSymbol(),
|
||||
final override val typeParameters: List<KtTypeParameterSymbol>
|
||||
get() = withValidityAssertion { emptyList() }
|
||||
|
||||
final override val contextReceivers: List<KtContextReceiver> get() = withValidityAssertion { emptyList() }
|
||||
|
||||
public abstract val isDefault: Boolean
|
||||
public abstract val isInline: Boolean
|
||||
public abstract val isOverride: Boolean
|
||||
|
||||
+8
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.analysis.api.symbols
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.analysis.api.*
|
||||
import org.jetbrains.kotlin.analysis.api.base.KtContextReceiver
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.builtins.StandardNames
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.*
|
||||
@@ -42,6 +43,7 @@ public abstract class KtBackingFieldSymbol : KtVariableLikeSymbol() {
|
||||
final override val callableIdIfNonLocal: CallableId? get() = withValidityAssertion { null }
|
||||
final override val isExtension: Boolean get() = withValidityAssertion { false }
|
||||
final override val receiverType: KtType? get() = withValidityAssertion { null }
|
||||
final override val contextReceivers: List<KtContextReceiver> get() = withValidityAssertion { emptyList() }
|
||||
|
||||
final override val typeParameters: List<KtTypeParameterSymbol>
|
||||
get() = withValidityAssertion { emptyList() }
|
||||
@@ -58,6 +60,7 @@ public abstract class KtEnumEntrySymbol : KtVariableLikeSymbol(), KtSymbolWithMe
|
||||
final override val symbolKind: KtSymbolKind get() = withValidityAssertion { KtSymbolKind.CLASS_MEMBER }
|
||||
final override val isExtension: Boolean get() = withValidityAssertion { false }
|
||||
final override val receiverType: KtType? get() = withValidityAssertion { null }
|
||||
final override val contextReceivers: List<KtContextReceiver> get() = withValidityAssertion { emptyList() }
|
||||
|
||||
final override val typeParameters: List<KtTypeParameterSymbol>
|
||||
get() = withValidityAssertion { emptyList() }
|
||||
@@ -82,6 +85,7 @@ public abstract class KtJavaFieldSymbol :
|
||||
final override val symbolKind: KtSymbolKind get() = withValidityAssertion { KtSymbolKind.CLASS_MEMBER }
|
||||
final override val isExtension: Boolean get() = withValidityAssertion { false }
|
||||
final override val receiverType: KtType? get() = withValidityAssertion { null }
|
||||
final override val contextReceivers: List<KtContextReceiver> get() = withValidityAssertion { emptyList() }
|
||||
|
||||
final override val typeParameters: List<KtTypeParameterSymbol>
|
||||
get() = withValidityAssertion { emptyList() }
|
||||
@@ -137,6 +141,8 @@ public abstract class KtSyntheticJavaPropertySymbol : KtPropertySymbol() {
|
||||
final override val isDelegatedProperty: Boolean get() = withValidityAssertion { false }
|
||||
final override val hasGetter: Boolean get() = withValidityAssertion { true }
|
||||
final override val symbolKind: KtSymbolKind get() = withValidityAssertion { KtSymbolKind.CLASS_MEMBER }
|
||||
final override val contextReceivers: List<KtContextReceiver> get() = withValidityAssertion { emptyList() }
|
||||
|
||||
|
||||
abstract override val getter: KtPropertyGetterSymbol
|
||||
|
||||
@@ -150,6 +156,7 @@ public abstract class KtLocalVariableSymbol : KtVariableSymbol(), KtSymbolWithKi
|
||||
final override val callableIdIfNonLocal: CallableId? get() = withValidityAssertion { null }
|
||||
final override val isExtension: Boolean get() = withValidityAssertion { false }
|
||||
final override val receiverType: KtType? get() = withValidityAssertion { null }
|
||||
final override val contextReceivers: List<KtContextReceiver> get() = withValidityAssertion { emptyList() }
|
||||
|
||||
final override val typeParameters: List<KtTypeParameterSymbol>
|
||||
get() = withValidityAssertion { emptyList() }
|
||||
@@ -162,6 +169,7 @@ public abstract class KtValueParameterSymbol : KtVariableLikeSymbol(), KtSymbolW
|
||||
final override val callableIdIfNonLocal: CallableId? get() = withValidityAssertion { null }
|
||||
final override val isExtension: Boolean get() = withValidityAssertion { false }
|
||||
final override val receiverType: KtType? get() = withValidityAssertion { null }
|
||||
final override val contextReceivers: List<KtContextReceiver> get() = withValidityAssertion { emptyList() }
|
||||
|
||||
final override val typeParameters: List<KtTypeParameterSymbol>
|
||||
get() = withValidityAssertion { emptyList() }
|
||||
|
||||
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
context(kotlin.Int, s@kotlin.String)
|
||||
class A {
|
||||
constructor(int: Int) {}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
class A {
|
||||
constructor(int: kotlin.Int)
|
||||
}
|
||||
Vendored
+63
@@ -0,0 +1,63 @@
|
||||
KtValueParameterSymbol:
|
||||
annotationsList: []
|
||||
callableIdIfNonLocal: null
|
||||
contextReceivers: []
|
||||
generatedPrimaryConstructorProperty: null
|
||||
hasDefaultValue: false
|
||||
isExtension: false
|
||||
isImplicitLambdaParameter: false
|
||||
isVararg: false
|
||||
name: int
|
||||
origin: SOURCE
|
||||
receiverType: null
|
||||
returnType: kotlin/Int
|
||||
symbolKind: LOCAL
|
||||
typeParameters: []
|
||||
getContainingModule: KtSourceModule "Sources of main"
|
||||
deprecationStatus: null
|
||||
|
||||
KtConstructorSymbol:
|
||||
annotationsList: []
|
||||
callableIdIfNonLocal: null
|
||||
containingClassIdIfNonLocal: A
|
||||
contextReceivers: []
|
||||
hasStableParameterNames: true
|
||||
isExtension: false
|
||||
isPrimary: false
|
||||
origin: SOURCE
|
||||
receiverType: null
|
||||
returnType: A
|
||||
symbolKind: CLASS_MEMBER
|
||||
typeParameters: []
|
||||
valueParameters: [
|
||||
KtValueParameterSymbol(int)
|
||||
]
|
||||
visibility: Public
|
||||
getContainingModule: KtSourceModule "Sources of main"
|
||||
deprecationStatus: null
|
||||
|
||||
KtNamedClassOrObjectSymbol:
|
||||
annotationsList: []
|
||||
classIdIfNonLocal: A
|
||||
classKind: CLASS
|
||||
companionObject: null
|
||||
contextReceivers: [
|
||||
ContextReceiver(kotlin/Int)
|
||||
ContextReceiver(s@kotlin/String)
|
||||
]
|
||||
isData: false
|
||||
isExternal: false
|
||||
isFun: false
|
||||
isInline: false
|
||||
isInner: false
|
||||
modality: FINAL
|
||||
name: A
|
||||
origin: SOURCE
|
||||
superTypes: [
|
||||
kotlin/Any
|
||||
]
|
||||
symbolKind: TOP_LEVEL
|
||||
typeParameters: []
|
||||
visibility: Public
|
||||
getContainingModule: KtSourceModule "Sources of main"
|
||||
deprecationStatus: null
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
context(Int, s@String)
|
||||
fun y(){}
|
||||
+1
@@ -0,0 +1 @@
|
||||
fun y()
|
||||
Vendored
+28
@@ -0,0 +1,28 @@
|
||||
KtFunctionSymbol:
|
||||
annotationsList: []
|
||||
callableIdIfNonLocal: /y
|
||||
contextReceivers: [
|
||||
ContextReceiver(kotlin/Int)
|
||||
ContextReceiver(s@kotlin/String)
|
||||
]
|
||||
hasStableParameterNames: true
|
||||
isBuiltinFunctionInvoke: false
|
||||
isExtension: false
|
||||
isExternal: false
|
||||
isInfix: false
|
||||
isInline: false
|
||||
isOperator: false
|
||||
isOverride: false
|
||||
isStatic: false
|
||||
isSuspend: false
|
||||
modality: FINAL
|
||||
name: y
|
||||
origin: SOURCE
|
||||
receiverType: null
|
||||
returnType: kotlin/Unit
|
||||
symbolKind: TOP_LEVEL
|
||||
typeParameters: []
|
||||
valueParameters: []
|
||||
visibility: Public
|
||||
getContainingModule: KtSourceModule "Sources of main"
|
||||
deprecationStatus: null
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
context(Int, s@String)
|
||||
val y get() = 10
|
||||
+1
@@ -0,0 +1 @@
|
||||
val y: kotlin.Int
|
||||
Vendored
+56
@@ -0,0 +1,56 @@
|
||||
KtPropertyGetterSymbol:
|
||||
annotationsList: []
|
||||
callableIdIfNonLocal: null
|
||||
contextReceivers: []
|
||||
hasBody: true
|
||||
hasStableParameterNames: true
|
||||
isDefault: false
|
||||
isExtension: false
|
||||
isInline: false
|
||||
isOverride: false
|
||||
modality: FINAL
|
||||
origin: SOURCE
|
||||
receiverType: null
|
||||
returnType: kotlin/Int
|
||||
symbolKind: ACCESSOR
|
||||
typeParameters: []
|
||||
valueParameters: []
|
||||
visibility: Public
|
||||
getContainingModule: KtSourceModule "Sources of main"
|
||||
deprecationStatus: null
|
||||
|
||||
KtKotlinPropertySymbol:
|
||||
annotationsList: []
|
||||
callableIdIfNonLocal: /y
|
||||
contextReceivers: [
|
||||
ContextReceiver(kotlin/Int)
|
||||
ContextReceiver(s@kotlin/String)
|
||||
]
|
||||
getter: KtPropertyGetterSymbol(<getter>)
|
||||
hasBackingField: false
|
||||
hasGetter: true
|
||||
hasSetter: false
|
||||
initializer: null
|
||||
isConst: false
|
||||
isDelegatedProperty: false
|
||||
isExtension: false
|
||||
isFromPrimaryConstructor: false
|
||||
isLateInit: false
|
||||
isOverride: false
|
||||
isStatic: false
|
||||
isVal: true
|
||||
modality: FINAL
|
||||
name: y
|
||||
origin: SOURCE
|
||||
receiverType: null
|
||||
returnType: kotlin/Int
|
||||
setter: null
|
||||
symbolKind: TOP_LEVEL
|
||||
typeParameters: []
|
||||
visibility: Public
|
||||
getContainingModule: KtSourceModule "Sources of main"
|
||||
deprecationStatus: null
|
||||
getterDeprecationStatus: null
|
||||
javaGetterName: getY
|
||||
javaSetterName: null
|
||||
setterDeprecationStatus: null
|
||||
Reference in New Issue
Block a user