Move light classes for decompiled declarations from IJ repository
This commit is contained in:
@@ -0,0 +1,16 @@
|
|||||||
|
plugins {
|
||||||
|
kotlin("jvm")
|
||||||
|
id("jps-compatible")
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
api(project(":compiler:psi"))
|
||||||
|
api(project(":analysis:decompiled:decompiler-to-psi"))
|
||||||
|
api(project(":compiler:light-classes"))
|
||||||
|
implementation(intellijCore())
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceSets {
|
||||||
|
"main" { projectDefault() }
|
||||||
|
"test" { none() }
|
||||||
|
}
|
||||||
+231
@@ -0,0 +1,231 @@
|
|||||||
|
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.analysis.decompiled.light.classes
|
||||||
|
|
||||||
|
import com.intellij.openapi.util.Pair
|
||||||
|
import com.intellij.psi.*
|
||||||
|
import com.intellij.psi.impl.PsiClassImplUtil
|
||||||
|
import com.intellij.psi.impl.PsiImplUtil
|
||||||
|
import com.intellij.psi.impl.PsiSuperMethodImplUtil
|
||||||
|
import com.intellij.psi.javadoc.PsiDocComment
|
||||||
|
import com.intellij.psi.scope.PsiScopeProcessor
|
||||||
|
import com.intellij.psi.util.PsiUtil
|
||||||
|
import org.jetbrains.annotations.NonNls
|
||||||
|
import org.jetbrains.kotlin.analysis.decompiled.light.classes.origin.LightMemberOriginForCompiledField
|
||||||
|
import org.jetbrains.kotlin.analysis.decompiled.light.classes.origin.LightMemberOriginForCompiledMethod
|
||||||
|
import org.jetbrains.kotlin.analysis.decompiler.psi.file.KtClsFile
|
||||||
|
import org.jetbrains.kotlin.analyzer.KotlinModificationTrackerService
|
||||||
|
import org.jetbrains.kotlin.asJava.classes.KotlinClassInnerStuffCache
|
||||||
|
import org.jetbrains.kotlin.asJava.classes.LightClassesLazyCreator
|
||||||
|
import org.jetbrains.kotlin.asJava.classes.lazyPub
|
||||||
|
import org.jetbrains.kotlin.load.java.structure.LightClassOriginKind
|
||||||
|
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||||
|
|
||||||
|
open class KtLightClassForDecompiledDeclaration(
|
||||||
|
override val clsDelegate: PsiClass,
|
||||||
|
private val clsParent: PsiElement,
|
||||||
|
private val file: KtClsFile,
|
||||||
|
kotlinOrigin: KtClassOrObject?
|
||||||
|
) : KtLightClassForDecompiledDeclarationBase(clsDelegate, clsParent, kotlinOrigin) {
|
||||||
|
|
||||||
|
private val myInnersCache = KotlinClassInnerStuffCache(
|
||||||
|
myClass = this,
|
||||||
|
externalDependencies = listOf(KotlinModificationTrackerService.getInstance(manager.project).outOfBlockModificationTracker),
|
||||||
|
lazyCreator = LightClassesLazyCreator(project)
|
||||||
|
)
|
||||||
|
|
||||||
|
override fun getOwnMethods(): MutableList<PsiMethod> = _methods
|
||||||
|
|
||||||
|
override fun getOwnFields(): MutableList<PsiField> = _fields
|
||||||
|
|
||||||
|
override fun getOwnInnerClasses(): MutableList<PsiClass> = _innerClasses
|
||||||
|
|
||||||
|
override fun getFields() = myInnersCache.fields
|
||||||
|
|
||||||
|
override fun getMethods() = myInnersCache.methods
|
||||||
|
|
||||||
|
override fun getConstructors() = myInnersCache.constructors
|
||||||
|
|
||||||
|
override fun getInnerClasses() = myInnersCache.innerClasses
|
||||||
|
|
||||||
|
override fun findFieldByName(name: String, checkBases: Boolean) = myInnersCache.findFieldByName(name, checkBases)
|
||||||
|
|
||||||
|
override fun findMethodsByName(name: String, checkBases: Boolean) = myInnersCache.findMethodsByName(name, checkBases)
|
||||||
|
|
||||||
|
override fun findInnerClassByName(name: String, checkBases: Boolean) = myInnersCache.findInnerClassByName(name, checkBases)
|
||||||
|
|
||||||
|
override fun hasModifierProperty(name: String): Boolean =
|
||||||
|
clsDelegate.hasModifierProperty(name)
|
||||||
|
|
||||||
|
override fun findMethodBySignature(patternMethod: PsiMethod?, checkBases: Boolean): PsiMethod? =
|
||||||
|
patternMethod?.let { PsiClassImplUtil.findMethodBySignature(this, it, checkBases) }
|
||||||
|
|
||||||
|
override fun findMethodsBySignature(patternMethod: PsiMethod?, checkBases: Boolean): Array<PsiMethod?> =
|
||||||
|
patternMethod?.let { PsiClassImplUtil.findMethodsBySignature(this, it, checkBases) } ?: emptyArray()
|
||||||
|
|
||||||
|
override fun findMethodsAndTheirSubstitutorsByName(@NonNls name: String?, checkBases: Boolean): List<Pair<PsiMethod, PsiSubstitutor>> =
|
||||||
|
PsiClassImplUtil.findMethodsAndTheirSubstitutorsByName(this, name, checkBases)
|
||||||
|
|
||||||
|
override fun getImplementsList(): PsiReferenceList? = clsDelegate.implementsList
|
||||||
|
|
||||||
|
override fun getRBrace(): PsiElement? = null
|
||||||
|
|
||||||
|
override fun getLBrace(): PsiElement? = null
|
||||||
|
|
||||||
|
override fun getInitializers(): Array<PsiClassInitializer> = clsDelegate.initializers
|
||||||
|
|
||||||
|
override fun getContainingClass(): PsiClass? = parent as? PsiClass
|
||||||
|
|
||||||
|
override fun isInheritorDeep(baseClass: PsiClass?, classToByPass: PsiClass?): Boolean = clsDelegate.isInheritorDeep(baseClass, classToByPass)
|
||||||
|
|
||||||
|
override fun getAllMethodsAndTheirSubstitutors(): List<Pair<PsiMethod?, PsiSubstitutor?>?> =
|
||||||
|
PsiClassImplUtil.getAllWithSubstitutorsByMap<PsiMethod>(this, PsiClassImplUtil.MemberType.METHOD)
|
||||||
|
|
||||||
|
override fun isInterface(): Boolean = clsDelegate.isInterface
|
||||||
|
|
||||||
|
override fun getTypeParameters(): Array<PsiTypeParameter> =
|
||||||
|
clsDelegate.typeParameters
|
||||||
|
|
||||||
|
override fun isInheritor(baseClass: PsiClass, checkDeep: Boolean): Boolean =
|
||||||
|
clsDelegate.isInheritor(baseClass, checkDeep)
|
||||||
|
|
||||||
|
override fun processDeclarations(
|
||||||
|
processor: PsiScopeProcessor,
|
||||||
|
state: ResolveState,
|
||||||
|
lastParent: PsiElement?,
|
||||||
|
place: PsiElement
|
||||||
|
): Boolean {
|
||||||
|
if (isEnum) {
|
||||||
|
if (!KotlinClassInnerStuffCache.processDeclarationsInEnum(processor, state, myInnersCache)) return false
|
||||||
|
}
|
||||||
|
return PsiClassImplUtil.processDeclarationsInClass(
|
||||||
|
this, processor, state, null,
|
||||||
|
lastParent, place, PsiUtil.getLanguageLevel(place), false
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isEnum(): Boolean = clsDelegate.isEnum
|
||||||
|
|
||||||
|
override fun getExtendsListTypes(): Array<PsiClassType?> =
|
||||||
|
PsiClassImplUtil.getExtendsListTypes(this)
|
||||||
|
|
||||||
|
override fun getTypeParameterList(): PsiTypeParameterList? = clsDelegate.typeParameterList
|
||||||
|
|
||||||
|
override fun isAnnotationType(): Boolean = clsDelegate.isAnnotationType
|
||||||
|
|
||||||
|
override fun getNameIdentifier(): PsiIdentifier? = clsDelegate.nameIdentifier
|
||||||
|
|
||||||
|
override fun getInterfaces(): Array<PsiClass> =
|
||||||
|
PsiClassImplUtil.getInterfaces(this)
|
||||||
|
|
||||||
|
override fun getSuperClass(): PsiClass? =
|
||||||
|
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 getImplementsListTypes(): Array<PsiClassType?> =
|
||||||
|
PsiClassImplUtil.getImplementsListTypes(this)
|
||||||
|
|
||||||
|
override fun isDeprecated(): Boolean = clsDelegate.isDeprecated
|
||||||
|
|
||||||
|
override fun setName(name: String): PsiElement = clsDelegate.setName(name)
|
||||||
|
|
||||||
|
override fun hasTypeParameters(): Boolean =
|
||||||
|
PsiImplUtil.hasTypeParameters(this)
|
||||||
|
|
||||||
|
override fun getExtendsList(): PsiReferenceList? = clsDelegate.extendsList
|
||||||
|
|
||||||
|
override fun getDocComment(): PsiDocComment? = clsDelegate.docComment
|
||||||
|
|
||||||
|
override fun getModifierList(): PsiModifierList? = clsDelegate.modifierList
|
||||||
|
|
||||||
|
override fun getScope(): PsiElement = clsDelegate.scope
|
||||||
|
|
||||||
|
override fun getAllInnerClasses(): Array<PsiClass> = PsiClassImplUtil.getAllInnerClasses(this)
|
||||||
|
|
||||||
|
override fun getAllMethods(): Array<PsiMethod> = PsiClassImplUtil.getAllMethods(this)
|
||||||
|
|
||||||
|
override fun getAllFields(): Array<PsiField> = PsiClassImplUtil.getAllFields(this)
|
||||||
|
|
||||||
|
private val _methods: MutableList<PsiMethod> by lazyPub {
|
||||||
|
mutableListOf<PsiMethod>().also {
|
||||||
|
clsDelegate.methods.mapTo(it) { psiMethod ->
|
||||||
|
KtLightMethodForDecompiledDeclaration(
|
||||||
|
funDelegate = psiMethod,
|
||||||
|
funParent = this,
|
||||||
|
lightMemberOrigin = LightMemberOriginForCompiledMethod(psiMethod, file)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private val _fields: MutableList<PsiField> by lazyPub {
|
||||||
|
mutableListOf<PsiField>().also {
|
||||||
|
clsDelegate.fields.mapTo(it) { psiField ->
|
||||||
|
if (psiField !is PsiEnumConstant) {
|
||||||
|
KtLightFieldForDecompiledDeclaration(
|
||||||
|
fldDelegate = psiField,
|
||||||
|
fldParent = this,
|
||||||
|
lightMemberOrigin = LightMemberOriginForCompiledField(psiField, file)
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
KtLightEnumEntryForDecompiledDeclaration(
|
||||||
|
fldDelegate = psiField,
|
||||||
|
fldParent = this,
|
||||||
|
lightMemberOrigin = LightMemberOriginForCompiledField(psiField, file),
|
||||||
|
file = file
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private val _innerClasses: MutableList<PsiClass> by lazyPub {
|
||||||
|
mutableListOf<PsiClass>().also {
|
||||||
|
clsDelegate.innerClasses.mapTo(it) { psiClass ->
|
||||||
|
val innerDeclaration = kotlinOrigin
|
||||||
|
?.declarations
|
||||||
|
?.filterIsInstance<KtClassOrObject>()
|
||||||
|
?.firstOrNull { cls -> cls.name == clsDelegate.name }
|
||||||
|
|
||||||
|
KtLightClassForDecompiledDeclaration(
|
||||||
|
clsDelegate = psiClass,
|
||||||
|
clsParent = this,
|
||||||
|
file = file,
|
||||||
|
kotlinOrigin = innerDeclaration,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override val originKind: LightClassOriginKind = LightClassOriginKind.BINARY
|
||||||
|
|
||||||
|
override fun getNavigationElement() = kotlinOrigin?.navigationElement ?: file
|
||||||
|
|
||||||
|
override fun equals(other: Any?): Boolean {
|
||||||
|
return this === other || other is KtLightClassForDecompiledDeclaration &&
|
||||||
|
qualifiedName == other.qualifiedName &&
|
||||||
|
kotlinOrigin?.fqName == other.kotlinOrigin?.fqName
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun hashCode(): Int = qualifiedName?.hashCode() ?: kotlinOrigin?.fqName?.hashCode() ?: 0
|
||||||
|
|
||||||
|
override fun copy(): PsiElement = this
|
||||||
|
|
||||||
|
override fun clone(): Any = this
|
||||||
|
|
||||||
|
override fun toString(): String = "${this.javaClass.simpleName} of $parent"
|
||||||
|
|
||||||
|
override fun getName(): String? = clsDelegate.name
|
||||||
|
|
||||||
|
override fun isValid(): Boolean = file.isValid && clsDelegate.isValid && (kotlinOrigin?.isValid != false)
|
||||||
|
}
|
||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.analysis.decompiled.light.classes
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiClass
|
||||||
|
import com.intellij.psi.PsiElement
|
||||||
|
import com.intellij.psi.impl.source.PsiExtensibleClass
|
||||||
|
import org.jetbrains.kotlin.asJava.classes.KtLightClass
|
||||||
|
import org.jetbrains.kotlin.asJava.elements.KtLightElementBase
|
||||||
|
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||||
|
|
||||||
|
abstract class KtLightClassForDecompiledDeclarationBase(
|
||||||
|
override val clsDelegate: PsiClass,
|
||||||
|
clsParent: PsiElement,
|
||||||
|
final override val kotlinOrigin: KtClassOrObject?
|
||||||
|
) : KtLightElementBase(clsParent), PsiClass, KtLightClass, PsiExtensibleClass
|
||||||
+35
@@ -0,0 +1,35 @@
|
|||||||
|
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.analysis.decompiled.light.classes
|
||||||
|
|
||||||
|
import com.intellij.psi.*
|
||||||
|
import org.jetbrains.kotlin.analysis.decompiler.psi.file.KtClsFile
|
||||||
|
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||||
|
|
||||||
|
internal class KtLightEnumClassForDecompiledDeclaration(
|
||||||
|
private val psiConstantInitializer: PsiEnumConstantInitializer,
|
||||||
|
private val enumConstant: KtLightEnumEntryForDecompiledDeclaration,
|
||||||
|
clsParent: KtLightClassForDecompiledDeclaration,
|
||||||
|
file: KtClsFile,
|
||||||
|
kotlinOrigin: KtClassOrObject?
|
||||||
|
) :
|
||||||
|
KtLightClassForDecompiledDeclaration(
|
||||||
|
clsDelegate = psiConstantInitializer,
|
||||||
|
clsParent = clsParent,
|
||||||
|
file = file,
|
||||||
|
kotlinOrigin = kotlinOrigin
|
||||||
|
), PsiEnumConstantInitializer {
|
||||||
|
|
||||||
|
override fun getBaseClassType(): PsiClassType = psiConstantInitializer.baseClassType
|
||||||
|
|
||||||
|
override fun getArgumentList(): PsiExpressionList? = psiConstantInitializer.argumentList
|
||||||
|
|
||||||
|
override fun getEnumConstant(): PsiEnumConstant = enumConstant
|
||||||
|
|
||||||
|
override fun getBaseClassReference(): PsiJavaCodeReferenceElement = psiConstantInitializer.baseClassReference
|
||||||
|
|
||||||
|
override fun isInQualifiedNew(): Boolean = psiConstantInitializer.isInQualifiedNew
|
||||||
|
|
||||||
|
override fun equals(other: Any?): Boolean = other is KtLightEnumClassForDecompiledDeclaration && super.equals(other)
|
||||||
|
override fun hashCode(): Int = super.hashCode()
|
||||||
|
}
|
||||||
+43
@@ -0,0 +1,43 @@
|
|||||||
|
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.analysis.decompiled.light.classes
|
||||||
|
|
||||||
|
import com.intellij.psi.*
|
||||||
|
import org.jetbrains.kotlin.analysis.decompiled.light.classes.origin.LightMemberOriginForCompiledField
|
||||||
|
import org.jetbrains.kotlin.analysis.decompiler.psi.file.KtClsFile
|
||||||
|
import org.jetbrains.kotlin.asJava.classes.lazyPub
|
||||||
|
|
||||||
|
internal class KtLightEnumEntryForDecompiledDeclaration(
|
||||||
|
private val fldDelegate: PsiEnumConstant,
|
||||||
|
fldParent: KtLightClassForDecompiledDeclaration,
|
||||||
|
lightMemberOrigin: LightMemberOriginForCompiledField,
|
||||||
|
file: KtClsFile,
|
||||||
|
) : KtLightFieldForDecompiledDeclaration(
|
||||||
|
fldDelegate,
|
||||||
|
fldParent,
|
||||||
|
lightMemberOrigin
|
||||||
|
), PsiEnumConstant {
|
||||||
|
|
||||||
|
private val _initializingClass: PsiEnumConstantInitializer? by lazyPub {
|
||||||
|
fldDelegate.initializingClass?.let {
|
||||||
|
KtLightEnumClassForDecompiledDeclaration(
|
||||||
|
psiConstantInitializer = it,
|
||||||
|
enumConstant = this,
|
||||||
|
clsParent = fldParent,
|
||||||
|
file = file,
|
||||||
|
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 =
|
||||||
|
_initializingClass ?: error("cannot create initializing class in light enum constant")
|
||||||
|
|
||||||
|
override fun equals(other: Any?): Boolean = other is KtLightEnumEntryForDecompiledDeclaration && super.equals(other)
|
||||||
|
override fun hashCode(): Int = super.hashCode()
|
||||||
|
}
|
||||||
+73
@@ -0,0 +1,73 @@
|
|||||||
|
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.analysis.decompiled.light.classes
|
||||||
|
|
||||||
|
import com.intellij.psi.*
|
||||||
|
import com.intellij.psi.impl.PsiVariableEx
|
||||||
|
import com.intellij.psi.javadoc.PsiDocComment
|
||||||
|
import org.jetbrains.kotlin.analysis.decompiled.light.classes.origin.LightMemberOriginForCompiledField
|
||||||
|
import org.jetbrains.kotlin.asJava.classes.KtLightClass
|
||||||
|
import org.jetbrains.kotlin.asJava.elements.KtLightElementBase
|
||||||
|
import org.jetbrains.kotlin.asJava.elements.KtLightFieldForSourceDeclarationSupport
|
||||||
|
import org.jetbrains.kotlin.asJava.elements.KtLightMember
|
||||||
|
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||||
|
|
||||||
|
open class KtLightFieldForDecompiledDeclaration(
|
||||||
|
private val fldDelegate: PsiField,
|
||||||
|
private val fldParent: KtLightClass,
|
||||||
|
override val lightMemberOrigin: LightMemberOriginForCompiledField
|
||||||
|
) : KtLightElementBase(fldParent), PsiField, KtLightFieldForSourceDeclarationSupport, KtLightMember<PsiField>, PsiVariableEx {
|
||||||
|
|
||||||
|
override val kotlinOrigin: KtDeclaration? get() = lightMemberOrigin.originalElement
|
||||||
|
|
||||||
|
override fun hasModifierProperty(name: String): Boolean = fldDelegate.hasModifierProperty(name)
|
||||||
|
|
||||||
|
override fun setInitializer(initializer: PsiExpression?) {
|
||||||
|
fldDelegate.initializer = initializer
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getContainingClass(): KtLightClass = fldParent
|
||||||
|
|
||||||
|
override fun normalizeDeclaration() = fldDelegate.normalizeDeclaration()
|
||||||
|
|
||||||
|
override fun getNameIdentifier(): PsiIdentifier = fldDelegate.nameIdentifier
|
||||||
|
|
||||||
|
override fun getName(): String = fldDelegate.name
|
||||||
|
|
||||||
|
override fun getInitializer(): PsiExpression? = fldDelegate.initializer
|
||||||
|
|
||||||
|
override fun getDocComment(): PsiDocComment? = fldDelegate.docComment
|
||||||
|
|
||||||
|
override fun getTypeElement(): PsiTypeElement? = fldDelegate.typeElement
|
||||||
|
|
||||||
|
override fun getModifierList(): PsiModifierList? = fldDelegate.modifierList
|
||||||
|
|
||||||
|
override fun hasInitializer(): Boolean = fldDelegate.hasInitializer()
|
||||||
|
|
||||||
|
override fun getType(): PsiType = fldDelegate.type
|
||||||
|
|
||||||
|
override fun isDeprecated(): Boolean = fldDelegate.isDeprecated
|
||||||
|
|
||||||
|
override fun setName(name: String): PsiElement = fldDelegate.setName(name)
|
||||||
|
|
||||||
|
override fun computeConstantValue(): Any? = fldDelegate.computeConstantValue()
|
||||||
|
|
||||||
|
override fun computeConstantValue(visitedVars: MutableSet<PsiVariable>?): Any? = (fldDelegate as? PsiVariableEx)?.computeConstantValue(visitedVars)
|
||||||
|
|
||||||
|
override fun equals(other: Any?): Boolean = other is KtLightFieldForDecompiledDeclaration &&
|
||||||
|
name == other.name &&
|
||||||
|
fldParent == other.fldParent &&
|
||||||
|
fldDelegate == other.fldDelegate
|
||||||
|
|
||||||
|
override fun hashCode(): Int = name.hashCode()
|
||||||
|
|
||||||
|
override fun copy(): PsiElement = this
|
||||||
|
|
||||||
|
override fun clone(): Any = this
|
||||||
|
|
||||||
|
override fun toString(): String = "${this.javaClass.simpleName} of $fldParent"
|
||||||
|
|
||||||
|
override val clsDelegate: PsiField = fldDelegate
|
||||||
|
|
||||||
|
override fun isValid(): Boolean = parent.isValid
|
||||||
|
}
|
||||||
+109
@@ -0,0 +1,109 @@
|
|||||||
|
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.analysis.decompiled.light.classes
|
||||||
|
|
||||||
|
import com.intellij.psi.*
|
||||||
|
import com.intellij.psi.impl.PsiSuperMethodImplUtil
|
||||||
|
import com.intellij.psi.javadoc.PsiDocComment
|
||||||
|
import com.intellij.psi.util.MethodSignature
|
||||||
|
import com.intellij.psi.util.MethodSignatureBackedByPsiMethod
|
||||||
|
import org.jetbrains.kotlin.analysis.decompiled.light.classes.origin.LightMemberOriginForCompiledMethod
|
||||||
|
import org.jetbrains.kotlin.asJava.classes.KtLightClass
|
||||||
|
import org.jetbrains.kotlin.asJava.elements.KtLightElementBase
|
||||||
|
import org.jetbrains.kotlin.asJava.elements.KtLightMember
|
||||||
|
import org.jetbrains.kotlin.asJava.elements.KtLightMethod
|
||||||
|
import org.jetbrains.kotlin.asJava.propertyNameByAccessor
|
||||||
|
import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper
|
||||||
|
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||||
|
|
||||||
|
class KtLightMethodForDecompiledDeclaration(
|
||||||
|
private val funDelegate: PsiMethod,
|
||||||
|
private val funParent: KtLightClass,
|
||||||
|
override val lightMemberOrigin: LightMemberOriginForCompiledMethod,
|
||||||
|
) : KtLightElementBase(funParent), PsiMethod, KtLightMethod, KtLightMember<PsiMethod> {
|
||||||
|
|
||||||
|
override val kotlinOrigin: KtDeclaration? get() = lightMemberOrigin.originalElement
|
||||||
|
|
||||||
|
override val isMangled: Boolean get() = checkIsMangled()
|
||||||
|
|
||||||
|
override fun hasModifierProperty(name: String): Boolean = funDelegate.hasModifierProperty(name)
|
||||||
|
|
||||||
|
override fun getReturnTypeElement(): PsiTypeElement? = funDelegate.returnTypeElement
|
||||||
|
|
||||||
|
override fun getContainingClass(): KtLightClass = funParent
|
||||||
|
|
||||||
|
override fun getTypeParameters(): Array<PsiTypeParameter> = funDelegate.typeParameters
|
||||||
|
|
||||||
|
override fun getThrowsList(): PsiReferenceList = funDelegate.throwsList
|
||||||
|
|
||||||
|
override fun getReturnType(): PsiType? = funDelegate.returnType
|
||||||
|
|
||||||
|
override fun hasTypeParameters(): Boolean = funDelegate.hasTypeParameters()
|
||||||
|
|
||||||
|
override fun getTypeParameterList(): PsiTypeParameterList? = funDelegate.typeParameterList
|
||||||
|
|
||||||
|
override fun isVarArgs(): Boolean = funDelegate.isVarArgs
|
||||||
|
|
||||||
|
override fun isConstructor(): Boolean = funDelegate.isConstructor
|
||||||
|
|
||||||
|
override fun getNameIdentifier(): PsiIdentifier? = funDelegate.nameIdentifier
|
||||||
|
|
||||||
|
override fun getName(): String = funDelegate.name
|
||||||
|
|
||||||
|
override fun getDocComment(): PsiDocComment? = funDelegate.docComment
|
||||||
|
|
||||||
|
override fun getModifierList(): PsiModifierList = funDelegate.modifierList
|
||||||
|
|
||||||
|
override fun getBody(): PsiCodeBlock? = null
|
||||||
|
|
||||||
|
override fun getDefaultValue(): PsiAnnotationMemberValue? = (funDelegate as? PsiAnnotationMethod)?.defaultValue
|
||||||
|
|
||||||
|
override fun isDeprecated(): Boolean = funDelegate.isDeprecated
|
||||||
|
|
||||||
|
override fun setName(name: String): PsiElement = funDelegate.setName(name)
|
||||||
|
|
||||||
|
override fun getParameterList(): PsiParameterList = funDelegate.parameterList
|
||||||
|
|
||||||
|
override fun getHierarchicalMethodSignature() = PsiSuperMethodImplUtil.getHierarchicalMethodSignature(this)
|
||||||
|
|
||||||
|
override fun findSuperMethodSignaturesIncludingStatic(checkAccess: Boolean): List<MethodSignatureBackedByPsiMethod> =
|
||||||
|
PsiSuperMethodImplUtil.findSuperMethodSignaturesIncludingStatic(this, checkAccess)
|
||||||
|
|
||||||
|
override fun findDeepestSuperMethod() = PsiSuperMethodImplUtil.findDeepestSuperMethod(this)
|
||||||
|
|
||||||
|
override fun findDeepestSuperMethods(): Array<out PsiMethod> = PsiSuperMethodImplUtil.findDeepestSuperMethods(this)
|
||||||
|
|
||||||
|
override fun findSuperMethods(): Array<out PsiMethod> = PsiSuperMethodImplUtil.findSuperMethods(this)
|
||||||
|
|
||||||
|
override fun findSuperMethods(checkAccess: Boolean): Array<out PsiMethod> =
|
||||||
|
PsiSuperMethodImplUtil.findSuperMethods(this, checkAccess)
|
||||||
|
|
||||||
|
override fun findSuperMethods(parentClass: PsiClass?): Array<out PsiMethod> =
|
||||||
|
PsiSuperMethodImplUtil.findSuperMethods(this, parentClass)
|
||||||
|
|
||||||
|
override fun getSignature(substitutor: PsiSubstitutor): MethodSignature =
|
||||||
|
MethodSignatureBackedByPsiMethod.create(this, substitutor)
|
||||||
|
|
||||||
|
override fun equals(other: Any?): Boolean = other is KtLightMethodForDecompiledDeclaration &&
|
||||||
|
name == other.name &&
|
||||||
|
funParent == other.funParent &&
|
||||||
|
funDelegate == other.funDelegate
|
||||||
|
|
||||||
|
override fun hashCode(): Int = name.hashCode()
|
||||||
|
|
||||||
|
override fun copy(): PsiElement = this
|
||||||
|
|
||||||
|
override fun clone(): Any = this
|
||||||
|
|
||||||
|
override fun toString(): String = "${this.javaClass.simpleName} of $funParent"
|
||||||
|
|
||||||
|
override val clsDelegate: PsiMethod = funDelegate
|
||||||
|
|
||||||
|
override fun isValid(): Boolean = parent.isValid
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun KtLightMethod.checkIsMangled(): Boolean {
|
||||||
|
val demangledName = KotlinTypeMapper.InternalNameMapper.demangleInternalName(name) ?: return false
|
||||||
|
val originalName = propertyNameByAccessor(demangledName, this) ?: demangledName
|
||||||
|
return originalName == kotlinOrigin?.name
|
||||||
|
}
|
||||||
+75
@@ -0,0 +1,75 @@
|
|||||||
|
package org.jetbrains.kotlin.analysis.decompiled.light.classes.origin
|
||||||
|
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiElement
|
||||||
|
import com.intellij.psi.PsiField
|
||||||
|
import com.intellij.psi.PsiMember
|
||||||
|
import com.intellij.psi.PsiMethod
|
||||||
|
import org.jetbrains.kotlin.analysis.decompiler.psi.file.KtClsFile
|
||||||
|
import org.jetbrains.kotlin.asJava.builder.LightMemberOrigin
|
||||||
|
import org.jetbrains.kotlin.asJava.classes.lazyPub
|
||||||
|
import org.jetbrains.kotlin.load.kotlin.MemberSignature
|
||||||
|
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||||
|
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOriginKind
|
||||||
|
import org.jetbrains.kotlin.type.MapPsiToAsmDesc
|
||||||
|
|
||||||
|
interface LightMemberOriginForCompiledElement<T : PsiMember> : LightMemberOrigin {
|
||||||
|
val member: T
|
||||||
|
|
||||||
|
override val originKind: JvmDeclarationOriginKind
|
||||||
|
get() = JvmDeclarationOriginKind.OTHER
|
||||||
|
|
||||||
|
override fun isEquivalentTo(other: PsiElement?): Boolean {
|
||||||
|
return when (other) {
|
||||||
|
is KtDeclaration -> originalElement?.isEquivalentTo(other) ?: false
|
||||||
|
is PsiMember -> member.isEquivalentTo(other)
|
||||||
|
else -> false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isValid(): Boolean = member.isValid
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
data class LightMemberOriginForCompiledField(val psiField: PsiField, val file: KtClsFile) : LightMemberOriginForCompiledElement<PsiField> {
|
||||||
|
override val member: PsiField
|
||||||
|
get() = psiField
|
||||||
|
|
||||||
|
override fun copy(): LightMemberOrigin {
|
||||||
|
return LightMemberOriginForCompiledField(psiField.copy() as PsiField, file)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isEquivalentTo(other: LightMemberOrigin?): Boolean {
|
||||||
|
if (other !is LightMemberOriginForCompiledField) return false
|
||||||
|
return psiField.isEquivalentTo(other.psiField)
|
||||||
|
}
|
||||||
|
|
||||||
|
override val originalElement: KtDeclaration? by lazyPub {
|
||||||
|
val desc = MapPsiToAsmDesc.typeDesc(psiField.type)
|
||||||
|
val signature = MemberSignature.fromFieldNameAndDesc(psiField.name, desc)
|
||||||
|
findDeclarationInCompiledFile(file, psiField, signature)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data class LightMemberOriginForCompiledMethod(val psiMethod: PsiMethod, val file: KtClsFile) :
|
||||||
|
LightMemberOriginForCompiledElement<PsiMethod> {
|
||||||
|
|
||||||
|
override val member: PsiMethod
|
||||||
|
get() = psiMethod
|
||||||
|
|
||||||
|
override fun isEquivalentTo(other: LightMemberOrigin?): Boolean {
|
||||||
|
if (other !is LightMemberOriginForCompiledMethod) return false
|
||||||
|
return psiMethod.isEquivalentTo(other.psiMethod)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun copy(): LightMemberOrigin {
|
||||||
|
return LightMemberOriginForCompiledMethod(psiMethod.copy() as PsiMethod, file)
|
||||||
|
}
|
||||||
|
|
||||||
|
override val originalElement: KtDeclaration? by lazyPub {
|
||||||
|
val desc = MapPsiToAsmDesc.methodDesc(psiMethod)
|
||||||
|
val name = if (psiMethod.isConstructor) "<init>" else psiMethod.name
|
||||||
|
val signature = MemberSignature.fromMethodNameAndDesc(name, desc)
|
||||||
|
findDeclarationInCompiledFile(file, psiMethod, signature)
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
-1
@@ -499,7 +499,8 @@ include ":generators:analysis-api-generator",
|
|||||||
":analysis:symbol-light-classes",
|
":analysis:symbol-light-classes",
|
||||||
":analysis:project-structure",
|
":analysis:project-structure",
|
||||||
":analysis:analysis-api-fe10",
|
":analysis:analysis-api-fe10",
|
||||||
":analysis:decompiled:decompiler-to-psi"
|
":analysis:decompiled:decompiler-to-psi",
|
||||||
|
":analysis:decompiled:light-classes-for-decompiled"
|
||||||
|
|
||||||
|
|
||||||
if (buildProperties.inJpsBuildIdeaSync) {
|
if (buildProperties.inJpsBuildIdeaSync) {
|
||||||
|
|||||||
Reference in New Issue
Block a user