From d88249bda72e77cce7e51c0e43d334f5ad2f6bb5 Mon Sep 17 00:00:00 2001 From: Dmitrii Gridin Date: Wed, 27 Dec 2023 19:55:40 +0100 Subject: [PATCH] [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 --- ...ationToLibraryInterface.standalone.fir.txt | 1 - .../delegationToLibraryInterface.txt | 3 - .../delegateInterfaceLibrary.pretty.txt | 14 +- .../delegateInterfaceLibrary.txt | 654 ++++++++++++++++++ .../Delegation/Delegation.k2.txt | 55 ++ .../Delegation/Delegation.kt | 1 - .../Delegation/Delegation.txt | 15 + .../psi/text/buildDecompiledText.kt | 11 +- .../decompiler/stub/CallableClsStubBuilder.kt | 11 +- .../testData/getOrBuildFirBinary/delegate.txt | 30 + .../kotlin/psi/stubs/KotlinStubVersions.kt | 2 +- 11 files changed, 778 insertions(+), 19 deletions(-) delete mode 100644 analysis/analysis-api/testData/components/diagnosticsProvider/diagnostics/delegationToLibraryInterface.standalone.fir.txt create mode 100644 analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/Delegation/Delegation.k2.txt diff --git a/analysis/analysis-api/testData/components/diagnosticsProvider/diagnostics/delegationToLibraryInterface.standalone.fir.txt b/analysis/analysis-api/testData/components/diagnosticsProvider/diagnostics/delegationToLibraryInterface.standalone.fir.txt deleted file mode 100644 index 9f370a89565..00000000000 --- a/analysis/analysis-api/testData/components/diagnosticsProvider/diagnostics/delegationToLibraryInterface.standalone.fir.txt +++ /dev/null @@ -1 +0,0 @@ -Diagnostics from elements: diff --git a/analysis/analysis-api/testData/components/diagnosticsProvider/diagnostics/delegationToLibraryInterface.txt b/analysis/analysis-api/testData/components/diagnosticsProvider/diagnostics/delegationToLibraryInterface.txt index db56c4b933d..9f370a89565 100644 --- a/analysis/analysis-api/testData/components/diagnosticsProvider/diagnostics/delegationToLibraryInterface.txt +++ b/analysis/analysis-api/testData/components/diagnosticsProvider/diagnostics/delegationToLibraryInterface.txt @@ -1,4 +1 @@ Diagnostics from elements: - for PSI element of type KtClass at (13,1) - (15,96) - ABSTRACT_MEMBER_NOT_IMPLEMENTED text ranges: [(51,71)] - PSI: KtClass at (13,1) - (15,96) diff --git a/analysis/analysis-api/testData/components/scopeProvider/declaredMemberScope/delegateInterfaceLibrary.pretty.txt b/analysis/analysis-api/testData/components/scopeProvider/declaredMemberScope/delegateInterfaceLibrary.pretty.txt index b0771732344..1aaf3666f5e 100644 --- a/analysis/analysis-api/testData/components/scopeProvider/declaredMemberScope/delegateInterfaceLibrary.pretty.txt +++ b/analysis/analysis-api/testData/components/scopeProvider/declaredMemberScope/delegateInterfaceLibrary.pretty.txt @@ -1,3 +1,15 @@ private val p: A -constructor(p: A) +open var bar: kotlin.Long + +open val kotlin.Int.doo: kotlin.String + +open fun foo() + +open val foo: kotlin.Int + +open var kotlin.Int.zoo: kotlin.Unit + +open fun kotlin.Int.smth(): kotlin.Short + +constructor(p: A) \ No newline at end of file diff --git a/analysis/analysis-api/testData/components/scopeProvider/declaredMemberScope/delegateInterfaceLibrary.txt b/analysis/analysis-api/testData/components/scopeProvider/declaredMemberScope/delegateInterfaceLibrary.txt index 2eb42107769..1b8f506bb18 100644 --- a/analysis/analysis-api/testData/components/scopeProvider/declaredMemberScope/delegateInterfaceLibrary.txt +++ b/analysis/analysis-api/testData/components/scopeProvider/declaredMemberScope/delegateInterfaceLibrary.txt @@ -89,6 +89,660 @@ KtKotlinPropertySymbol: javaSetterName: null setterDeprecationStatus: null +KtKotlinPropertySymbol: + annotationsList: [] + backingFieldSymbol: KtBackingFieldSymbol: + annotationsList: [] + callableIdIfNonLocal: null + contextReceivers: [] + isExtension: false + name: field + origin: PROPERTY_BACKING_FIELD + owningProperty: KtKotlinPropertySymbol(/I.bar) + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Long + symbolKind: LOCAL + typeParameters: [] + getContainingFileSymbol: KtFileSymbol(I.class) + getContainingJvmClassName: I + getContainingModule: KtLibraryModule "Library main" + deprecationStatus: null + callableIdIfNonLocal: /I.bar + contextReceivers: [] + getter: KtPropertyGetterSymbol: + annotationsList: [] + callableIdIfNonLocal: null + contextReceivers: [] + hasBody: false + hasStableParameterNames: true + isDefault: true + isExtension: false + isInline: false + isOverride: false + modality: FINAL + origin: SOURCE + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Long + symbolKind: ACCESSOR + typeParameters: [] + valueParameters: [] + visibility: Public + getDispatchReceiver(): KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: I + getContainingFileSymbol: KtFileSymbol(I.class) + getContainingJvmClassName: I + getContainingModule: KtLibraryModule "Library main" + deprecationStatus: null + hasBackingField: true + hasGetter: true + hasSetter: true + initializer: null + isActual: false + isConst: false + isDelegatedProperty: false + isExpect: false + isExtension: false + isFromPrimaryConstructor: false + isLateInit: false + isOverride: false + isStatic: false + isVal: false + modality: OPEN + name: bar + origin: SOURCE + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Long + setter: KtPropertySetterSymbol: + annotationsList: [] + callableIdIfNonLocal: null + contextReceivers: [] + hasBody: false + hasStableParameterNames: true + isDefault: true + isExtension: false + isInline: false + isOverride: false + modality: FINAL + origin: SOURCE + parameter: KtValueParameterSymbol: + annotationsList: [] + callableIdIfNonLocal: null + contextReceivers: [] + generatedPrimaryConstructorProperty: null + hasDefaultValue: false + isCrossinline: false + isExtension: false + isImplicitLambdaParameter: false + isNoinline: false + isVararg: false + name: value + origin: SOURCE + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Long + symbolKind: LOCAL + typeParameters: [] + getContainingFileSymbol: KtFileSymbol(I.class) + getContainingJvmClassName: null + getContainingModule: KtLibraryModule "Library main" + deprecationStatus: null + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Unit + symbolKind: ACCESSOR + typeParameters: [] + valueParameters: [ + KtValueParameterSymbol: + annotationsList: [] + callableIdIfNonLocal: null + contextReceivers: [] + generatedPrimaryConstructorProperty: null + hasDefaultValue: false + isCrossinline: false + isExtension: false + isImplicitLambdaParameter: false + isNoinline: false + isVararg: false + name: value + origin: SOURCE + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Long + symbolKind: LOCAL + typeParameters: [] + getContainingFileSymbol: KtFileSymbol(I.class) + getContainingJvmClassName: null + getContainingModule: KtLibraryModule "Library main" + deprecationStatus: null + ] + visibility: Public + getDispatchReceiver(): KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: I + getContainingFileSymbol: KtFileSymbol(I.class) + getContainingJvmClassName: I + getContainingModule: KtLibraryModule "Library main" + deprecationStatus: null + symbolKind: CLASS_MEMBER + typeParameters: [] + visibility: Public + getDispatchReceiver(): KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: I + getContainingFileSymbol: KtFileSymbol(I.class) + getContainingJvmClassName: I + getContainingModule: KtLibraryModule "Library main" + deprecationStatus: null + getterDeprecationStatus: null + javaGetterName: getBar + javaSetterName: setBar + setterDeprecationStatus: null + +KtKotlinPropertySymbol: + annotationsList: [] + backingFieldSymbol: KtBackingFieldSymbol: + annotationsList: [] + callableIdIfNonLocal: null + contextReceivers: [] + isExtension: false + name: field + origin: PROPERTY_BACKING_FIELD + owningProperty: KtKotlinPropertySymbol(/I.doo) + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/String + symbolKind: LOCAL + typeParameters: [] + getContainingFileSymbol: KtFileSymbol(I.class) + getContainingJvmClassName: I + getContainingModule: KtLibraryModule "Library main" + deprecationStatus: null + callableIdIfNonLocal: /I.doo + contextReceivers: [] + getter: KtPropertyGetterSymbol: + annotationsList: [] + callableIdIfNonLocal: null + contextReceivers: [] + hasBody: false + hasStableParameterNames: true + isDefault: true + isExtension: false + isInline: false + isOverride: false + modality: FINAL + origin: SOURCE + receiverParameter: KtReceiverParameterSymbol: + annotationsList: [] + origin: SOURCE + owningCallableSymbol: KtKotlinPropertySymbol(/I.doo) + type: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Int + getContainingFileSymbol: KtFileSymbol(I.class) + getContainingModule: KtLibraryModule "Library main" + deprecationStatus: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/String + symbolKind: ACCESSOR + typeParameters: [] + valueParameters: [] + visibility: Public + getDispatchReceiver(): KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: I + getContainingFileSymbol: KtFileSymbol(I.class) + getContainingJvmClassName: I + getContainingModule: KtLibraryModule "Library main" + deprecationStatus: null + hasBackingField: true + hasGetter: true + hasSetter: false + initializer: null + isActual: false + isConst: false + isDelegatedProperty: false + isExpect: false + isExtension: true + isFromPrimaryConstructor: false + isLateInit: false + isOverride: false + isStatic: false + isVal: true + modality: OPEN + name: doo + origin: SOURCE + receiverParameter: KtReceiverParameterSymbol: + annotationsList: [] + origin: SOURCE + owningCallableSymbol: KtKotlinPropertySymbol(/I.doo) + type: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Int + getContainingFileSymbol: KtFileSymbol(I.class) + getContainingModule: KtLibraryModule "Library main" + deprecationStatus: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/String + setter: null + symbolKind: CLASS_MEMBER + typeParameters: [] + visibility: Public + getDispatchReceiver(): KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: I + getContainingFileSymbol: KtFileSymbol(I.class) + getContainingJvmClassName: I + getContainingModule: KtLibraryModule "Library main" + deprecationStatus: null + getterDeprecationStatus: null + javaGetterName: getDoo + javaSetterName: null + setterDeprecationStatus: null + +KtFunctionSymbol: + annotationsList: [] + callableIdIfNonLocal: /I.foo + contextReceivers: [] + contractEffects: [] + hasStableParameterNames: true + isActual: false + isBuiltinFunctionInvoke: false + isExpect: false + isExtension: false + isExternal: false + isInfix: false + isInline: false + isOperator: false + isOverride: false + isStatic: false + isSuspend: false + modality: OPEN + name: foo + origin: SOURCE + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Unit + symbolKind: CLASS_MEMBER + typeParameters: [] + valueParameters: [] + visibility: Public + getDispatchReceiver(): KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: I + getContainingFileSymbol: KtFileSymbol(I.class) + getContainingJvmClassName: I + getContainingModule: KtLibraryModule "Library main" + deprecationStatus: null + +KtKotlinPropertySymbol: + annotationsList: [] + backingFieldSymbol: KtBackingFieldSymbol: + annotationsList: [] + callableIdIfNonLocal: null + contextReceivers: [] + isExtension: false + name: field + origin: PROPERTY_BACKING_FIELD + owningProperty: KtKotlinPropertySymbol(/I.foo) + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Int + symbolKind: LOCAL + typeParameters: [] + getContainingFileSymbol: KtFileSymbol(I.class) + getContainingJvmClassName: I + getContainingModule: KtLibraryModule "Library main" + deprecationStatus: null + callableIdIfNonLocal: /I.foo + contextReceivers: [] + getter: KtPropertyGetterSymbol: + annotationsList: [] + callableIdIfNonLocal: null + contextReceivers: [] + hasBody: false + hasStableParameterNames: true + isDefault: true + isExtension: false + isInline: false + isOverride: false + modality: FINAL + origin: SOURCE + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Int + symbolKind: ACCESSOR + typeParameters: [] + valueParameters: [] + visibility: Public + getDispatchReceiver(): KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: I + getContainingFileSymbol: KtFileSymbol(I.class) + getContainingJvmClassName: I + getContainingModule: KtLibraryModule "Library main" + deprecationStatus: null + hasBackingField: true + hasGetter: true + hasSetter: false + initializer: null + isActual: false + isConst: false + isDelegatedProperty: false + isExpect: false + isExtension: false + isFromPrimaryConstructor: false + isLateInit: false + isOverride: false + isStatic: false + isVal: true + modality: OPEN + name: foo + origin: SOURCE + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Int + setter: null + symbolKind: CLASS_MEMBER + typeParameters: [] + visibility: Public + getDispatchReceiver(): KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: I + getContainingFileSymbol: KtFileSymbol(I.class) + getContainingJvmClassName: I + getContainingModule: KtLibraryModule "Library main" + deprecationStatus: null + getterDeprecationStatus: null + javaGetterName: getFoo + javaSetterName: null + setterDeprecationStatus: null + +KtKotlinPropertySymbol: + annotationsList: [] + backingFieldSymbol: KtBackingFieldSymbol: + annotationsList: [] + callableIdIfNonLocal: null + contextReceivers: [] + isExtension: false + name: field + origin: PROPERTY_BACKING_FIELD + owningProperty: KtKotlinPropertySymbol(/I.zoo) + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Unit + symbolKind: LOCAL + typeParameters: [] + getContainingFileSymbol: KtFileSymbol(I.class) + getContainingJvmClassName: I + getContainingModule: KtLibraryModule "Library main" + deprecationStatus: null + callableIdIfNonLocal: /I.zoo + contextReceivers: [] + getter: KtPropertyGetterSymbol: + annotationsList: [] + callableIdIfNonLocal: null + contextReceivers: [] + hasBody: false + hasStableParameterNames: true + isDefault: true + isExtension: false + isInline: false + isOverride: false + modality: FINAL + origin: SOURCE + receiverParameter: KtReceiverParameterSymbol: + annotationsList: [] + origin: SOURCE + owningCallableSymbol: KtKotlinPropertySymbol(/I.zoo) + type: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Int + getContainingFileSymbol: KtFileSymbol(I.class) + getContainingModule: KtLibraryModule "Library main" + deprecationStatus: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Unit + symbolKind: ACCESSOR + typeParameters: [] + valueParameters: [] + visibility: Public + getDispatchReceiver(): KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: I + getContainingFileSymbol: KtFileSymbol(I.class) + getContainingJvmClassName: I + getContainingModule: KtLibraryModule "Library main" + deprecationStatus: null + hasBackingField: true + hasGetter: true + hasSetter: true + initializer: null + isActual: false + isConst: false + isDelegatedProperty: false + isExpect: false + isExtension: true + isFromPrimaryConstructor: false + isLateInit: false + isOverride: false + isStatic: false + isVal: false + modality: OPEN + name: zoo + origin: SOURCE + receiverParameter: KtReceiverParameterSymbol: + annotationsList: [] + origin: SOURCE + owningCallableSymbol: KtKotlinPropertySymbol(/I.zoo) + type: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Int + getContainingFileSymbol: KtFileSymbol(I.class) + getContainingModule: KtLibraryModule "Library main" + deprecationStatus: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Unit + setter: KtPropertySetterSymbol: + annotationsList: [] + callableIdIfNonLocal: null + contextReceivers: [] + hasBody: false + hasStableParameterNames: true + isDefault: true + isExtension: false + isInline: false + isOverride: false + modality: FINAL + origin: SOURCE + parameter: KtValueParameterSymbol: + annotationsList: [] + callableIdIfNonLocal: null + contextReceivers: [] + generatedPrimaryConstructorProperty: null + hasDefaultValue: false + isCrossinline: false + isExtension: false + isImplicitLambdaParameter: false + isNoinline: false + isVararg: false + name: value + origin: SOURCE + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Unit + symbolKind: LOCAL + typeParameters: [] + getContainingFileSymbol: KtFileSymbol(I.class) + getContainingJvmClassName: null + getContainingModule: KtLibraryModule "Library main" + deprecationStatus: null + receiverParameter: KtReceiverParameterSymbol: + annotationsList: [] + origin: SOURCE + owningCallableSymbol: KtKotlinPropertySymbol(/I.zoo) + type: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Int + getContainingFileSymbol: KtFileSymbol(I.class) + getContainingModule: KtLibraryModule "Library main" + deprecationStatus: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Unit + symbolKind: ACCESSOR + typeParameters: [] + valueParameters: [ + KtValueParameterSymbol: + annotationsList: [] + callableIdIfNonLocal: null + contextReceivers: [] + generatedPrimaryConstructorProperty: null + hasDefaultValue: false + isCrossinline: false + isExtension: false + isImplicitLambdaParameter: false + isNoinline: false + isVararg: false + name: value + origin: SOURCE + receiverParameter: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Unit + symbolKind: LOCAL + typeParameters: [] + getContainingFileSymbol: KtFileSymbol(I.class) + getContainingJvmClassName: null + getContainingModule: KtLibraryModule "Library main" + deprecationStatus: null + ] + visibility: Public + getDispatchReceiver(): KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: I + getContainingFileSymbol: KtFileSymbol(I.class) + getContainingJvmClassName: I + getContainingModule: KtLibraryModule "Library main" + deprecationStatus: null + symbolKind: CLASS_MEMBER + typeParameters: [] + visibility: Public + getDispatchReceiver(): KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: I + getContainingFileSymbol: KtFileSymbol(I.class) + getContainingJvmClassName: I + getContainingModule: KtLibraryModule "Library main" + deprecationStatus: null + getterDeprecationStatus: null + javaGetterName: getZoo + javaSetterName: setZoo + setterDeprecationStatus: null + +KtFunctionSymbol: + annotationsList: [] + callableIdIfNonLocal: /I.smth + contextReceivers: [] + contractEffects: [] + hasStableParameterNames: true + isActual: false + isBuiltinFunctionInvoke: false + isExpect: false + isExtension: true + isExternal: false + isInfix: false + isInline: false + isOperator: false + isOverride: false + isStatic: false + isSuspend: false + modality: OPEN + name: smth + origin: SOURCE + receiverParameter: KtReceiverParameterSymbol: + annotationsList: [] + origin: SOURCE + owningCallableSymbol: KtFunctionSymbol(/I.smth) + type: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Int + getContainingFileSymbol: KtFileSymbol(I.class) + getContainingModule: KtLibraryModule "Library main" + deprecationStatus: null + returnType: KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: kotlin/Short + symbolKind: CLASS_MEMBER + typeParameters: [] + valueParameters: [] + visibility: Public + getDispatchReceiver(): KtUsualClassType: + annotationsList: [] + ownTypeArguments: [] + type: I + getContainingFileSymbol: KtFileSymbol(I.class) + getContainingJvmClassName: I + getContainingModule: KtLibraryModule "Library main" + deprecationStatus: null + KtConstructorSymbol: annotationsList: [] callableIdIfNonLocal: null diff --git a/analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/Delegation/Delegation.k2.txt b/analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/Delegation/Delegation.k2.txt new file mode 100644 index 00000000000..4911dcc25a5 --- /dev/null +++ b/analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/Delegation/Delegation.k2.txt @@ -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] diff --git a/analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/Delegation/Delegation.kt b/analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/Delegation/Delegation.kt index c83d90f6950..e89e93081f3 100644 --- a/analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/Delegation/Delegation.kt +++ b/analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/Delegation/Delegation.kt @@ -1,4 +1,3 @@ -// FIR_IDENTICAL interface T { fun f() val g: Int diff --git a/analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/Delegation/Delegation.txt b/analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/Delegation/Delegation.txt index 0f3b80a2e91..00fce7bf9d5 100644 --- a/analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/Delegation/Delegation.txt +++ b/analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/Delegation/Delegation.txt @@ -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 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 56fb4f0436f..734b65fc07e 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 @@ -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( 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 89f1681e355..a1765deb1cb 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 @@ -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, diff --git a/analysis/low-level-api-fir/testData/getOrBuildFirBinary/delegate.txt b/analysis/low-level-api-fir/testData/getOrBuildFirBinary/delegate.txt index 58eac69e467..e2921d460c4 100644 --- a/analysis/low-level-api-fir/testData/getOrBuildFirBinary/delegate.txt +++ b/analysis/low-level-api-fir/testData/getOrBuildFirBinary/delegate.txt @@ -2,15 +2,45 @@ KT element: KtClass KT element text: public final class I public constructor(p: A) : A { private final val p: A /* compiled code */ + + public open var bar: kotlin.Long /* compiled code */ + + public open val kotlin.Int.doo: kotlin.String /* compiled code */ + + public open val foo: kotlin.Int /* compiled code */ + + public open var kotlin.Int.zoo: kotlin.Unit /* compiled code */ + + public open fun foo(): kotlin.Unit { /* compiled code */ } + + public open fun kotlin.Int.smth(): kotlin.Short { /* compiled code */ } } FIR element: FirRegularClassImpl FIR source kind: KtRealSourceElementKind FIR element rendered: public final [ResolvedTo(BODY_RESOLVE)] class I : R|A| { + public open [ResolvedTo(BODY_RESOLVE)] fun foo(): R|kotlin/Unit| + + public open [ResolvedTo(BODY_RESOLVE)] fun R|kotlin/Int|.smth(): R|kotlin/Short| + + public open [ResolvedTo(BODY_RESOLVE)] var bar: R|kotlin/Long| + + + + public open [ResolvedTo(BODY_RESOLVE)] val R|kotlin/Int|.doo: R|kotlin/String| + + + public open [ResolvedTo(BODY_RESOLVE)] val foo: R|kotlin/Int| + + private final [ResolvedTo(BODY_RESOLVE)] val p: R|A| + public open [ResolvedTo(BODY_RESOLVE)] var R|kotlin/Int|.zoo: R|kotlin/Unit| + + + public [ResolvedTo(BODY_RESOLVE)] [ContainingClassKey=I] constructor([ResolvedTo(BODY_RESOLVE)] p: R|A|): R|I| } \ No newline at end of file diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/stubs/KotlinStubVersions.kt b/compiler/psi/src/org/jetbrains/kotlin/psi/stubs/KotlinStubVersions.kt index 2c21f106d47..ecec4972cc9 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/stubs/KotlinStubVersions.kt +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/stubs/KotlinStubVersions.kt @@ -17,7 +17,7 @@ object KotlinStubVersions { // Binary stub version should be increased if stub format (org.jetbrains.kotlin.psi.stubs.impl) is changed // or changes are made to the core stub building code (org.jetbrains.kotlin.idea.decompiler.stubBuilder). // Increasing this version will lead to reindexing of all binary files that are potentially kotlin binaries (including all class files). - private const val BINARY_STUB_VERSION = 93 + private const val BINARY_STUB_VERSION = 94 // Classfile stub version should be increased if changes are made to classfile stub building subsystem (org.jetbrains.kotlin.idea.decompiler.classFile) // Increasing this version will lead to reindexing of all classfiles.