Adjust stub-builder, decompiler and renderer to new PSI structure
of primary ctor
This commit is contained in:
+8
-2
@@ -20,8 +20,10 @@ import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.stubs.StubElement
|
||||
import org.jetbrains.kotlin.idea.decompiler.stubBuilder.FlagsToModifiers.MODALITY
|
||||
import org.jetbrains.kotlin.idea.decompiler.stubBuilder.FlagsToModifiers.VISIBILITY
|
||||
import org.jetbrains.kotlin.lexer.JetTokens
|
||||
import org.jetbrains.kotlin.psi.JetSecondaryConstructor
|
||||
import org.jetbrains.kotlin.psi.stubs.elements.JetStubElementTypes
|
||||
import org.jetbrains.kotlin.psi.stubs.impl.KotlinClassStubImpl
|
||||
import org.jetbrains.kotlin.psi.stubs.impl.KotlinFunctionStubImpl
|
||||
import org.jetbrains.kotlin.psi.stubs.impl.KotlinPlaceHolderStubImpl
|
||||
import org.jetbrains.kotlin.psi.stubs.impl.KotlinPropertyStubImpl
|
||||
@@ -66,6 +68,7 @@ private class CallableClsStubBuilder(
|
||||
private val isTopLevel: Boolean get() = protoContainer.packageFqName != null
|
||||
private val callableKind = Flags.CALLABLE_KIND[callableProto.getFlags()]
|
||||
private val isConstructor = callableKind == ProtoBuf.Callable.CallableKind.CONSTRUCTOR
|
||||
private val isPrimaryConstructor = isConstructor && parent is KotlinClassStubImpl
|
||||
private val callableStub = doCreateCallableStub()
|
||||
|
||||
fun build() {
|
||||
@@ -101,7 +104,7 @@ private class CallableClsStubBuilder(
|
||||
val annotationIds = c.components.annotationLoader.loadCallableAnnotations(
|
||||
protoContainer, callableProto, c.nameResolver, callableProto.annotatedCallableKind
|
||||
)
|
||||
createAnnotationStubs(annotationIds, modifierListStubImpl)
|
||||
createAnnotationStubs(annotationIds, modifierListStubImpl, needWrappingAnnotationEntries = isPrimaryConstructor)
|
||||
}
|
||||
|
||||
private fun doCreateCallableStub(): StubElement<out PsiElement> {
|
||||
@@ -137,7 +140,10 @@ private class CallableClsStubBuilder(
|
||||
)
|
||||
}
|
||||
ProtoBuf.Callable.CallableKind.CONSTRUCTOR -> {
|
||||
KotlinPlaceHolderStubImpl<JetSecondaryConstructor>(parent, JetStubElementTypes.SECONDARY_CONSTRUCTOR)
|
||||
if (isPrimaryConstructor)
|
||||
KotlinPlaceHolderStubImpl(parent, JetStubElementTypes.PRIMARY_CONSTRUCTOR)
|
||||
else
|
||||
KotlinPlaceHolderStubImpl(parent, JetStubElementTypes.SECONDARY_CONSTRUCTOR)
|
||||
}
|
||||
else -> throw IllegalStateException("Unknown callable kind $callableKind")
|
||||
}
|
||||
|
||||
+6
-12
@@ -25,10 +25,7 @@ import org.jetbrains.kotlin.idea.decompiler.stubBuilder.FlagsToModifiers.VISIBIL
|
||||
import org.jetbrains.kotlin.lexer.JetModifierKeywordToken
|
||||
import org.jetbrains.kotlin.lexer.JetTokens
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.psi.JetClassBody
|
||||
import org.jetbrains.kotlin.psi.JetDelegationSpecifierList
|
||||
import org.jetbrains.kotlin.psi.JetDelegatorToSuperClass
|
||||
import org.jetbrains.kotlin.psi.JetParameterList
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.stubs.elements.JetClassElementType
|
||||
import org.jetbrains.kotlin.psi.stubs.elements.JetStubElementTypes
|
||||
import org.jetbrains.kotlin.psi.stubs.impl.KotlinClassStubImpl
|
||||
@@ -139,15 +136,12 @@ private class ClassClsStubBuilder(
|
||||
|
||||
private fun createConstructorStub() {
|
||||
if (!isClass() || !classProto.hasPrimaryConstructor()) return
|
||||
|
||||
val primaryConstructorProto = classProto.getPrimaryConstructor()
|
||||
if (primaryConstructorProto.hasData()) {
|
||||
typeStubBuilder.createValueParameterListStub(classOrObjectStub, primaryConstructorProto.getData(), ProtoContainer(classProto, null))
|
||||
}
|
||||
else {
|
||||
//default empty constructor
|
||||
KotlinPlaceHolderStubImpl<JetParameterList>(classOrObjectStub, JetStubElementTypes.VALUE_PARAMETER_LIST)
|
||||
}
|
||||
|
||||
assert(classProto.getPrimaryConstructor().hasData(),
|
||||
"Primary constructor in class is always non-default, so data should not be empty")
|
||||
|
||||
createCallableStub(classOrObjectStub, primaryConstructorProto.getData(), c, ProtoContainer(classProto, null))
|
||||
}
|
||||
|
||||
private fun createDelegationSpecifierList() {
|
||||
|
||||
+23
-14
@@ -25,10 +25,7 @@ import org.jetbrains.kotlin.lexer.JetTokens
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.JetConstructorCalleeExpression
|
||||
import org.jetbrains.kotlin.psi.JetDotQualifiedExpression
|
||||
import org.jetbrains.kotlin.psi.JetPackageDirective
|
||||
import org.jetbrains.kotlin.psi.JetTypeReference
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.stubs.KotlinUserTypeStub
|
||||
import org.jetbrains.kotlin.psi.stubs.elements.JetStubElementTypes
|
||||
import org.jetbrains.kotlin.psi.stubs.impl.*
|
||||
@@ -171,16 +168,28 @@ fun createModifierListStub(
|
||||
)
|
||||
}
|
||||
|
||||
fun createAnnotationStubs(annotationIds: List<ClassId>, modifierList: KotlinModifierListStubImpl) = annotationIds.forEach {
|
||||
annotationClassId ->
|
||||
val annotationEntryStubImpl = KotlinAnnotationEntryStubImpl(
|
||||
modifierList,
|
||||
shortName = annotationClassId.getShortClassName().ref(),
|
||||
hasValueArguments = false
|
||||
)
|
||||
val constructorCallee = KotlinPlaceHolderStubImpl<JetConstructorCalleeExpression>(annotationEntryStubImpl, JetStubElementTypes.CONSTRUCTOR_CALLEE)
|
||||
val typeReference = KotlinPlaceHolderStubImpl<JetTypeReference>(constructorCallee, JetStubElementTypes.TYPE_REFERENCE)
|
||||
createStubForTypeName(annotationClassId, typeReference)
|
||||
fun createAnnotationStubs(
|
||||
annotationIds: List<ClassId>,
|
||||
modifierList: KotlinModifierListStubImpl,
|
||||
needWrappingAnnotationEntries: Boolean = false
|
||||
) {
|
||||
if (annotationIds.isEmpty()) return
|
||||
|
||||
val entriesParent =
|
||||
if (needWrappingAnnotationEntries) KotlinPlaceHolderStubImpl<JetAnnotation>(modifierList, JetStubElementTypes.ANNOTATION)
|
||||
else modifierList
|
||||
|
||||
annotationIds.forEach {
|
||||
annotationClassId ->
|
||||
val annotationEntryStubImpl = KotlinAnnotationEntryStubImpl(
|
||||
entriesParent,
|
||||
shortName = annotationClassId.getShortClassName().ref(),
|
||||
hasValueArguments = false
|
||||
)
|
||||
val constructorCallee = KotlinPlaceHolderStubImpl<JetConstructorCalleeExpression>(annotationEntryStubImpl, JetStubElementTypes.CONSTRUCTOR_CALLEE)
|
||||
val typeReference = KotlinPlaceHolderStubImpl<JetTypeReference>(constructorCallee, JetStubElementTypes.TYPE_REFERENCE)
|
||||
createStubForTypeName(annotationClassId, typeReference)
|
||||
}
|
||||
}
|
||||
|
||||
val ProtoBuf.Callable.annotatedCallableKind: AnnotatedCallableKind
|
||||
|
||||
Reference in New Issue
Block a user