From 96c15f6c71681b9a1e44d52956d02b649e534bb7 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Tue, 18 Apr 2023 10:40:13 +0200 Subject: [PATCH] [cls] include generated equals/hashCode/toString method in stubs to avoid heavy computation of super functions --- .../DataClass/DataClass.txt | 31 +++++++++++++++++++ .../Modifiers/Modifiers.txt | 16 ++++++++++ .../psi/text/buildDecompiledText.kt | 7 ++++- .../decompiler/stub/CallableClsStubBuilder.kt | 9 +++++- 4 files changed, 61 insertions(+), 2 deletions(-) diff --git a/analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/DataClass/DataClass.txt b/analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/DataClass/DataClass.txt index 4eef53618e8..3333d84ce64 100644 --- a/analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/DataClass/DataClass.txt +++ b/analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/DataClass/DataClass.txt @@ -54,6 +54,21 @@ PsiJetFileStubImpl[package=a.b.c] USER_TYPE REFERENCE_EXPRESSION[referencedName=kotlin] REFERENCE_EXPRESSION[referencedName=String] + FUN[fqName=a.b.c.DataClass.equals, hasBlockBody=true, hasBody=true, hasTypeParameterListBeforeFunctionName=false, isExtension=false, isTopLevel=false, mayHaveContract=false, name=equals] + MODIFIER_LIST[open public operator] + VALUE_PARAMETER_LIST + VALUE_PARAMETER[fqName=null, hasDefaultValue=false, hasValOrVar=false, isMutable=false, name=other] + TYPE_REFERENCE + NULLABLE_TYPE + USER_TYPE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=kotlin] + REFERENCE_EXPRESSION[referencedName=Any] + TYPE_REFERENCE + USER_TYPE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=kotlin] + REFERENCE_EXPRESSION[referencedName=Boolean] FUN[fqName=a.b.c.DataClass.f, hasBlockBody=true, hasBody=true, hasTypeParameterListBeforeFunctionName=false, isExtension=false, isTopLevel=false, mayHaveContract=false, name=f] MODIFIER_LIST[public final] VALUE_PARAMETER_LIST @@ -62,3 +77,19 @@ PsiJetFileStubImpl[package=a.b.c] USER_TYPE REFERENCE_EXPRESSION[referencedName=kotlin] REFERENCE_EXPRESSION[referencedName=Int] + FUN[fqName=a.b.c.DataClass.hashCode, hasBlockBody=true, hasBody=true, hasTypeParameterListBeforeFunctionName=false, isExtension=false, isTopLevel=false, mayHaveContract=false, name=hashCode] + MODIFIER_LIST[open public] + VALUE_PARAMETER_LIST + TYPE_REFERENCE + USER_TYPE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=kotlin] + REFERENCE_EXPRESSION[referencedName=Int] + FUN[fqName=a.b.c.DataClass.toString, hasBlockBody=true, hasBody=true, hasTypeParameterListBeforeFunctionName=false, isExtension=false, isTopLevel=false, mayHaveContract=false, name=toString] + MODIFIER_LIST[open public] + VALUE_PARAMETER_LIST + TYPE_REFERENCE + USER_TYPE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=kotlin] + REFERENCE_EXPRESSION[referencedName=String] diff --git a/analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/Modifiers/Modifiers.txt b/analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/Modifiers/Modifiers.txt index 5e54c7d2179..a6dfc0bb241 100644 --- a/analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/Modifiers/Modifiers.txt +++ b/analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/Modifiers/Modifiers.txt @@ -94,6 +94,14 @@ PsiJetFileStubImpl[package=test] USER_TYPE REFERENCE_EXPRESSION[referencedName=kotlin] REFERENCE_EXPRESSION[referencedName=Unit] + FUN[fqName=test.Modifiers.hashCode, hasBlockBody=true, hasBody=true, hasTypeParameterListBeforeFunctionName=false, isExtension=false, isTopLevel=false, mayHaveContract=false, name=hashCode] + MODIFIER_LIST[open public] + VALUE_PARAMETER_LIST + TYPE_REFERENCE + USER_TYPE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=kotlin] + REFERENCE_EXPRESSION[referencedName=Int] FUN[fqName=test.Modifiers.inlined, hasBlockBody=true, hasBody=true, hasTypeParameterListBeforeFunctionName=false, isExtension=false, isTopLevel=false, mayHaveContract=false, name=inlined] MODIFIER_LIST[public final inline] VALUE_PARAMETER_LIST @@ -165,6 +173,14 @@ PsiJetFileStubImpl[package=test] USER_TYPE REFERENCE_EXPRESSION[referencedName=kotlin] REFERENCE_EXPRESSION[referencedName=Unit] + FUN[fqName=test.Modifiers.toString, hasBlockBody=true, hasBody=true, hasTypeParameterListBeforeFunctionName=false, isExtension=false, isTopLevel=false, mayHaveContract=false, name=toString] + MODIFIER_LIST[open public] + VALUE_PARAMETER_LIST + TYPE_REFERENCE + USER_TYPE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=kotlin] + REFERENCE_EXPRESSION[referencedName=String] CLASS[classId=test/Modifiers.Ann, fqName=test.Modifiers.Ann, isEnumEntry=false, isInterface=false, isLocal=false, isTopLevel=false, name=Ann, superNames=[Annotation]] MODIFIER_LIST[public final annotation] PRIMARY_CONSTRUCTOR[fqName=null, hasBody=false, isDelegatedCallToThis=false, isExtension=false, isTopLevel=false, name=Ann] diff --git a/analysis/decompiled/decompiler-to-psi/src/org/jetbrains/kotlin/analysis/decompiler/psi/text/buildDecompiledText.kt b/analysis/decompiled/decompiler-to-psi/src/org/jetbrains/kotlin/analysis/decompiler/psi/text/buildDecompiledText.kt index 179c2335567..d4801817298 100644 --- a/analysis/decompiled/decompiler-to-psi/src/org/jetbrains/kotlin/analysis/decompiler/psi/text/buildDecompiledText.kt +++ b/analysis/decompiled/decompiler-to-psi/src/org/jetbrains/kotlin/analysis/decompiler/psi/text/buildDecompiledText.kt @@ -23,6 +23,7 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils.isEnumEntry import org.jetbrains.kotlin.resolve.constants.* import org.jetbrains.kotlin.resolve.descriptorUtil.secondaryConstructors import org.jetbrains.kotlin.types.isFlexible +import org.jetbrains.kotlin.util.OperatorNameConventions import org.jetbrains.kotlin.util.capitalizeDecapitalize.toLowerCaseAsciiOnly private const val DECOMPILED_CODE_COMMENT = "/* compiled code */" @@ -52,7 +53,11 @@ internal fun CallableMemberDescriptor.mustNotBeWrittenToDecompiledText(): Boolea CallableMemberDescriptor.Kind.SYNTHESIZED -> { // Of all synthesized functions, only `component*` functions are rendered (for historical reasons) - !DataClassDescriptorResolver.isComponentLike(name) + !DataClassDescriptorResolver.isComponentLike(name) && name !in listOf( + OperatorNameConventions.EQUALS, + StandardNames.HASHCODE_NAME, + OperatorNameConventions.TO_STRING + ) } } } diff --git a/analysis/decompiled/decompiler-to-stubs/src/org/jetbrains/kotlin/analysis/decompiler/stub/CallableClsStubBuilder.kt b/analysis/decompiled/decompiler-to-stubs/src/org/jetbrains/kotlin/analysis/decompiler/stub/CallableClsStubBuilder.kt index ebbea60075c..8865c9dec55 100644 --- a/analysis/decompiled/decompiler-to-stubs/src/org/jetbrains/kotlin/analysis/decompiler/stub/CallableClsStubBuilder.kt +++ b/analysis/decompiled/decompiler-to-stubs/src/org/jetbrains/kotlin/analysis/decompiler/stub/CallableClsStubBuilder.kt @@ -7,6 +7,7 @@ import com.intellij.psi.stubs.StubElement import com.intellij.util.io.StringRef import org.jetbrains.kotlin.analysis.decompiler.stub.flags.* import org.jetbrains.kotlin.constant.ConstantValue +import org.jetbrains.kotlin.builtins.StandardNames import org.jetbrains.kotlin.descriptors.SourceElement import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget import org.jetbrains.kotlin.load.kotlin.* @@ -27,6 +28,8 @@ import org.jetbrains.kotlin.resolve.constants.ClassLiteralValue import org.jetbrains.kotlin.serialization.deserialization.AnnotatedCallableKind import org.jetbrains.kotlin.serialization.deserialization.ProtoContainer import org.jetbrains.kotlin.serialization.deserialization.getName +import org.jetbrains.kotlin.utils.addToStdlib.runIf +import org.jetbrains.kotlin.util.OperatorNameConventions import org.jetbrains.kotlin.utils.addIfNotNull import org.jetbrains.kotlin.utils.addToStdlib.runIf @@ -85,7 +88,11 @@ private fun shouldSkip(flags: Int, name: Name): Boolean { return when (Flags.MEMBER_KIND.get(flags)) { MemberKind.FAKE_OVERRIDE, MemberKind.DELEGATION -> true //TODO: fix decompiler to use sane criteria - MemberKind.SYNTHESIZED -> !DataClassResolver.isComponentLike(name) + MemberKind.SYNTHESIZED -> !DataClassResolver.isComponentLike(name) && name !in listOf( + OperatorNameConventions.EQUALS, + StandardNames.HASHCODE_NAME, + OperatorNameConventions.TO_STRING + ) else -> false } }