[FIR] preserve real source for property accessors
^ KT-59705 If property is delegated, it can't have property accessors with non-default impl, but it can contain property accessors declarations with non-default visibility, annotations, etc. Seems, it's more logical to preserve them as fake sources than use property itself
This commit is contained in:
+2
-1
@@ -158,7 +158,8 @@ private fun KtDeclaration.findSourceNonLocalFirDeclarationByProvider(
|
||||
else -> errorWithFirSpecificEntries("Invalid container", psi = this)
|
||||
}
|
||||
|
||||
return candidate?.takeIf { it.realPsi == this }
|
||||
//property accessors for properties with delegation have KtFakeSourceElementKind.DelegatedPropertyAccessor kind
|
||||
return candidate?.takeIf { it.psi == this }
|
||||
}
|
||||
|
||||
fun FirAnonymousInitializer.containingClass(): FirRegularClass {
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
val one: Int by Prp()
|
||||
@Deprecated("reason") ge<caret>t
|
||||
|
||||
class Prp {
|
||||
fun getValue() = 1
|
||||
}
|
||||
+231
@@ -0,0 +1,231 @@
|
||||
RAW_FIR:
|
||||
FILE: [ResolvedTo(RAW_FIR)] getterWithDelegation.kt
|
||||
[ResolvedTo(BODY_RESOLVE)] annotations container
|
||||
public? final? [ResolvedTo(RAW_FIR)] val one: Intby LAZY_EXPRESSION
|
||||
@Deprecated[Unresolved](LAZY_EXPRESSION) public? [ResolvedTo(RAW_FIR)] get(): <implicit> {
|
||||
^ D|/one|.getValue#(Null(null), ::R|/one|)
|
||||
}
|
||||
public? final? [ResolvedTo(RAW_FIR)] class Prp : R|kotlin/Any| {
|
||||
public? [ResolvedTo(RAW_FIR)] [ContainingClassKey=Prp] constructor(): R|Prp| {
|
||||
LAZY_super<R|kotlin/Any|>
|
||||
}
|
||||
|
||||
public? final? [ResolvedTo(RAW_FIR)] fun getValue(): <implicit> { LAZY_BLOCK }
|
||||
|
||||
}
|
||||
|
||||
IMPORTS:
|
||||
FILE: [ResolvedTo(IMPORTS)] getterWithDelegation.kt
|
||||
[ResolvedTo(BODY_RESOLVE)] annotations container
|
||||
public? final? [ResolvedTo(RAW_FIR)] val one: Intby LAZY_EXPRESSION
|
||||
@Deprecated[Unresolved](LAZY_EXPRESSION) public? [ResolvedTo(RAW_FIR)] get(): <implicit> {
|
||||
^ D|/one|.getValue#(Null(null), ::R|/one|)
|
||||
}
|
||||
public? final? [ResolvedTo(RAW_FIR)] class Prp : R|kotlin/Any| {
|
||||
public? [ResolvedTo(RAW_FIR)] [ContainingClassKey=Prp] constructor(): R|Prp| {
|
||||
LAZY_super<R|kotlin/Any|>
|
||||
}
|
||||
|
||||
public? final? [ResolvedTo(RAW_FIR)] fun getValue(): <implicit> { LAZY_BLOCK }
|
||||
|
||||
}
|
||||
|
||||
COMPILER_REQUIRED_ANNOTATIONS:
|
||||
FILE: [ResolvedTo(IMPORTS)] getterWithDelegation.kt
|
||||
[ResolvedTo(BODY_RESOLVE)] annotations container
|
||||
public? final? [ResolvedTo(COMPILER_REQUIRED_ANNOTATIONS)] val one: Intby LAZY_EXPRESSION
|
||||
@R|kotlin/Deprecated|[CompilerRequiredAnnotations](String(reason)) public? [ResolvedTo(COMPILER_REQUIRED_ANNOTATIONS)] get(): <implicit> {
|
||||
^ D|/one|.getValue#(Null(null), ::R|/one|)
|
||||
}
|
||||
public? final? [ResolvedTo(RAW_FIR)] class Prp : R|kotlin/Any| {
|
||||
public? [ResolvedTo(RAW_FIR)] [ContainingClassKey=Prp] constructor(): R|Prp| {
|
||||
LAZY_super<R|kotlin/Any|>
|
||||
}
|
||||
|
||||
public? final? [ResolvedTo(RAW_FIR)] fun getValue(): <implicit> { LAZY_BLOCK }
|
||||
|
||||
}
|
||||
|
||||
COMPANION_GENERATION:
|
||||
FILE: [ResolvedTo(IMPORTS)] getterWithDelegation.kt
|
||||
[ResolvedTo(BODY_RESOLVE)] annotations container
|
||||
public? final? [ResolvedTo(COMPANION_GENERATION)] val one: Intby LAZY_EXPRESSION
|
||||
@R|kotlin/Deprecated|[CompilerRequiredAnnotations](String(reason)) public? [ResolvedTo(COMPANION_GENERATION)] get(): <implicit> {
|
||||
^ D|/one|.getValue#(Null(null), ::R|/one|)
|
||||
}
|
||||
public? final? [ResolvedTo(RAW_FIR)] class Prp : R|kotlin/Any| {
|
||||
public? [ResolvedTo(RAW_FIR)] [ContainingClassKey=Prp] constructor(): R|Prp| {
|
||||
LAZY_super<R|kotlin/Any|>
|
||||
}
|
||||
|
||||
public? final? [ResolvedTo(RAW_FIR)] fun getValue(): <implicit> { LAZY_BLOCK }
|
||||
|
||||
}
|
||||
|
||||
SUPER_TYPES:
|
||||
FILE: [ResolvedTo(IMPORTS)] getterWithDelegation.kt
|
||||
[ResolvedTo(BODY_RESOLVE)] annotations container
|
||||
public? final? [ResolvedTo(SUPER_TYPES)] val one: Intby LAZY_EXPRESSION
|
||||
@R|kotlin/Deprecated|[CompilerRequiredAnnotations](String(reason)) public? [ResolvedTo(SUPER_TYPES)] get(): <implicit> {
|
||||
^ D|/one|.getValue#(Null(null), ::R|/one|)
|
||||
}
|
||||
public? final? [ResolvedTo(RAW_FIR)] class Prp : R|kotlin/Any| {
|
||||
public? [ResolvedTo(RAW_FIR)] [ContainingClassKey=Prp] constructor(): R|Prp| {
|
||||
LAZY_super<R|kotlin/Any|>
|
||||
}
|
||||
|
||||
public? final? [ResolvedTo(RAW_FIR)] fun getValue(): <implicit> { LAZY_BLOCK }
|
||||
|
||||
}
|
||||
|
||||
TYPES:
|
||||
FILE: [ResolvedTo(IMPORTS)] getterWithDelegation.kt
|
||||
[ResolvedTo(BODY_RESOLVE)] annotations container
|
||||
public? final? [ResolvedTo(TYPES)] val one: R|kotlin/Int|by LAZY_EXPRESSION
|
||||
@R|kotlin/Deprecated|[Types](String(reason)) public? [ResolvedTo(TYPES)] get(): R|kotlin/Int| {
|
||||
^ D|/one|.getValue#(Null(null), ::R|/one|)
|
||||
}
|
||||
public? final? [ResolvedTo(RAW_FIR)] class Prp : R|kotlin/Any| {
|
||||
public? [ResolvedTo(RAW_FIR)] [ContainingClassKey=Prp] constructor(): R|Prp| {
|
||||
LAZY_super<R|kotlin/Any|>
|
||||
}
|
||||
|
||||
public? final? [ResolvedTo(RAW_FIR)] fun getValue(): <implicit> { LAZY_BLOCK }
|
||||
|
||||
}
|
||||
|
||||
STATUS:
|
||||
FILE: [ResolvedTo(IMPORTS)] getterWithDelegation.kt
|
||||
[ResolvedTo(BODY_RESOLVE)] annotations container
|
||||
public final [ResolvedTo(STATUS)] val one: R|kotlin/Int|by LAZY_EXPRESSION
|
||||
@R|kotlin/Deprecated|[Types](String(reason)) public [ResolvedTo(STATUS)] get(): R|kotlin/Int| {
|
||||
^ D|/one|.getValue#(Null(null), ::R|/one|)
|
||||
}
|
||||
public? final? [ResolvedTo(RAW_FIR)] class Prp : R|kotlin/Any| {
|
||||
public? [ResolvedTo(RAW_FIR)] [ContainingClassKey=Prp] constructor(): R|Prp| {
|
||||
LAZY_super<R|kotlin/Any|>
|
||||
}
|
||||
|
||||
public? final? [ResolvedTo(RAW_FIR)] fun getValue(): <implicit> { LAZY_BLOCK }
|
||||
|
||||
}
|
||||
|
||||
EXPECT_ACTUAL_MATCHING:
|
||||
FILE: [ResolvedTo(IMPORTS)] getterWithDelegation.kt
|
||||
[ResolvedTo(BODY_RESOLVE)] annotations container
|
||||
public final [ResolvedTo(EXPECT_ACTUAL_MATCHING)] val one: R|kotlin/Int|by LAZY_EXPRESSION
|
||||
@R|kotlin/Deprecated|[Types](String(reason)) public [ResolvedTo(EXPECT_ACTUAL_MATCHING)] get(): R|kotlin/Int| {
|
||||
^ D|/one|.getValue#(Null(null), ::R|/one|)
|
||||
}
|
||||
public? final? [ResolvedTo(RAW_FIR)] class Prp : R|kotlin/Any| {
|
||||
public? [ResolvedTo(RAW_FIR)] [ContainingClassKey=Prp] constructor(): R|Prp| {
|
||||
LAZY_super<R|kotlin/Any|>
|
||||
}
|
||||
|
||||
public? final? [ResolvedTo(RAW_FIR)] fun getValue(): <implicit> { LAZY_BLOCK }
|
||||
|
||||
}
|
||||
|
||||
ARGUMENTS_OF_ANNOTATIONS:
|
||||
FILE: [ResolvedTo(IMPORTS)] getterWithDelegation.kt
|
||||
[ResolvedTo(BODY_RESOLVE)] annotations container
|
||||
public final [ResolvedTo(ARGUMENTS_OF_ANNOTATIONS)] val one: R|kotlin/Int|by LAZY_EXPRESSION
|
||||
@R|kotlin/Deprecated|[Types](String(reason)) public [ResolvedTo(ARGUMENTS_OF_ANNOTATIONS)] get(): R|kotlin/Int| {
|
||||
^ D|/one|.getValue#(Null(null), ::R|/one|)
|
||||
}
|
||||
public? final? [ResolvedTo(RAW_FIR)] class Prp : R|kotlin/Any| {
|
||||
public? [ResolvedTo(RAW_FIR)] [ContainingClassKey=Prp] constructor(): R|Prp| {
|
||||
LAZY_super<R|kotlin/Any|>
|
||||
}
|
||||
|
||||
public? final? [ResolvedTo(RAW_FIR)] fun getValue(): <implicit> { LAZY_BLOCK }
|
||||
|
||||
}
|
||||
|
||||
CONTRACTS:
|
||||
FILE: [ResolvedTo(IMPORTS)] getterWithDelegation.kt
|
||||
[ResolvedTo(BODY_RESOLVE)] annotations container
|
||||
public final [ResolvedTo(CONTRACTS)] val one: R|kotlin/Int|by Prp#()
|
||||
@R|kotlin/Deprecated|[Types](String(reason)) public [ResolvedTo(CONTRACTS)] get(): R|kotlin/Int| {
|
||||
^ D|/one|.getValue#(Null(null), ::R|/one|)
|
||||
}
|
||||
public? final? [ResolvedTo(RAW_FIR)] class Prp : R|kotlin/Any| {
|
||||
public? [ResolvedTo(RAW_FIR)] [ContainingClassKey=Prp] constructor(): R|Prp| {
|
||||
LAZY_super<R|kotlin/Any|>
|
||||
}
|
||||
|
||||
public? final? [ResolvedTo(RAW_FIR)] fun getValue(): <implicit> { LAZY_BLOCK }
|
||||
|
||||
}
|
||||
|
||||
IMPLICIT_TYPES_BODY_RESOLVE:
|
||||
FILE: [ResolvedTo(IMPORTS)] getterWithDelegation.kt
|
||||
[ResolvedTo(BODY_RESOLVE)] annotations container
|
||||
public final [ResolvedTo(IMPLICIT_TYPES_BODY_RESOLVE)] val one: R|kotlin/Int|by R|/Prp.Prp|()
|
||||
@R|kotlin/Deprecated|[Types](message = String(reason)) public [ResolvedTo(IMPLICIT_TYPES_BODY_RESOLVE)] get(): R|kotlin/Int| {
|
||||
^ D|/one|.R|/Prp.getValue<Inapplicable(INAPPLICABLE_ARGUMENTS_MAPPING_ERROR): /Prp.getValue>#|(Null(null), ::R|/one|)
|
||||
}
|
||||
public final [ResolvedTo(STATUS)] class Prp : R|kotlin/Any| {
|
||||
public [ResolvedTo(STATUS)] [ContainingClassKey=Prp] constructor(): R|Prp| {
|
||||
LAZY_super<R|kotlin/Any|>
|
||||
}
|
||||
|
||||
public final [ResolvedTo(IMPLICIT_TYPES_BODY_RESOLVE)] fun getValue(): R|kotlin/Int| {
|
||||
^getValue Int(1)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ANNOTATIONS_ARGUMENTS_MAPPING:
|
||||
FILE: [ResolvedTo(IMPORTS)] getterWithDelegation.kt
|
||||
[ResolvedTo(BODY_RESOLVE)] annotations container
|
||||
public final [ResolvedTo(ANNOTATIONS_ARGUMENTS_MAPPING)] val one: R|kotlin/Int|by R|/Prp.Prp|()
|
||||
@R|kotlin/Deprecated|[Types](message = String(reason)) public [ResolvedTo(ANNOTATIONS_ARGUMENTS_MAPPING)] get(): R|kotlin/Int| {
|
||||
^ D|/one|.R|/Prp.getValue<Inapplicable(INAPPLICABLE_ARGUMENTS_MAPPING_ERROR): /Prp.getValue>#|(Null(null), ::R|/one|)
|
||||
}
|
||||
public final [ResolvedTo(STATUS)] class Prp : R|kotlin/Any| {
|
||||
public [ResolvedTo(STATUS)] [ContainingClassKey=Prp] constructor(): R|Prp| {
|
||||
LAZY_super<R|kotlin/Any|>
|
||||
}
|
||||
|
||||
public final [ResolvedTo(IMPLICIT_TYPES_BODY_RESOLVE)] fun getValue(): R|kotlin/Int| {
|
||||
^getValue Int(1)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
BODY_RESOLVE:
|
||||
FILE: [ResolvedTo(IMPORTS)] getterWithDelegation.kt
|
||||
[ResolvedTo(BODY_RESOLVE)] annotations container
|
||||
public final [ResolvedTo(BODY_RESOLVE)] val one: R|kotlin/Int|by R|/Prp.Prp|()
|
||||
@R|kotlin/Deprecated|[Types](message = String(reason)) public [ResolvedTo(BODY_RESOLVE)] get(): R|kotlin/Int| {
|
||||
^ D|/one|.R|/Prp.getValue<Inapplicable(INAPPLICABLE_ARGUMENTS_MAPPING_ERROR): /Prp.getValue>#|(Null(null), ::R|/one|)
|
||||
}
|
||||
public final [ResolvedTo(STATUS)] class Prp : R|kotlin/Any| {
|
||||
public [ResolvedTo(STATUS)] [ContainingClassKey=Prp] constructor(): R|Prp| {
|
||||
LAZY_super<R|kotlin/Any|>
|
||||
}
|
||||
|
||||
public final [ResolvedTo(IMPLICIT_TYPES_BODY_RESOLVE)] fun getValue(): R|kotlin/Int| {
|
||||
^getValue Int(1)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
FILE RAW TO BODY:
|
||||
FILE: [ResolvedTo(IMPORTS)] getterWithDelegation.kt
|
||||
[ResolvedTo(BODY_RESOLVE)] annotations container
|
||||
public final [ResolvedTo(BODY_RESOLVE)] val one: R|kotlin/Int|by R|/Prp.Prp|()
|
||||
@R|kotlin/Deprecated|[Types](message = String(reason)) public [ResolvedTo(BODY_RESOLVE)] get(): R|kotlin/Int| {
|
||||
^ D|/one|.R|/Prp.getValue<Inapplicable(INAPPLICABLE_ARGUMENTS_MAPPING_ERROR): /Prp.getValue>#|(Null(null), ::R|/one|)
|
||||
}
|
||||
public final [ResolvedTo(BODY_RESOLVE)] class Prp : R|kotlin/Any| {
|
||||
public [ResolvedTo(BODY_RESOLVE)] [ContainingClassKey=Prp] constructor(): R|Prp| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
public final [ResolvedTo(BODY_RESOLVE)] fun getValue(): R|kotlin/Int| {
|
||||
^getValue Int(1)
|
||||
}
|
||||
|
||||
}
|
||||
+6
@@ -693,6 +693,12 @@ public class FirOutOfContentRootLazyDeclarationResolveTestGenerated extends Abst
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/low-level-api-fir/testdata/lazyResolve/properties"), Pattern.compile("^(.+)\\.kt$"), null, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("getterWithDelegation.kt")
|
||||
public void testGetterWithDelegation() throws Exception {
|
||||
runTest("analysis/low-level-api-fir/testdata/lazyResolve/properties/getterWithDelegation.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("hierarchyWithOverride.kt")
|
||||
public void testHierarchyWithOverride() throws Exception {
|
||||
|
||||
+6
@@ -693,6 +693,12 @@ public class FirSourceLazyDeclarationResolveTestGenerated extends AbstractFirSou
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/low-level-api-fir/testdata/lazyResolve/properties"), Pattern.compile("^(.+)\\.kt$"), null, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("getterWithDelegation.kt")
|
||||
public void testGetterWithDelegation() throws Exception {
|
||||
runTest("analysis/low-level-api-fir/testdata/lazyResolve/properties/getterWithDelegation.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("hierarchyWithOverride.kt")
|
||||
public void testHierarchyWithOverride() throws Exception {
|
||||
|
||||
+4
-2
@@ -417,8 +417,9 @@ fun <T> FirPropertyBuilder.generateAccessorsByDelegate(
|
||||
val annotations = getter?.annotations
|
||||
val returnTarget = FirFunctionTarget(null, isLambda = false)
|
||||
val getterStatus = getter?.status
|
||||
val getterElement = getter?.source?.fakeElement(KtFakeSourceElementKind.DelegatedPropertyAccessor) ?: fakeSource
|
||||
getter = buildPropertyAccessor {
|
||||
this.source = fakeSource
|
||||
this.source = getterElement
|
||||
this.moduleData = moduleData
|
||||
origin = FirDeclarationOrigin.Source
|
||||
returnTypeRef = FirImplicitTypeRefImplWithoutSource
|
||||
@@ -456,8 +457,9 @@ fun <T> FirPropertyBuilder.generateAccessorsByDelegate(
|
||||
val annotations = setter?.annotations
|
||||
val parameterAnnotations = setter?.valueParameters?.firstOrNull()?.annotations
|
||||
val setterStatus = setter?.status
|
||||
val setterElement = setter?.source?.fakeElement(KtFakeSourceElementKind.DelegatedPropertyAccessor) ?: fakeSource
|
||||
setter = buildPropertyAccessor {
|
||||
this.source = fakeSource
|
||||
this.source = setterElement
|
||||
this.moduleData = moduleData
|
||||
origin = FirDeclarationOrigin.Source
|
||||
returnTypeRef = moduleData.session.builtinTypes.unitType
|
||||
|
||||
Reference in New Issue
Block a user