From 29b94f650c5c5baf2bfc7418eb03a22aaf766d05 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Fri, 10 Jun 2016 17:35:46 +0300 Subject: [PATCH] Make Kotlin light class more like PsiAnonymousClassImpl Avoid delegating to cls delegate in more places --- .../KtLightClassForAnonymousDeclaration.kt | 17 ++++++++++++----- .../KtLightClassForExplicitDeclaration.kt | 8 ++++---- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightClassForAnonymousDeclaration.kt b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightClassForAnonymousDeclaration.kt index 9dfbffe1977..71be72c5e6e 100644 --- a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightClassForAnonymousDeclaration.kt +++ b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightClassForAnonymousDeclaration.kt @@ -18,7 +18,6 @@ package org.jetbrains.kotlin.asJava import com.intellij.openapi.diagnostic.Logger import com.intellij.psi.* -import com.intellij.psi.impl.InheritanceImplUtil import com.intellij.psi.search.GlobalSearchScope import com.intellij.reference.SoftReference import org.jetbrains.kotlin.name.FqName @@ -35,10 +34,6 @@ internal open class KtLightClassForAnonymousDeclaration(name: FqName, return JavaPsiFacade.getElementFactory(classOrObject.project).createReferenceElementByType(baseClassType) } - override fun getContainingClass(): PsiClass? { - return delegate.containingClass - } - private val firstSupertypeFQName: String get() { val descriptor = getDescriptor() ?: return CommonClassNames.JAVA_LANG_OBJECT @@ -104,6 +99,18 @@ internal open class KtLightClassForAnonymousDeclaration(name: FqName, return classOrObject.hashCode() } + override fun getNameIdentifier() = null + override fun getQualifiedName(): String? = null + override fun getModifierList(): PsiModifierList? = null + override fun hasModifierProperty(name: String): Boolean = name == PsiModifier.FINAL + override fun getExtendsList(): PsiReferenceList? = null + override fun getImplementsList(): PsiReferenceList? = null + override fun getContainingClass(): PsiClass? = null + override fun isInterface() = false + override fun isAnnotationType() = false + override fun getTypeParameterList() = null + override fun isEnum() = false + companion object { private val LOG = Logger.getInstance(KtLightClassForAnonymousDeclaration::class.java) } diff --git a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightClassForExplicitDeclaration.kt b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightClassForExplicitDeclaration.kt index e5699567674..45b85ce5ad7 100644 --- a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightClassForExplicitDeclaration.kt +++ b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightClassForExplicitDeclaration.kt @@ -254,7 +254,7 @@ open class KtLightClassForExplicitDeclaration( override fun getName(): String? = classFqName.shortName().asString() - override fun getQualifiedName(): String = classFqName.asString() + override fun getQualifiedName(): String? = classFqName.asString() private val _modifierList : PsiModifierList by lazy(LazyThreadSafetyMode.PUBLICATION) { object : KtLightModifierListWithExplicitModifiers(this@KtLightClassForExplicitDeclaration, computeModifiers()) { @@ -263,7 +263,7 @@ open class KtLightClassForExplicitDeclaration( } } - override fun getModifierList(): PsiModifierList = _modifierList + override fun getModifierList(): PsiModifierList? = _modifierList protected open fun computeModifiers(): Array { val psiModifiers = hashSetOf() @@ -306,7 +306,7 @@ open class KtLightClassForExplicitDeclaration( private fun isSealed(): Boolean = classOrObject.hasModifier(SEALED_KEYWORD) - override fun hasModifierProperty(@NonNls name: String): Boolean = modifierList.hasModifierProperty(name) + override fun hasModifierProperty(@NonNls name: String): Boolean = modifierList?.hasModifierProperty(name) ?: false override fun isDeprecated(): Boolean { val jetModifierList = classOrObject.modifierList ?: return false @@ -392,7 +392,7 @@ open class KtLightClassForExplicitDeclaration( override fun getElementType(): IStubElementType, *>? = classOrObject.elementType override fun getStub(): KotlinClassOrObjectStub? = classOrObject.stub - override fun getNameIdentifier() = lightIdentifier + override fun getNameIdentifier(): KtLightIdentifier? = lightIdentifier companion object { private val JAVA_API_STUB = Key.create>("JAVA_API_STUB")