[cls] include property accessors in cls stubs
This commit is contained in:
+59
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes
|
||||
import org.jetbrains.kotlin.psi.stubs.impl.KotlinConstructorStubImpl
|
||||
import org.jetbrains.kotlin.psi.stubs.impl.KotlinFunctionStubImpl
|
||||
import org.jetbrains.kotlin.psi.stubs.impl.KotlinPropertyAccessorStubImpl
|
||||
import org.jetbrains.kotlin.psi.stubs.impl.KotlinPropertyStubImpl
|
||||
import org.jetbrains.kotlin.resolve.DataClassResolver
|
||||
import org.jetbrains.kotlin.serialization.deserialization.AnnotatedCallableKind
|
||||
@@ -99,6 +100,7 @@ abstract class CallableClsStubBuilder(
|
||||
createValueParameterList()
|
||||
createReturnTypeStub()
|
||||
typeStubBuilder.createTypeConstraintListStub(callableStub, typeConstraintListData)
|
||||
createCallableSpecialParts()
|
||||
}
|
||||
|
||||
abstract val receiverType: ProtoBuf.Type?
|
||||
@@ -124,6 +126,8 @@ abstract class CallableClsStubBuilder(
|
||||
abstract fun createValueParameterList()
|
||||
|
||||
abstract fun doCreateCallableStub(parent: StubElement<out PsiElement>): StubElement<out PsiElement>
|
||||
|
||||
protected open fun createCallableSpecialParts() {}
|
||||
}
|
||||
|
||||
private class FunctionClsStubBuilder(
|
||||
@@ -260,6 +264,61 @@ private class PropertyClsStubBuilder(
|
||||
fqName = c.containerFqName.child(callableName)
|
||||
)
|
||||
}
|
||||
|
||||
override fun createCallableSpecialParts() {
|
||||
val flags = propertyProto.flags
|
||||
if (Flags.HAS_GETTER[flags] && propertyProto.hasGetterFlags()) {
|
||||
val getterFlags = propertyProto.getterFlags
|
||||
if (Flags.IS_NOT_DEFAULT.get(getterFlags)) {
|
||||
createModifierListAndAnnotationStubsForAccessor(
|
||||
KotlinPropertyAccessorStubImpl(callableStub, true, false, true),
|
||||
flags = getterFlags,
|
||||
callableKind = AnnotatedCallableKind.PROPERTY_GETTER
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (Flags.HAS_SETTER[flags] && propertyProto.hasSetterFlags()) {
|
||||
val setterFlags = propertyProto.setterFlags
|
||||
if (Flags.IS_NOT_DEFAULT.get(setterFlags)) {
|
||||
val setterStub = KotlinPropertyAccessorStubImpl(callableStub, false, true, true)
|
||||
createModifierListAndAnnotationStubsForAccessor(
|
||||
setterStub,
|
||||
flags = setterFlags,
|
||||
callableKind = AnnotatedCallableKind.PROPERTY_SETTER
|
||||
)
|
||||
if (propertyProto.hasSetterValueParameter()) {
|
||||
typeStubBuilder.createValueParameterListStub(
|
||||
setterStub,
|
||||
propertyProto,
|
||||
listOf(propertyProto.setterValueParameter),
|
||||
protoContainer,
|
||||
AnnotatedCallableKind.PROPERTY_SETTER
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun createModifierListAndAnnotationStubsForAccessor(
|
||||
accessorStub: KotlinPropertyAccessorStubImpl,
|
||||
flags: Int,
|
||||
callableKind: AnnotatedCallableKind
|
||||
) {
|
||||
val modifierList = createModifierListStubForDeclaration(
|
||||
accessorStub,
|
||||
flags,
|
||||
listOf(VISIBILITY, MODALITY, INLINE_ACCESSOR, EXTERNAL_ACCESSOR)
|
||||
)
|
||||
if (Flags.HAS_ANNOTATIONS.get(flags)) {
|
||||
val annotationIds = c.components.annotationLoader.loadCallableAnnotations(
|
||||
protoContainer,
|
||||
propertyProto,
|
||||
callableKind
|
||||
)
|
||||
createAnnotationStubs(annotationIds, modifierList)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class ConstructorClsStubBuilder(
|
||||
|
||||
+9
-4
@@ -17,6 +17,7 @@ import org.jetbrains.kotlin.metadata.jvm.JvmProtoBuf
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.name.SpecialNames
|
||||
import org.jetbrains.kotlin.protobuf.MessageLite
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.stubs.KotlinUserTypeStub
|
||||
@@ -302,14 +303,18 @@ class TypeClsStubBuilder(private val c: ClsStubBuilderContext) {
|
||||
parent: StubElement<out PsiElement>,
|
||||
callableProto: MessageLite,
|
||||
parameters: List<ProtoBuf.ValueParameter>,
|
||||
container: ProtoContainer
|
||||
container: ProtoContainer,
|
||||
callableKind: AnnotatedCallableKind = callableProto.annotatedCallableKind
|
||||
) {
|
||||
val parameterListStub = KotlinPlaceHolderStubImpl<KtParameterList>(parent, KtStubElementTypes.VALUE_PARAMETER_LIST)
|
||||
for ((index, valueParameterProto) in parameters.withIndex()) {
|
||||
val name = c.nameResolver.getName(valueParameterProto.name)
|
||||
val paramName = when (val name = c.nameResolver.getName(valueParameterProto.name)) {
|
||||
SpecialNames.IMPLICIT_SET_PARAMETER -> StandardNames.DEFAULT_VALUE_PARAMETER
|
||||
else -> name
|
||||
}
|
||||
val parameterStub = KotlinParameterStubImpl(
|
||||
parameterListStub,
|
||||
name = name.ref(),
|
||||
name = paramName.ref(),
|
||||
fqName = null,
|
||||
hasDefaultValue = false,
|
||||
hasValOrVar = false,
|
||||
@@ -333,7 +338,7 @@ class TypeClsStubBuilder(private val c: ClsStubBuilderContext) {
|
||||
|
||||
if (Flags.HAS_ANNOTATIONS.get(valueParameterProto.flags)) {
|
||||
val parameterAnnotations = c.components.annotationLoader.loadValueParameterAnnotations(
|
||||
container, callableProto, callableProto.annotatedCallableKind, index, valueParameterProto
|
||||
container, callableProto, callableKind, index, valueParameterProto
|
||||
)
|
||||
if (parameterAnnotations.isNotEmpty()) {
|
||||
createAnnotationStubs(parameterAnnotations, modifierList ?: createEmptyModifierListStub(parameterStub))
|
||||
|
||||
+2
@@ -45,8 +45,10 @@ val INFIX = createBooleanFlagToModifier(Flags.IS_INFIX, KtTokens.INFIX_KEYWORD)
|
||||
val DATA = createBooleanFlagToModifier(Flags.IS_DATA, KtTokens.DATA_KEYWORD)
|
||||
val EXTERNAL_FUN = createBooleanFlagToModifier(Flags.IS_EXTERNAL_FUNCTION, KtTokens.EXTERNAL_KEYWORD)
|
||||
val EXTERNAL_PROPERTY = createBooleanFlagToModifier(Flags.IS_EXTERNAL_PROPERTY, KtTokens.EXTERNAL_KEYWORD)
|
||||
val EXTERNAL_ACCESSOR = createBooleanFlagToModifier(Flags.IS_EXTERNAL_ACCESSOR, KtTokens.EXTERNAL_KEYWORD)
|
||||
val EXTERNAL_CLASS = createBooleanFlagToModifier(Flags.IS_EXTERNAL_CLASS, KtTokens.EXTERNAL_KEYWORD)
|
||||
val INLINE = createBooleanFlagToModifier(Flags.IS_INLINE, KtTokens.INLINE_KEYWORD)
|
||||
val INLINE_ACCESSOR = createBooleanFlagToModifier(Flags.IS_INLINE_ACCESSOR, KtTokens.INLINE_KEYWORD)
|
||||
val VALUE_CLASS = createBooleanFlagToModifier(Flags.IS_VALUE_CLASS, KtTokens.VALUE_KEYWORD)
|
||||
val FUN_INTERFACE = createBooleanFlagToModifier(Flags.IS_FUN_INTERFACE, KtTokens.FUN_KEYWORD)
|
||||
val TAILREC = createBooleanFlagToModifier(Flags.IS_TAILREC, KtTokens.TAILREC_KEYWORD)
|
||||
|
||||
Reference in New Issue
Block a user