From 1e2f74aed6460520fc52258f4b936f5187419cda Mon Sep 17 00:00:00 2001 From: Jinseong Jeon Date: Mon, 5 Aug 2024 23:10:19 -0700 Subject: [PATCH] SLC: use proper source PSI for no-arg constructor If no-arg constructor stems from the primary constructor (e.g., when all arguments have a default value), that primary constructor should be used as source PSI. Otherwise, i.e., literally default constructor, the containing class is the source PSI. ^KT-70491 fixed --- .../classes/symbol/classes/symbolLightClassUtils.kt | 11 ++++++++--- .../converter/defaultParameterValueOff.fir.txt | 2 +- .../converter/defaultParameterValueOn.fir.txt | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/analysis/symbol-light-classes/src/org/jetbrains/kotlin/light/classes/symbol/classes/symbolLightClassUtils.kt b/analysis/symbol-light-classes/src/org/jetbrains/kotlin/light/classes/symbol/classes/symbolLightClassUtils.kt index 7e4dd46a5976f..6bf243256494c 100644 --- a/analysis/symbol-light-classes/src/org/jetbrains/kotlin/light/classes/symbol/classes/symbolLightClassUtils.kt +++ b/analysis/symbol-light-classes/src/org/jetbrains/kotlin/light/classes/symbol/classes/symbolLightClassUtils.kt @@ -168,7 +168,11 @@ internal fun SymbolLightClassBase.createConstructors( val primaryConstructor = constructors.singleOrNull { it.isPrimary } if (primaryConstructor != null && shouldGenerateNoArgOverload(primaryConstructor, constructors)) { result.add( - noArgConstructor(primaryConstructor.compilerVisibility.externalDisplayName, METHOD_INDEX_FOR_NO_ARG_OVERLOAD_CTOR) + noArgConstructor( + primaryConstructor.compilerVisibility.externalDisplayName, + primaryConstructor.sourcePsiSafe(), + METHOD_INDEX_FOR_NO_ARG_OVERLOAD_CTOR + ) ) } } @@ -198,14 +202,15 @@ private fun SymbolLightClassBase.defaultConstructor(): KtLightMethod { else -> PsiModifier.PUBLIC } - return noArgConstructor(visibility, METHOD_INDEX_FOR_DEFAULT_CTOR) + return noArgConstructor(visibility, classOrObject, METHOD_INDEX_FOR_DEFAULT_CTOR) } private fun SymbolLightClassBase.noArgConstructor( visibility: String, + declaration: KtDeclaration?, methodIndex: Int, ): KtLightMethod = SymbolLightNoArgConstructor( - kotlinOrigin?.let { + declaration?.let { LightMemberOriginForDeclaration( originalElement = it, originKind = JvmDeclarationOriginKind.OTHER, diff --git a/plugins/kapt3/kapt3-compiler/testData/converter/defaultParameterValueOff.fir.txt b/plugins/kapt3/kapt3-compiler/testData/converter/defaultParameterValueOff.fir.txt index dede3b6eeeda9..b2fa28872c503 100644 --- a/plugins/kapt3/kapt3-compiler/testData/converter/defaultParameterValueOff.fir.txt +++ b/plugins/kapt3/kapt3-compiler/testData/converter/defaultParameterValueOff.fir.txt @@ -34,7 +34,7 @@ public enum Em { /** * public final class Foo : kotlin/Any { * - * // signature: (ZBCCSIJFDLjava/lang/String;[I[J[D[Ljava/lang/String;Ljava/lang/Class;[Ljava/lang/Class;LEm;[LEm;)V + * // signature: (ZBCCSIJFDLjava/lang/String;[I[J[DLkotlin/Array;Ljava/lang/Class;Lkotlin/Array;LEm;Lkotlin/Array;)V * public constructor(z: kotlin/Boolean (* = ... *), b: kotlin/Byte (* = ... *), c: kotlin/Char (* = ... *), c2: kotlin/Char (* = ... *), sh: kotlin/Short (* = ... *), i: kotlin/Int (* = ... *), l: kotlin/Long (* = ... *), f: kotlin/Float (* = ... *), d: kotlin/Double (* = ... *), s: kotlin/String (* = ... *), iarr: kotlin/IntArray (* = ... *), larr: kotlin/LongArray (* = ... *), darr: kotlin/DoubleArray (* = ... *), sarr: kotlin/Array (* = ... *), cl: java/lang/Class<*> (* = ... *), clarr: kotlin/Array> (* = ... *), em: Em (* = ... *), emarr: kotlin/Array (* = ... *)) * * // signature: foo(I)V diff --git a/plugins/kapt3/kapt3-compiler/testData/converter/defaultParameterValueOn.fir.txt b/plugins/kapt3/kapt3-compiler/testData/converter/defaultParameterValueOn.fir.txt index 6a2c315db150f..0d5767a80e47e 100644 --- a/plugins/kapt3/kapt3-compiler/testData/converter/defaultParameterValueOn.fir.txt +++ b/plugins/kapt3/kapt3-compiler/testData/converter/defaultParameterValueOn.fir.txt @@ -34,7 +34,7 @@ public enum Em { /** * public final class Foo : kotlin/Any { * - * // signature: (ZBCCSIJFDLjava/lang/String;[I[J[D[Ljava/lang/String;Ljava/lang/Class;[Ljava/lang/Class;LEm;[LEm;)V + * // signature: (ZBCCSIJFDLjava/lang/String;[I[J[DLkotlin/Array;Ljava/lang/Class;Lkotlin/Array;LEm;Lkotlin/Array;)V * public constructor(z: kotlin/Boolean (* = ... *), b: kotlin/Byte (* = ... *), c: kotlin/Char (* = ... *), c2: kotlin/Char (* = ... *), sh: kotlin/Short (* = ... *), i: kotlin/Int (* = ... *), l: kotlin/Long (* = ... *), f: kotlin/Float (* = ... *), d: kotlin/Double (* = ... *), s: kotlin/String (* = ... *), iarr: kotlin/IntArray (* = ... *), larr: kotlin/LongArray (* = ... *), darr: kotlin/DoubleArray (* = ... *), sarr: kotlin/Array (* = ... *), cl: java/lang/Class<*> (* = ... *), clarr: kotlin/Array> (* = ... *), em: Em (* = ... *), emarr: kotlin/Array (* = ... *)) * * // signature: foo(I)V