[Analysis API decompiler] materialize delegate declarations in stubs
We should materialize delegated declarations to process callables in scopes correctly. Standalone mode works the same way as it deserialize directly into FIR. Another solution is to rework proto and stub serializer/deserializer to restore FirFields like `$$delegate_0` correctly to work with `FirDelegatedMemberScope` ^KT-62896 Fixed ^KT-64584 Fixed
This commit is contained in:
committed by
Space Team
parent
06950f57db
commit
d88249bda7
+55
@@ -0,0 +1,55 @@
|
||||
PsiJetFileStubImpl[package=]
|
||||
PACKAGE_DIRECTIVE
|
||||
IMPORT_LIST
|
||||
CLASS[classId=/Delegation, fqName=Delegation, isEnumEntry=false, isInterface=false, isLocal=false, isTopLevel=true, name=Delegation, superNames=[T]]
|
||||
MODIFIER_LIST[public final]
|
||||
PRIMARY_CONSTRUCTOR[fqName=null, hasBody=false, isDelegatedCallToThis=false, isExtension=false, isTopLevel=false, name=Delegation]
|
||||
MODIFIER_LIST[public]
|
||||
VALUE_PARAMETER_LIST
|
||||
VALUE_PARAMETER[fqName=null, hasDefaultValue=true, hasValOrVar=false, isMutable=false, name=c]
|
||||
TYPE_REFERENCE
|
||||
USER_TYPE
|
||||
USER_TYPE
|
||||
REFERENCE_EXPRESSION[referencedName=kotlin]
|
||||
REFERENCE_EXPRESSION[referencedName=Int]
|
||||
REFERENCE_EXPRESSION[referencedName=COMPILED_CODE]
|
||||
VALUE_PARAMETER[fqName=null, hasDefaultValue=false, hasValOrVar=false, isMutable=false, name=a]
|
||||
TYPE_REFERENCE
|
||||
USER_TYPE
|
||||
REFERENCE_EXPRESSION[referencedName=A]
|
||||
SUPER_TYPE_LIST
|
||||
SUPER_TYPE_ENTRY
|
||||
TYPE_REFERENCE
|
||||
USER_TYPE
|
||||
REFERENCE_EXPRESSION[referencedName=T]
|
||||
CLASS_BODY
|
||||
PROPERTY[fqName=Delegation.c, hasDelegate=false, hasDelegateExpression=false, hasInitializer=false, hasReturnTypeRef=true, isExtension=false, isTopLevel=false, isVar=false, name=c]
|
||||
MODIFIER_LIST[public final]
|
||||
TYPE_REFERENCE
|
||||
USER_TYPE
|
||||
USER_TYPE
|
||||
REFERENCE_EXPRESSION[referencedName=kotlin]
|
||||
REFERENCE_EXPRESSION[referencedName=Int]
|
||||
PROPERTY[fqName=Delegation.g, hasDelegate=false, hasDelegateExpression=false, hasInitializer=false, hasReturnTypeRef=true, isExtension=false, isTopLevel=false, isVar=false, name=g]
|
||||
MODIFIER_LIST[open public]
|
||||
TYPE_REFERENCE
|
||||
USER_TYPE
|
||||
USER_TYPE
|
||||
REFERENCE_EXPRESSION[referencedName=kotlin]
|
||||
REFERENCE_EXPRESSION[referencedName=Int]
|
||||
FUN[fqName=Delegation.ff, hasBlockBody=true, hasBody=true, hasTypeParameterListBeforeFunctionName=false, isExtension=false, isTopLevel=false, mayHaveContract=false, name=ff]
|
||||
MODIFIER_LIST[public final]
|
||||
VALUE_PARAMETER_LIST
|
||||
TYPE_REFERENCE
|
||||
USER_TYPE
|
||||
USER_TYPE
|
||||
REFERENCE_EXPRESSION[referencedName=kotlin]
|
||||
REFERENCE_EXPRESSION[referencedName=Int]
|
||||
FUN[fqName=Delegation.f, hasBlockBody=true, hasBody=true, hasTypeParameterListBeforeFunctionName=false, isExtension=false, isTopLevel=false, mayHaveContract=false, name=f]
|
||||
MODIFIER_LIST[open public]
|
||||
VALUE_PARAMETER_LIST
|
||||
TYPE_REFERENCE
|
||||
USER_TYPE
|
||||
USER_TYPE
|
||||
REFERENCE_EXPRESSION[referencedName=kotlin]
|
||||
REFERENCE_EXPRESSION[referencedName=Unit]
|
||||
Vendored
-1
@@ -1,4 +1,3 @@
|
||||
// FIR_IDENTICAL
|
||||
interface T {
|
||||
fun f()
|
||||
val g: Int
|
||||
|
||||
Vendored
+15
@@ -30,6 +30,21 @@ PsiJetFileStubImpl[package=]
|
||||
USER_TYPE
|
||||
REFERENCE_EXPRESSION[referencedName=kotlin]
|
||||
REFERENCE_EXPRESSION[referencedName=Int]
|
||||
PROPERTY[fqName=Delegation.g, hasDelegate=false, hasDelegateExpression=false, hasInitializer=false, hasReturnTypeRef=true, isExtension=false, isTopLevel=false, isVar=false, name=g]
|
||||
MODIFIER_LIST[open public]
|
||||
TYPE_REFERENCE
|
||||
USER_TYPE
|
||||
USER_TYPE
|
||||
REFERENCE_EXPRESSION[referencedName=kotlin]
|
||||
REFERENCE_EXPRESSION[referencedName=Int]
|
||||
FUN[fqName=Delegation.f, hasBlockBody=true, hasBody=true, hasTypeParameterListBeforeFunctionName=false, isExtension=false, isTopLevel=false, mayHaveContract=false, name=f]
|
||||
MODIFIER_LIST[open public]
|
||||
VALUE_PARAMETER_LIST
|
||||
TYPE_REFERENCE
|
||||
USER_TYPE
|
||||
USER_TYPE
|
||||
REFERENCE_EXPRESSION[referencedName=kotlin]
|
||||
REFERENCE_EXPRESSION[referencedName=Unit]
|
||||
FUN[fqName=Delegation.ff, hasBlockBody=true, hasBody=true, hasTypeParameterListBeforeFunctionName=false, isExtension=false, isTopLevel=false, mayHaveContract=false, name=ff]
|
||||
MODIFIER_LIST[public final]
|
||||
VALUE_PARAMETER_LIST
|
||||
|
||||
+3
-8
@@ -1,11 +1,10 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.analysis.decompiler.psi.text
|
||||
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import org.jetbrains.kotlin.analysis.decompiler.stub.COMPILED_DEFAULT_INITIALIZER
|
||||
import org.jetbrains.kotlin.analysis.decompiler.stub.COMPILED_DEFAULT_PARAMETER_VALUE
|
||||
import org.jetbrains.kotlin.builtins.StandardNames
|
||||
@@ -20,7 +19,6 @@ import org.jetbrains.kotlin.renderer.DescriptorRendererOptions
|
||||
import org.jetbrains.kotlin.renderer.render
|
||||
import org.jetbrains.kotlin.resolve.DataClassDescriptorResolver
|
||||
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
|
||||
@@ -46,11 +44,8 @@ fun DescriptorRendererOptions.defaultDecompilerRendererOptions() {
|
||||
|
||||
internal fun CallableMemberDescriptor.mustNotBeWrittenToDecompiledText(): Boolean {
|
||||
return when (kind) {
|
||||
CallableMemberDescriptor.Kind.DECLARATION -> false
|
||||
|
||||
CallableMemberDescriptor.Kind.FAKE_OVERRIDE,
|
||||
CallableMemberDescriptor.Kind.DELEGATION -> true
|
||||
|
||||
CallableMemberDescriptor.Kind.DECLARATION, CallableMemberDescriptor.Kind.DELEGATION -> false
|
||||
CallableMemberDescriptor.Kind.FAKE_OVERRIDE -> true
|
||||
CallableMemberDescriptor.Kind.SYNTHESIZED -> {
|
||||
// Of all synthesized functions, only `component*` functions are rendered (for historical reasons)
|
||||
!DataClassDescriptorResolver.isComponentLike(name) && name !in listOf(
|
||||
|
||||
+7
-4
@@ -1,4 +1,7 @@
|
||||
// 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.
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.analysis.decompiler.stub
|
||||
|
||||
@@ -6,8 +9,8 @@ import com.intellij.psi.PsiElement
|
||||
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.constant.ConstantValue
|
||||
import org.jetbrains.kotlin.descriptors.SourceElement
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
|
||||
import org.jetbrains.kotlin.load.kotlin.*
|
||||
@@ -28,9 +31,9 @@ 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
|
||||
|
||||
const val COMPILED_DEFAULT_INITIALIZER = "COMPILED_CODE"
|
||||
|
||||
@@ -85,7 +88,7 @@ fun createConstructorStub(
|
||||
|
||||
private fun shouldSkip(flags: Int, name: Name): Boolean {
|
||||
return when (Flags.MEMBER_KIND.get(flags)) {
|
||||
MemberKind.FAKE_OVERRIDE, MemberKind.DELEGATION -> true
|
||||
MemberKind.FAKE_OVERRIDE -> true
|
||||
//TODO: fix decompiler to use sane criteria
|
||||
MemberKind.SYNTHESIZED -> !DataClassResolver.isComponentLike(name) && name !in listOf(
|
||||
OperatorNameConventions.EQUALS,
|
||||
|
||||
Reference in New Issue
Block a user