[DLC] cleanup code and drop some redundant constructions
^KT-56613
This commit is contained in:
committed by
Space Team
parent
007af1c547
commit
5e18ebcd7e
+38
-82
@@ -40,34 +40,21 @@ open class KtLightClassForDecompiledDeclaration(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getOwnMethods(): List<PsiMethod> = _methods
|
|
||||||
|
|
||||||
override fun getOwnFields(): List<PsiField> = _fields
|
|
||||||
|
|
||||||
override fun getOwnInnerClasses(): List<PsiClass> = _innerClasses
|
|
||||||
|
|
||||||
override fun getFields(): Array<PsiField> = myInnersCache.fields
|
override fun getFields(): Array<PsiField> = myInnersCache.fields
|
||||||
|
|
||||||
override fun getMethods(): Array<PsiMethod> = myInnersCache.methods
|
override fun getMethods(): Array<PsiMethod> = myInnersCache.methods
|
||||||
|
|
||||||
override fun getConstructors(): Array<PsiMethod> = myInnersCache.constructors
|
override fun getConstructors(): Array<PsiMethod> = myInnersCache.constructors
|
||||||
|
|
||||||
override fun getInnerClasses(): Array<PsiClass> = myInnersCache.innerClasses
|
override fun getInnerClasses(): Array<PsiClass> = myInnersCache.innerClasses
|
||||||
|
|
||||||
override fun findFieldByName(name: String, checkBases: Boolean): PsiField? = myInnersCache.findFieldByName(name, checkBases)
|
override fun findFieldByName(name: String, checkBases: Boolean): PsiField? = myInnersCache.findFieldByName(name, checkBases)
|
||||||
|
|
||||||
override fun findMethodsByName(name: String, checkBases: Boolean): Array<PsiMethod> = myInnersCache.findMethodsByName(name, checkBases)
|
override fun findMethodsByName(name: String, checkBases: Boolean): Array<PsiMethod> = myInnersCache.findMethodsByName(name, checkBases)
|
||||||
|
|
||||||
override fun findInnerClassByName(name: String, checkBases: Boolean): PsiClass? = myInnersCache.findInnerClassByName(name, checkBases)
|
override fun findInnerClassByName(name: String, checkBases: Boolean): PsiClass? = myInnersCache.findInnerClassByName(name, checkBases)
|
||||||
|
override fun hasModifierProperty(name: String): Boolean = clsDelegate.hasModifierProperty(name)
|
||||||
override fun hasModifierProperty(name: String): Boolean =
|
|
||||||
clsDelegate.hasModifierProperty(name)
|
|
||||||
|
|
||||||
override fun findMethodBySignature(patternMethod: PsiMethod?, checkBases: Boolean): PsiMethod? =
|
override fun findMethodBySignature(patternMethod: PsiMethod?, checkBases: Boolean): PsiMethod? =
|
||||||
patternMethod?.let { PsiClassImplUtil.findMethodBySignature(this, it, checkBases) }
|
patternMethod?.let { PsiClassImplUtil.findMethodBySignature(this, it, checkBases) }
|
||||||
|
|
||||||
override fun findMethodsBySignature(patternMethod: PsiMethod?, checkBases: Boolean): Array<PsiMethod?> =
|
override fun findMethodsBySignature(patternMethod: PsiMethod?, checkBases: Boolean): Array<PsiMethod> = patternMethod?.let {
|
||||||
patternMethod?.let { PsiClassImplUtil.findMethodsBySignature(this, it, checkBases) } ?: emptyArray()
|
PsiClassImplUtil.findMethodsBySignature(this, it, checkBases)
|
||||||
|
} ?: PsiMethod.EMPTY_ARRAY
|
||||||
|
|
||||||
override fun findMethodsAndTheirSubstitutorsByName(@NonNls name: String?, checkBases: Boolean): List<Pair<PsiMethod, PsiSubstitutor>> =
|
override fun findMethodsAndTheirSubstitutorsByName(@NonNls name: String?, checkBases: Boolean): List<Pair<PsiMethod, PsiSubstitutor>> =
|
||||||
PsiClassImplUtil.findMethodsAndTheirSubstitutorsByName(this, name, checkBases)
|
PsiClassImplUtil.findMethodsAndTheirSubstitutorsByName(this, name, checkBases)
|
||||||
@@ -89,77 +76,50 @@ open class KtLightClassForDecompiledDeclaration(
|
|||||||
PsiClassImplUtil.getAllWithSubstitutorsByMap<PsiMethod>(this, PsiClassImplUtil.MemberType.METHOD)
|
PsiClassImplUtil.getAllWithSubstitutorsByMap<PsiMethod>(this, PsiClassImplUtil.MemberType.METHOD)
|
||||||
|
|
||||||
override fun isInterface(): Boolean = clsDelegate.isInterface
|
override fun isInterface(): Boolean = clsDelegate.isInterface
|
||||||
|
|
||||||
override fun getTypeParameters(): Array<PsiTypeParameter> = clsDelegate.typeParameters
|
override fun getTypeParameters(): Array<PsiTypeParameter> = clsDelegate.typeParameters
|
||||||
|
override fun isInheritor(baseClass: PsiClass, checkDeep: Boolean): Boolean = clsDelegate.isInheritor(baseClass, checkDeep)
|
||||||
override fun isInheritor(baseClass: PsiClass, checkDeep: Boolean): Boolean =
|
|
||||||
clsDelegate.isInheritor(baseClass, checkDeep)
|
|
||||||
|
|
||||||
override fun processDeclarations(
|
override fun processDeclarations(
|
||||||
processor: PsiScopeProcessor,
|
processor: PsiScopeProcessor,
|
||||||
state: ResolveState,
|
state: ResolveState,
|
||||||
lastParent: PsiElement?,
|
lastParent: PsiElement?,
|
||||||
place: PsiElement
|
place: PsiElement
|
||||||
): Boolean {
|
): Boolean = PsiClassImplUtil.processDeclarationsInClass(
|
||||||
return PsiClassImplUtil.processDeclarationsInClass(
|
/* aClass = */ this,
|
||||||
this, processor, state, null,
|
/* processor = */ processor,
|
||||||
lastParent, place, PsiUtil.getLanguageLevel(place), false
|
/* state = */ state,
|
||||||
)
|
/* visited = */ null,
|
||||||
}
|
/* last = */ lastParent,
|
||||||
|
/* place = */ place,
|
||||||
|
/* languageLevel = */ PsiUtil.getLanguageLevel(place),
|
||||||
|
/* isRaw = */ false,
|
||||||
|
)
|
||||||
|
|
||||||
override fun isEnum(): Boolean = clsDelegate.isEnum
|
override fun isEnum(): Boolean = clsDelegate.isEnum
|
||||||
|
override fun getExtendsListTypes(): Array<PsiClassType> = PsiClassImplUtil.getExtendsListTypes(this)
|
||||||
override fun getExtendsListTypes(): Array<PsiClassType?> =
|
|
||||||
PsiClassImplUtil.getExtendsListTypes(this)
|
|
||||||
|
|
||||||
override fun getTypeParameterList(): PsiTypeParameterList? = clsDelegate.typeParameterList
|
override fun getTypeParameterList(): PsiTypeParameterList? = clsDelegate.typeParameterList
|
||||||
|
|
||||||
override fun isAnnotationType(): Boolean = clsDelegate.isAnnotationType
|
override fun isAnnotationType(): Boolean = clsDelegate.isAnnotationType
|
||||||
|
|
||||||
override fun getNameIdentifier(): PsiIdentifier? = clsDelegate.nameIdentifier
|
override fun getNameIdentifier(): PsiIdentifier? = clsDelegate.nameIdentifier
|
||||||
|
override fun getInterfaces(): Array<PsiClass> = PsiClassImplUtil.getInterfaces(this)
|
||||||
override fun getInterfaces(): Array<PsiClass> =
|
override fun getSuperClass(): PsiClass? = PsiClassImplUtil.getSuperClass(this)
|
||||||
PsiClassImplUtil.getInterfaces(this)
|
override fun getSupers(): Array<PsiClass> = PsiClassImplUtil.getSupers(this)
|
||||||
|
override fun getSuperTypes(): Array<PsiClassType> = PsiClassImplUtil.getSuperTypes(this)
|
||||||
override fun getSuperClass(): PsiClass? =
|
override fun getVisibleSignatures(): Collection<HierarchicalMethodSignature> = PsiSuperMethodImplUtil.getVisibleSignatures(this)
|
||||||
PsiClassImplUtil.getSuperClass(this)
|
|
||||||
|
|
||||||
override fun getSupers(): Array<PsiClass> =
|
|
||||||
PsiClassImplUtil.getSupers(this)
|
|
||||||
|
|
||||||
override fun getSuperTypes(): Array<PsiClassType> =
|
|
||||||
PsiClassImplUtil.getSuperTypes(this)
|
|
||||||
|
|
||||||
override fun getVisibleSignatures(): MutableCollection<HierarchicalMethodSignature> =
|
|
||||||
PsiSuperMethodImplUtil.getVisibleSignatures(this)
|
|
||||||
|
|
||||||
override fun getQualifiedName(): String? = clsDelegate.qualifiedName
|
override fun getQualifiedName(): String? = clsDelegate.qualifiedName
|
||||||
|
override fun getImplementsListTypes(): Array<PsiClassType> = PsiClassImplUtil.getImplementsListTypes(this)
|
||||||
override fun getImplementsListTypes(): Array<PsiClassType?> =
|
|
||||||
PsiClassImplUtil.getImplementsListTypes(this)
|
|
||||||
|
|
||||||
override fun isDeprecated(): Boolean = clsDelegate.isDeprecated
|
override fun isDeprecated(): Boolean = clsDelegate.isDeprecated
|
||||||
|
|
||||||
override fun setName(name: String): PsiElement = clsDelegate.setName(name)
|
override fun setName(name: String): PsiElement = clsDelegate.setName(name)
|
||||||
|
override fun hasTypeParameters(): Boolean = PsiImplUtil.hasTypeParameters(this)
|
||||||
override fun hasTypeParameters(): Boolean =
|
|
||||||
PsiImplUtil.hasTypeParameters(this)
|
|
||||||
|
|
||||||
override fun getExtendsList(): PsiReferenceList? = clsDelegate.extendsList
|
override fun getExtendsList(): PsiReferenceList? = clsDelegate.extendsList
|
||||||
|
|
||||||
override fun getDocComment(): PsiDocComment? = clsDelegate.docComment
|
override fun getDocComment(): PsiDocComment? = clsDelegate.docComment
|
||||||
|
|
||||||
override fun getModifierList(): PsiModifierList? = clsDelegate.modifierList
|
override fun getModifierList(): PsiModifierList? = clsDelegate.modifierList
|
||||||
|
|
||||||
override fun getScope(): PsiElement = clsDelegate.scope
|
override fun getScope(): PsiElement = clsDelegate.scope
|
||||||
|
|
||||||
override fun getAllInnerClasses(): Array<PsiClass> = PsiClassImplUtil.getAllInnerClasses(this)
|
override fun getAllInnerClasses(): Array<PsiClass> = PsiClassImplUtil.getAllInnerClasses(this)
|
||||||
|
|
||||||
override fun getAllMethods(): Array<PsiMethod> = PsiClassImplUtil.getAllMethods(this)
|
override fun getAllMethods(): Array<PsiMethod> = PsiClassImplUtil.getAllMethods(this)
|
||||||
|
|
||||||
override fun getAllFields(): Array<PsiField> = PsiClassImplUtil.getAllFields(this)
|
override fun getAllFields(): Array<PsiField> = PsiClassImplUtil.getAllFields(this)
|
||||||
|
|
||||||
private val _methods: List<PsiMethod> by lazyPub {
|
override fun getOwnMethods(): List<PsiMethod> = _ownMethods
|
||||||
|
private val _ownMethods: List<PsiMethod> by lazyPub {
|
||||||
val isEnum = isEnum
|
val isEnum = isEnum
|
||||||
this.clsDelegate.methods.mapNotNull { psiMethod ->
|
this.clsDelegate.methods.mapNotNull { psiMethod ->
|
||||||
if (isSyntheticValuesOrValueOfMethod(psiMethod)) return@mapNotNull null
|
if (isSyntheticValuesOrValueOfMethod(psiMethod)) return@mapNotNull null
|
||||||
@@ -175,26 +135,28 @@ open class KtLightClassForDecompiledDeclaration(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val _fields: List<PsiField> by lazyPub {
|
override fun getOwnFields(): List<PsiField> = _ownFields
|
||||||
|
private val _ownFields: List<PsiField> by lazyPub {
|
||||||
this.clsDelegate.fields.map { psiField ->
|
this.clsDelegate.fields.map { psiField ->
|
||||||
if (psiField !is PsiEnumConstant) {
|
if (psiField is PsiEnumConstant) {
|
||||||
KtLightFieldForDecompiledDeclaration(
|
|
||||||
fldDelegate = psiField,
|
|
||||||
fldParent = this,
|
|
||||||
lightMemberOrigin = LightMemberOriginForCompiledField(psiField, file)
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
KtLightEnumEntryForDecompiledDeclaration(
|
KtLightEnumEntryForDecompiledDeclaration(
|
||||||
fldDelegate = psiField,
|
fldDelegate = psiField,
|
||||||
fldParent = this,
|
fldParent = this,
|
||||||
lightMemberOrigin = LightMemberOriginForCompiledField(psiField, file),
|
lightMemberOrigin = LightMemberOriginForCompiledField(psiField, file),
|
||||||
file = file
|
file = file,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
KtLightFieldForDecompiledDeclaration(
|
||||||
|
fldDelegate = psiField,
|
||||||
|
fldParent = this,
|
||||||
|
lightMemberOrigin = LightMemberOriginForCompiledField(psiField, file),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val _innerClasses: List<PsiClass> by lazyPub {
|
override fun getOwnInnerClasses(): List<PsiClass> = _ownInnerClasses
|
||||||
|
private val _ownInnerClasses: List<PsiClass> by lazyPub {
|
||||||
this.clsDelegate.innerClasses.map { psiClass ->
|
this.clsDelegate.innerClasses.map { psiClass ->
|
||||||
val innerDeclaration = this.kotlinOrigin
|
val innerDeclaration = this.kotlinOrigin
|
||||||
?.declarations
|
?.declarations
|
||||||
@@ -211,24 +173,18 @@ open class KtLightClassForDecompiledDeclaration(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override val originKind: LightClassOriginKind = LightClassOriginKind.BINARY
|
override val originKind: LightClassOriginKind = LightClassOriginKind.BINARY
|
||||||
|
|
||||||
override fun getNavigationElement() = kotlinOrigin?.navigationElement ?: file
|
override fun getNavigationElement() = kotlinOrigin?.navigationElement ?: file
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
return this === other || other is KtLightClassForDecompiledDeclaration &&
|
return this === other || other is KtLightClassForDecompiledDeclaration &&
|
||||||
qualifiedName == other.qualifiedName &&
|
qualifiedName == other.qualifiedName &&
|
||||||
kotlinOrigin?.fqName == other.kotlinOrigin?.fqName
|
file == other.file
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun hashCode(): Int = qualifiedName?.hashCode() ?: kotlinOrigin?.fqName?.hashCode() ?: 0
|
override fun hashCode(): Int = qualifiedName?.hashCode() ?: kotlinOrigin?.fqName?.hashCode() ?: 0
|
||||||
|
|
||||||
override fun copy(): PsiElement = this
|
override fun copy(): PsiElement = this
|
||||||
|
|
||||||
override fun clone(): Any = this
|
override fun clone(): Any = this
|
||||||
|
|
||||||
override fun toString(): String = "${this.javaClass.simpleName} of $parent"
|
override fun toString(): String = "${this.javaClass.simpleName} of $parent"
|
||||||
|
|
||||||
override fun getName(): String? = clsDelegate.name
|
override fun getName(): String? = clsDelegate.name
|
||||||
|
|
||||||
override fun isValid(): Boolean = file.isValid && clsDelegate.isValid && (kotlinOrigin?.isValid != false)
|
override fun isValid(): Boolean = file.isValid && clsDelegate.isValid && (kotlinOrigin?.isValid != false)
|
||||||
}
|
}
|
||||||
+3
-2
@@ -7,12 +7,13 @@ package org.jetbrains.kotlin.analysis.decompiled.light.classes
|
|||||||
|
|
||||||
import com.intellij.psi.*
|
import com.intellij.psi.*
|
||||||
import org.jetbrains.kotlin.analysis.decompiler.psi.file.KtClsFile
|
import org.jetbrains.kotlin.analysis.decompiler.psi.file.KtClsFile
|
||||||
|
import org.jetbrains.kotlin.asJava.classes.KtLightClass
|
||||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||||
|
|
||||||
internal class KtLightEnumClassForDecompiledDeclaration(
|
internal class KtLightEnumClassForDecompiledDeclaration(
|
||||||
private val psiConstantInitializer: PsiEnumConstantInitializer,
|
private val psiConstantInitializer: PsiEnumConstantInitializer,
|
||||||
private val enumConstant: KtLightEnumEntryForDecompiledDeclaration,
|
private val enumConstant: KtLightEnumEntryForDecompiledDeclaration,
|
||||||
clsParent: KtLightClassForDecompiledDeclaration,
|
clsParent: KtLightClass,
|
||||||
file: KtClsFile,
|
file: KtClsFile,
|
||||||
kotlinOrigin: KtClassOrObject?
|
kotlinOrigin: KtClassOrObject?
|
||||||
) : KtLightClassForDecompiledDeclaration(
|
) : KtLightClassForDecompiledDeclaration(
|
||||||
@@ -31,6 +32,6 @@ internal class KtLightEnumClassForDecompiledDeclaration(
|
|||||||
|
|
||||||
override fun isInQualifiedNew(): Boolean = psiConstantInitializer.isInQualifiedNew
|
override fun isInQualifiedNew(): Boolean = psiConstantInitializer.isInQualifiedNew
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean = other is KtLightEnumClassForDecompiledDeclaration && super.equals(other)
|
override fun equals(other: Any?): Boolean = this === other || other is KtLightEnumClassForDecompiledDeclaration && super.equals(other)
|
||||||
override fun hashCode(): Int = super.hashCode()
|
override fun hashCode(): Int = super.hashCode()
|
||||||
}
|
}
|
||||||
+15
-11
@@ -11,33 +11,37 @@ internal class KtLightEnumEntryForDecompiledDeclaration(
|
|||||||
private val fldDelegate: PsiEnumConstant,
|
private val fldDelegate: PsiEnumConstant,
|
||||||
fldParent: KtLightClassForDecompiledDeclaration,
|
fldParent: KtLightClassForDecompiledDeclaration,
|
||||||
lightMemberOrigin: LightMemberOriginForCompiledField,
|
lightMemberOrigin: LightMemberOriginForCompiledField,
|
||||||
file: KtClsFile,
|
private val file: KtClsFile,
|
||||||
) : KtLightFieldForDecompiledDeclaration(
|
) : KtLightFieldForDecompiledDeclaration(
|
||||||
fldDelegate,
|
fldDelegate,
|
||||||
fldParent,
|
fldParent,
|
||||||
lightMemberOrigin
|
lightMemberOrigin,
|
||||||
), PsiEnumConstant {
|
), PsiEnumConstant {
|
||||||
|
override fun getArgumentList(): PsiExpressionList? = fldDelegate.argumentList
|
||||||
|
override fun resolveConstructor(): PsiMethod? = fldDelegate.resolveConstructor()
|
||||||
|
override fun resolveMethod(): PsiMethod? = fldDelegate.resolveMethod()
|
||||||
|
override fun resolveMethodGenerics(): JavaResolveResult = fldDelegate.resolveMethodGenerics()
|
||||||
|
|
||||||
|
override fun getInitializingClass(): PsiEnumConstantInitializer? = _initializingClass
|
||||||
private val _initializingClass: PsiEnumConstantInitializer? by lazyPub {
|
private val _initializingClass: PsiEnumConstantInitializer? by lazyPub {
|
||||||
fldDelegate.initializingClass?.let {
|
fldDelegate.initializingClass?.let {
|
||||||
KtLightEnumClassForDecompiledDeclaration(
|
KtLightEnumClassForDecompiledDeclaration(
|
||||||
psiConstantInitializer = it,
|
psiConstantInitializer = it,
|
||||||
enumConstant = this,
|
enumConstant = this,
|
||||||
clsParent = fldParent,
|
clsParent = containingClass,
|
||||||
file = file,
|
file = file,
|
||||||
kotlinOrigin = null
|
kotlinOrigin = null,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getArgumentList(): PsiExpressionList? = fldDelegate.argumentList
|
|
||||||
override fun resolveConstructor(): PsiMethod? = fldDelegate.resolveConstructor()
|
|
||||||
override fun resolveMethod(): PsiMethod? = fldDelegate.resolveMethod()
|
|
||||||
override fun resolveMethodGenerics(): JavaResolveResult = fldDelegate.resolveMethodGenerics()
|
|
||||||
override fun getInitializingClass(): PsiEnumConstantInitializer? = _initializingClass
|
|
||||||
override fun getOrCreateInitializingClass(): PsiEnumConstantInitializer =
|
override fun getOrCreateInitializingClass(): PsiEnumConstantInitializer =
|
||||||
_initializingClass ?: error("cannot create initializing class in light enum constant")
|
initializingClass ?: error("cannot create initializing class in light enum constant")
|
||||||
|
|
||||||
|
override fun equals(other: Any?): Boolean = other === this ||
|
||||||
|
other is KtLightEnumEntryForDecompiledDeclaration &&
|
||||||
|
containingClass == other.containingClass &&
|
||||||
|
fldDelegate == other.fldDelegate
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean = other is KtLightEnumEntryForDecompiledDeclaration && super.equals(other)
|
|
||||||
override fun hashCode(): Int = super.hashCode()
|
override fun hashCode(): Int = super.hashCode()
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user