Stubs: add classId to KtTypeAlias stubs
This commit is contained in:
@@ -21,11 +21,13 @@ import com.intellij.navigation.ItemPresentationProviders
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.KtNodeTypes
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.psi.psiUtil.ClassIdCalculator
|
||||
import org.jetbrains.kotlin.psi.stubs.KotlinPlaceHolderStub
|
||||
import org.jetbrains.kotlin.psi.stubs.KotlinTypeAliasStub
|
||||
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes
|
||||
|
||||
class KtTypeAlias : KtTypeParameterListOwnerStub<KotlinTypeAliasStub>, KtNamedDeclaration {
|
||||
class KtTypeAlias : KtTypeParameterListOwnerStub<KotlinTypeAliasStub>, KtNamedDeclaration, KtClassLikeDeclaration {
|
||||
constructor(node: ASTNode) : super(node)
|
||||
constructor(stub: KotlinTypeAliasStub) : super(stub, KtStubElementTypes.TYPEALIAS)
|
||||
|
||||
@@ -50,5 +52,10 @@ class KtTypeAlias : KtTypeParameterListOwnerStub<KotlinTypeAliasStub>, KtNamedDe
|
||||
}
|
||||
}
|
||||
|
||||
override fun getClassId(): ClassId? {
|
||||
stub?.let { return it.getClassId() }
|
||||
return ClassIdCalculator.calculateClassId(this)
|
||||
}
|
||||
|
||||
override fun getPresentation() = ItemPresentationProviders.getItemPresentation(this)
|
||||
}
|
||||
|
||||
@@ -15,13 +15,13 @@ internal object ClassIdCalculator {
|
||||
fun calculateClassId(declaration: KtClassLikeDeclaration): ClassId? {
|
||||
var ktFile: KtFile? = null
|
||||
var element: PsiElement? = declaration
|
||||
val containingClasses = mutableListOf<KtClassOrObject>()
|
||||
val containingClasses = mutableListOf<KtClassLikeDeclaration>()
|
||||
while (element != null) {
|
||||
when (element) {
|
||||
is KtEnumEntry -> {
|
||||
return null
|
||||
}
|
||||
is KtClassOrObject -> {
|
||||
is KtClassLikeDeclaration -> {
|
||||
containingClasses += element
|
||||
}
|
||||
is KtFile -> {
|
||||
|
||||
@@ -45,7 +45,7 @@ interface KotlinClassifierStub {
|
||||
fun getClassId(): ClassId?
|
||||
}
|
||||
|
||||
interface KotlinTypeAliasStub : KotlinStubWithFqName<KtTypeAlias> {
|
||||
interface KotlinTypeAliasStub : KotlinClassifierStub, KotlinStubWithFqName<KtTypeAlias> {
|
||||
fun isTopLevel(): Boolean
|
||||
}
|
||||
|
||||
|
||||
@@ -21,9 +21,13 @@ import com.intellij.psi.stubs.StubElement
|
||||
import com.intellij.psi.stubs.StubInputStream
|
||||
import com.intellij.psi.stubs.StubOutputStream
|
||||
import com.intellij.util.io.StringRef
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.psi.KtTypeAlias
|
||||
import org.jetbrains.kotlin.psi.psiUtil.safeFqNameForLazyResolve
|
||||
import org.jetbrains.kotlin.psi.stubs.KotlinClassStub
|
||||
import org.jetbrains.kotlin.psi.stubs.KotlinFileStub
|
||||
import org.jetbrains.kotlin.psi.stubs.KotlinTypeAliasStub
|
||||
import org.jetbrains.kotlin.psi.stubs.StubUtils
|
||||
import org.jetbrains.kotlin.psi.stubs.impl.KotlinTypeAliasStubImpl
|
||||
|
||||
class KtTypeAliasElementType(debugName: String) :
|
||||
@@ -32,21 +36,36 @@ class KtTypeAliasElementType(debugName: String) :
|
||||
override fun createStub(psi: KtTypeAlias, parentStub: StubElement<*>?): KotlinTypeAliasStub {
|
||||
val name = StringRef.fromString(psi.name)
|
||||
val fqName = StringRef.fromString(psi.safeFqNameForLazyResolve()?.asString())
|
||||
val classId = parentStub?.let { createNestedClassId(it, psi) }
|
||||
val isTopLevel = psi.isTopLevel()
|
||||
return KotlinTypeAliasStubImpl(parentStub, name, fqName, isTopLevel)
|
||||
return KotlinTypeAliasStubImpl(parentStub, name, fqName, classId, isTopLevel)
|
||||
}
|
||||
|
||||
private fun createNestedClassId(parentStub: StubElement<*>, typeAlias: KtTypeAlias): ClassId? {
|
||||
val typeAliasName = typeAlias.nameAsName ?: return null
|
||||
return when {
|
||||
parentStub.stubType == KtStubElementTypes.CLASS_BODY -> {
|
||||
val parentClass = parentStub.parentStub as? KotlinClassStub
|
||||
parentClass?.getClassId()?.createNestedClassId(typeAliasName)
|
||||
}
|
||||
parentStub is KotlinFileStub -> ClassId(parentStub.getPackageFqName(), typeAliasName)
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
override fun serialize(stub: KotlinTypeAliasStub, dataStream: StubOutputStream) {
|
||||
dataStream.writeName(stub.name)
|
||||
dataStream.writeName(stub.getFqName()?.asString())
|
||||
StubUtils.serializeClassId(dataStream, stub.getClassId())
|
||||
dataStream.writeBoolean(stub.isTopLevel())
|
||||
}
|
||||
|
||||
override fun deserialize(dataStream: StubInputStream, parentStub: StubElement<*>?): KotlinTypeAliasStub {
|
||||
val name = dataStream.readName()
|
||||
val fqName = dataStream.readName()
|
||||
val classId = StubUtils.deserializeClassId(dataStream)
|
||||
val isTopLevel = dataStream.readBoolean()
|
||||
return KotlinTypeAliasStubImpl(parentStub, name, fqName, isTopLevel)
|
||||
return KotlinTypeAliasStubImpl(parentStub, name, fqName, classId, isTopLevel)
|
||||
}
|
||||
|
||||
override fun indexStub(stub: KotlinTypeAliasStub, sink: IndexSink) {
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.psi.stubs.impl
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.stubs.StubElement
|
||||
import com.intellij.util.io.StringRef
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.psi.KtTypeAlias
|
||||
import org.jetbrains.kotlin.psi.stubs.KotlinTypeAliasStub
|
||||
@@ -28,14 +29,16 @@ class KotlinTypeAliasStubImpl(
|
||||
parent: StubElement<out PsiElement>?,
|
||||
private val name: StringRef?,
|
||||
private val qualifiedName: StringRef?,
|
||||
private val classId: ClassId?,
|
||||
private val isTopLevel: Boolean
|
||||
) : KotlinStubBaseImpl<KtTypeAlias>(parent, KtStubElementTypes.TYPEALIAS), KotlinTypeAliasStub {
|
||||
|
||||
override fun getName(): String? =
|
||||
StringRef.toString(name)
|
||||
|
||||
override fun getFqName(): FqName? =
|
||||
StringRef.toString(qualifiedName)?.let(::FqName)
|
||||
|
||||
override fun getClassId(): ClassId? = classId
|
||||
|
||||
override fun isTopLevel(): Boolean = isTopLevel
|
||||
}
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ fun createTypeAliasStub(
|
||||
}
|
||||
|
||||
val typeAlias = KotlinTypeAliasStubImpl(
|
||||
parent, classId.shortClassName.ref(), classId.asSingleFqName().ref(),
|
||||
parent, classId.shortClassName.ref(), classId.asSingleFqName().ref(), classId,
|
||||
isTopLevel = !classId.isNestedClass
|
||||
)
|
||||
|
||||
|
||||
+1
-1
@@ -154,7 +154,7 @@ PsiJetFileStubImpl[package=foo.TopLevelMembers]
|
||||
USER_TYPE
|
||||
REFERENCE_EXPRESSION[referencedName=kotlin]
|
||||
REFERENCE_EXPRESSION[referencedName=Int]
|
||||
TYPEALIAS[fqName=foo.TopLevelMembers.Alias, isTopLevel=true, name=Alias]
|
||||
TYPEALIAS[classId=foo/TopLevelMembers/Alias, fqName=foo.TopLevelMembers.Alias, isTopLevel=true, name=Alias]
|
||||
MODIFIER_LIST[private]
|
||||
TYPE_PARAMETER_LIST
|
||||
TYPE_PARAMETER[fqName=null, isInVariance=false, isOutVariance=false, name=E]
|
||||
|
||||
@@ -107,7 +107,7 @@ PsiJetFileStubImpl[package=test]
|
||||
MODIFIER_LIST[public]
|
||||
VALUE_PARAMETER_LIST
|
||||
CLASS_BODY
|
||||
TYPEALIAS[fqName=test.TypeAliases.B, isTopLevel=false, name=B]
|
||||
TYPEALIAS[classId=test/TypeAliases.B, fqName=test.TypeAliases.B, isTopLevel=false, name=B]
|
||||
MODIFIER_LIST[public]
|
||||
TYPE_REFERENCE
|
||||
FUNCTION_TYPE
|
||||
@@ -123,7 +123,7 @@ PsiJetFileStubImpl[package=test]
|
||||
USER_TYPE
|
||||
REFERENCE_EXPRESSION[referencedName=kotlin]
|
||||
REFERENCE_EXPRESSION[referencedName=Unit]
|
||||
TYPEALIAS[fqName=test.TypeAliases.Parametrized, isTopLevel=false, name=Parametrized]
|
||||
TYPEALIAS[classId=test/TypeAliases.Parametrized, fqName=test.TypeAliases.Parametrized, isTopLevel=false, name=Parametrized]
|
||||
MODIFIER_LIST[private]
|
||||
ANNOTATION_ENTRY[hasValueArguments=false, shortName=Ann]
|
||||
CONSTRUCTOR_CALLEE
|
||||
|
||||
Reference in New Issue
Block a user