[Analysis API] add tests for delegate field

^KT-64584
This commit is contained in:
Dmitrii Gridin
2023-12-27 17:50:23 +01:00
committed by Space Team
parent 3f337bf62d
commit 06950f57db
22 changed files with 573 additions and 2 deletions
@@ -58,6 +58,12 @@ public class Fe10IdeNormalAnalysisSourceModuleDelegateMemberScopeTestGenerated e
runTest("analysis/analysis-api/testData/components/scopeProvider/delegatedMemberScope/simple.kt");
}
@Test
@TestMetadata("simpleLibrary.kt")
public void testSimpleLibrary() throws Exception {
runTest("analysis/analysis-api/testData/components/scopeProvider/delegatedMemberScope/simpleLibrary.kt");
}
@Test
@TestMetadata("withImplicitType.kt")
public void testWithImplicitType() throws Exception {
@@ -52,6 +52,18 @@ public class FirIdeNormalAnalysisSourceModuleDeclaredMemberScopeTestGenerated ex
runTest("analysis/analysis-api/testData/components/scopeProvider/declaredMemberScope/class.kt");
}
@Test
@TestMetadata("delegateInterface.kt")
public void testDelegateInterface() throws Exception {
runTest("analysis/analysis-api/testData/components/scopeProvider/declaredMemberScope/delegateInterface.kt");
}
@Test
@TestMetadata("delegateInterfaceLibrary.kt")
public void testDelegateInterfaceLibrary() throws Exception {
runTest("analysis/analysis-api/testData/components/scopeProvider/declaredMemberScope/delegateInterfaceLibrary.kt");
}
@Test
@TestMetadata("enumClass.kt")
public void testEnumClass() throws Exception {
@@ -58,6 +58,12 @@ public class FirIdeNormalAnalysisSourceModuleDelegateMemberScopeTestGenerated ex
runTest("analysis/analysis-api/testData/components/scopeProvider/delegatedMemberScope/simple.kt");
}
@Test
@TestMetadata("simpleLibrary.kt")
public void testSimpleLibrary() throws Exception {
runTest("analysis/analysis-api/testData/components/scopeProvider/delegatedMemberScope/simpleLibrary.kt");
}
@Test
@TestMetadata("withImplicitType.kt")
public void testWithImplicitType() throws Exception {
@@ -52,6 +52,18 @@ public class FirStandaloneNormalAnalysisSourceModuleDeclaredMemberScopeTestGener
runTest("analysis/analysis-api/testData/components/scopeProvider/declaredMemberScope/class.kt");
}
@Test
@TestMetadata("delegateInterface.kt")
public void testDelegateInterface() throws Exception {
runTest("analysis/analysis-api/testData/components/scopeProvider/declaredMemberScope/delegateInterface.kt");
}
@Test
@TestMetadata("delegateInterfaceLibrary.kt")
public void testDelegateInterfaceLibrary() throws Exception {
runTest("analysis/analysis-api/testData/components/scopeProvider/declaredMemberScope/delegateInterfaceLibrary.kt");
}
@Test
@TestMetadata("enumClass.kt")
public void testEnumClass() throws Exception {
@@ -58,6 +58,12 @@ public class FirStandaloneNormalAnalysisSourceModuleDelegateMemberScopeTestGener
runTest("analysis/analysis-api/testData/components/scopeProvider/delegatedMemberScope/simple.kt");
}
@Test
@TestMetadata("simpleLibrary.kt")
public void testSimpleLibrary() throws Exception {
runTest("analysis/analysis-api/testData/components/scopeProvider/delegatedMemberScope/simpleLibrary.kt");
}
@Test
@TestMetadata("withImplicitType.kt")
public void testWithImplicitType() throws Exception {
@@ -0,0 +1,13 @@
// FILE: A.kt
interface A {
var Int.zoo: Unit
fun foo()
fun Int.smth(): Short
val foo: Int
var bar: Long
val Int.doo: String
}
®
class I(private val p: A) : A by p
// class: I
@@ -0,0 +1,3 @@
private val p: A
constructor(p: A)
@@ -0,0 +1,229 @@
KtKotlinPropertySymbol:
annotationsList: []
backingFieldSymbol: KtBackingFieldSymbol:
annotationsList: []
callableIdIfNonLocal: null
contextReceivers: []
isExtension: false
name: field
origin: PROPERTY_BACKING_FIELD
owningProperty: KtKotlinPropertySymbol(/I.p)
receiverParameter: null
returnType: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: A
symbolKind: LOCAL
typeParameters: []
getContainingFileSymbol: KtFileSymbol(A.kt)
getContainingJvmClassName: I
getContainingModule: KtSourceModule "Sources of main"
deprecationStatus: null
callableIdIfNonLocal: /I.p
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: A
symbolKind: ACCESSOR
typeParameters: []
valueParameters: []
visibility: Private
getDispatchReceiver(): KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: I
getContainingFileSymbol: KtFileSymbol(A.kt)
getContainingJvmClassName: I
getContainingModule: KtSourceModule "Sources of main"
deprecationStatus: null
hasBackingField: true
hasGetter: true
hasSetter: false
initializer: KtNonConstantInitializerValue(private val p: A)
isActual: false
isConst: false
isDelegatedProperty: false
isExpect: false
isExtension: false
isFromPrimaryConstructor: true
isLateInit: false
isOverride: false
isStatic: false
isVal: true
modality: FINAL
name: p
origin: SOURCE
receiverParameter: null
returnType: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: A
setter: null
symbolKind: CLASS_MEMBER
typeParameters: []
visibility: Private
getDispatchReceiver(): KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: I
getContainingFileSymbol: KtFileSymbol(A.kt)
getContainingJvmClassName: I
getContainingModule: KtSourceModule "Sources of main"
deprecationStatus: null
getterDeprecationStatus: null
javaGetterName: getP
javaSetterName: null
setterDeprecationStatus: null
KtConstructorSymbol:
annotationsList: []
callableIdIfNonLocal: null
containingClassIdIfNonLocal: I
contextReceivers: []
hasStableParameterNames: true
isActual: false
isExpect: false
isExtension: false
isPrimary: true
origin: SOURCE
receiverParameter: null
returnType: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: I
symbolKind: CLASS_MEMBER
typeParameters: []
valueParameters: [
KtValueParameterSymbol:
annotationsList: []
callableIdIfNonLocal: null
contextReceivers: []
generatedPrimaryConstructorProperty: KtKotlinPropertySymbol:
annotationsList: []
backingFieldSymbol: KtBackingFieldSymbol:
annotationsList: []
callableIdIfNonLocal: null
contextReceivers: []
isExtension: false
name: field
origin: PROPERTY_BACKING_FIELD
owningProperty: KtKotlinPropertySymbol(/I.p)
receiverParameter: null
returnType: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: A
symbolKind: LOCAL
typeParameters: []
getContainingFileSymbol: KtFileSymbol(A.kt)
getContainingJvmClassName: I
getContainingModule: KtSourceModule "Sources of main"
deprecationStatus: null
callableIdIfNonLocal: /I.p
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: A
symbolKind: ACCESSOR
typeParameters: []
valueParameters: []
visibility: Private
getDispatchReceiver(): KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: I
getContainingFileSymbol: KtFileSymbol(A.kt)
getContainingJvmClassName: I
getContainingModule: KtSourceModule "Sources of main"
deprecationStatus: null
hasBackingField: true
hasGetter: true
hasSetter: false
initializer: KtNonConstantInitializerValue(private val p: A)
isActual: false
isConst: false
isDelegatedProperty: false
isExpect: false
isExtension: false
isFromPrimaryConstructor: true
isLateInit: false
isOverride: false
isStatic: false
isVal: true
modality: FINAL
name: p
origin: SOURCE
receiverParameter: null
returnType: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: A
setter: null
symbolKind: CLASS_MEMBER
typeParameters: []
visibility: Private
getDispatchReceiver(): KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: I
getContainingFileSymbol: KtFileSymbol(A.kt)
getContainingJvmClassName: I
getContainingModule: KtSourceModule "Sources of main"
deprecationStatus: null
getterDeprecationStatus: null
javaGetterName: getP
javaSetterName: null
setterDeprecationStatus: null
hasDefaultValue: false
isCrossinline: false
isExtension: false
isImplicitLambdaParameter: false
isNoinline: false
isVararg: false
name: p
origin: SOURCE
receiverParameter: null
returnType: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: A
symbolKind: LOCAL
typeParameters: []
getContainingFileSymbol: KtFileSymbol(A.kt)
getContainingJvmClassName: I
getContainingModule: KtSourceModule "Sources of main"
deprecationStatus: null
]
visibility: Public
getContainingFileSymbol: KtFileSymbol(A.kt)
getContainingJvmClassName: I
getContainingModule: KtSourceModule "Sources of main"
deprecationStatus: null
@@ -0,0 +1,16 @@
// MODULE: main
// MODULE_KIND: LibraryBinary
// FILE: A.kt
interface A {
var Int.zoo: Unit
fun foo()
fun Int.smth(): Short
val foo: Int
var bar: Long
val Int.doo: String
}
class I(private val p: A) : A by p
// class: I
@@ -0,0 +1,3 @@
private val p: A
constructor(p: A)
@@ -0,0 +1,140 @@
KtKotlinPropertySymbol:
annotationsList: []
backingFieldSymbol: KtBackingFieldSymbol:
annotationsList: []
callableIdIfNonLocal: null
contextReceivers: []
isExtension: false
name: field
origin: PROPERTY_BACKING_FIELD
owningProperty: KtKotlinPropertySymbol(/I.p)
receiverParameter: null
returnType: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: A
symbolKind: LOCAL
typeParameters: []
getContainingFileSymbol: KtFileSymbol(I.class)
getContainingJvmClassName: I
getContainingModule: KtLibraryModule "Library main"
deprecationStatus: null
callableIdIfNonLocal: /I.p
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: A
symbolKind: ACCESSOR
typeParameters: []
valueParameters: []
visibility: Private
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: FINAL
name: p
origin: SOURCE
receiverParameter: null
returnType: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: A
setter: null
symbolKind: CLASS_MEMBER
typeParameters: []
visibility: Private
getDispatchReceiver(): KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: I
getContainingFileSymbol: KtFileSymbol(I.class)
getContainingJvmClassName: I
getContainingModule: KtLibraryModule "Library main"
deprecationStatus: null
getterDeprecationStatus: null
javaGetterName: getP
javaSetterName: null
setterDeprecationStatus: null
KtConstructorSymbol:
annotationsList: []
callableIdIfNonLocal: null
containingClassIdIfNonLocal: I
contextReceivers: []
hasStableParameterNames: true
isActual: false
isExpect: false
isExtension: false
isPrimary: true
origin: SOURCE
receiverParameter: null
returnType: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: I
symbolKind: CLASS_MEMBER
typeParameters: []
valueParameters: [
KtValueParameterSymbol:
annotationsList: []
callableIdIfNonLocal: null
contextReceivers: []
generatedPrimaryConstructorProperty: null
hasDefaultValue: false
isCrossinline: false
isExtension: false
isImplicitLambdaParameter: false
isNoinline: false
isVararg: false
name: p
origin: SOURCE
receiverParameter: null
returnType: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: A
symbolKind: LOCAL
typeParameters: []
getContainingFileSymbol: KtFileSymbol(I.class)
getContainingJvmClassName: I
getContainingModule: KtLibraryModule "Library main"
deprecationStatus: null
]
visibility: Public
getContainingFileSymbol: KtFileSymbol(I.class)
getContainingJvmClassName: I
getContainingModule: KtLibraryModule "Library main"
deprecationStatus: null
@@ -0,0 +1,16 @@
// IGNORE_FE10
// MODULE: main
// MODULE_KIND: LibraryBinary
// FILE: A.kt
interface A {
var Int.zoo: Unit
fun foo()
fun Int.smth(): Short
val foo: Int
var bar: Long
val Int.doo: String
}
class I(private val p: A) : A by p
// class: I
@@ -0,0 +1,12 @@
<expr>
class I(private val p: A) : A by p
</expr>
interface A {
var Int.zoo: Unit
fun foo()
fun Int.smth(): Short
val foo: Int
var bar: Long
val Int.doo: String
}
@@ -0,0 +1,50 @@
KT element: KtClass
FIR element: FirRegularClassImpl
FIR source kind: KtRealSourceElementKind
FIR element rendered:
public final [ResolvedTo(BODY_RESOLVE)] [DelegateFieldsMapKey={0=FirFieldSymbol /I.$$delegate_0}] class I : R|A| {
public [ResolvedTo(BODY_RESOLVE)] [ContainingClassKey=I] constructor([ResolvedTo(BODY_RESOLVE)] [CorrespondingProperty=/I.p] p: R|A|): R|I| {
super<R|kotlin/Any|>()
}
private final [ResolvedTo(BODY_RESOLVE)] field $$delegate_0: R|A| = R|<local>/p|
private final [ResolvedTo(BODY_RESOLVE)] [IsFromPrimaryConstructor=true] val p: R|A| = R|<local>/p|
private [ResolvedTo(BODY_RESOLVE)] [ContainingClassKey=I] get(): R|A|
}
FIR FILE:
FILE: [ResolvedTo(IMPORTS)] delegate.kt
public final [ResolvedTo(BODY_RESOLVE)] [DelegateFieldsMapKey={0=FirFieldSymbol /I.$$delegate_0}] class I : R|A| {
public [ResolvedTo(BODY_RESOLVE)] [ContainingClassKey=I] constructor([ResolvedTo(BODY_RESOLVE)] [CorrespondingProperty=/I.p] p: R|A|): R|I| {
super<R|kotlin/Any|>()
}
private final [ResolvedTo(BODY_RESOLVE)] field $$delegate_0: R|A| = R|<local>/p|
private final [ResolvedTo(BODY_RESOLVE)] [IsFromPrimaryConstructor=true] val p: R|A| = R|<local>/p|
private [ResolvedTo(BODY_RESOLVE)] [ContainingClassKey=I] get(): R|A|
}
public abstract [ResolvedTo(STATUS)] interface A : R|kotlin/Any| {
public abstract [ResolvedTo(STATUS)] var R|kotlin/Int|.zoo: R|kotlin/Unit|
public [ResolvedTo(STATUS)] [ContainingClassKey=A] get(): R|kotlin/Unit|
public [ResolvedTo(STATUS)] [ContainingClassKey=A] set([ResolvedTo(STATUS)] value: R|kotlin/Unit|): R|kotlin/Unit|
public abstract [ResolvedTo(STATUS)] fun foo(): R|kotlin/Unit|
public abstract [ResolvedTo(STATUS)] fun R|kotlin/Int|.smth(): R|kotlin/Short|
public abstract [ResolvedTo(STATUS)] val foo: R|kotlin/Int|
public [ResolvedTo(STATUS)] [ContainingClassKey=A] get(): R|kotlin/Int|
public abstract [ResolvedTo(STATUS)] var bar: R|kotlin/Long|
public [ResolvedTo(STATUS)] [ContainingClassKey=A] get(): R|kotlin/Long|
public [ResolvedTo(STATUS)] [ContainingClassKey=A] set([ResolvedTo(STATUS)] value: R|kotlin/Long|): R|kotlin/Unit|
public abstract [ResolvedTo(STATUS)] val R|kotlin/Int|.doo: R|kotlin/String|
public [ResolvedTo(STATUS)] [ContainingClassKey=A] get(): R|kotlin/String|
}
@@ -0,0 +1,11 @@
// DECLARATION_TYPE: org.jetbrains.kotlin.psi.KtClass
class I(private val p: A) : A by p
interface A {
var Int.zoo: Unit
fun foo()
fun Int.smth(): Short
val foo: Int
var bar: Long
val Int.doo: String
}
@@ -0,0 +1,16 @@
KT element: KtClass
KT element text:
public final class I public constructor(p: A) : A {
private final val p: A /* compiled code */
}
FIR element: FirRegularClassImpl
FIR source kind: KtRealSourceElementKind
FIR element rendered:
public final [ResolvedTo(BODY_RESOLVE)] class I : R|A| {
private final [ResolvedTo(BODY_RESOLVE)] val p: R|A|
public [ResolvedTo(BODY_RESOLVE)] [ContainingClassKey=I] constructor([ResolvedTo(BODY_RESOLVE)] p: R|A|): R|I|
}
@@ -6,7 +6,7 @@
package org.jetbrains.kotlin.analysis.low.level.api.fir
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.analysis.low.level.api.fir.test.base.AbstractLowLevelApiSingleFileTest
import org.jetbrains.kotlin.analysis.low.level.api.fir.test.base.AbstractLowLevelApiLastModuleFirstFileTest
import org.jetbrains.kotlin.analysis.low.level.api.fir.test.configurators.AnalysisApiFirLibraryBinaryTestConfigurator
import org.jetbrains.kotlin.analysis.low.level.api.fir.util.FirDeclarationForCompiledElementSearcher
import org.jetbrains.kotlin.analysis.project.structure.ProjectStructureProvider
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.test.services.TestServices
import org.jetbrains.kotlin.test.services.assertions
import org.jetbrains.kotlin.test.services.service
abstract class AbstractLibraryGetOrBuildFirTest : AbstractLowLevelApiSingleFileTest() {
abstract class AbstractLibraryGetOrBuildFirTest : AbstractLowLevelApiLastModuleFirstFileTest() {
override val configurator = AnalysisApiFirLibraryBinaryTestConfigurator
override fun configureTest(builder: TestConfigurationBuilder) {
builder.forTestsMatching("analysis/low-level-api-fir/testData/getOrBuildFirBinary/js/*") {
@@ -24,6 +24,12 @@ public class LibraryGetOrBuildFirTestGenerated extends AbstractLibraryGetOrBuild
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/low-level-api-fir/testData/getOrBuildFirBinary"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@Test
@TestMetadata("delegate.kt")
public void testDelegate() throws Exception {
runTest("analysis/low-level-api-fir/testData/getOrBuildFirBinary/delegate.kt");
}
@Test
@TestMetadata("enumEntry.kt")
public void testEnumEntry() throws Exception {
@@ -1247,6 +1247,12 @@ public class OutOfContentRootGetOrBuildFirTestGenerated extends AbstractOutOfCon
runTest("analysis/low-level-api-fir/testData/getOrBuildFir/wholeDeclaration/classTypeParemeter.kt");
}
@Test
@TestMetadata("delegate.kt")
public void testDelegate() throws Exception {
runTest("analysis/low-level-api-fir/testData/getOrBuildFir/wholeDeclaration/delegate.kt");
}
@Test
@TestMetadata("enum.kt")
public void testEnum() throws Exception {
@@ -1247,6 +1247,12 @@ public class SourceGetOrBuildFirTestGenerated extends AbstractSourceGetOrBuildFi
runTest("analysis/low-level-api-fir/testData/getOrBuildFir/wholeDeclaration/classTypeParemeter.kt");
}
@Test
@TestMetadata("delegate.kt")
public void testDelegate() throws Exception {
runTest("analysis/low-level-api-fir/testData/getOrBuildFir/wholeDeclaration/delegate.kt");
}
@Test
@TestMetadata("enum.kt")
public void testEnum() throws Exception {