[LL API] Check declaration resolution status in 'ContextCollector' tests

This commit is contained in:
Yan Zhulanow
2023-08-04 22:13:31 +09:00
committed by Space Team
parent ee22cc08d1
commit 6c26aeeb97
12 changed files with 203 additions and 18 deletions
@@ -26,4 +26,18 @@ Tower Data Context:
Type: Bar
Label: Bar
Element 9
Scope: FirLocalScope
Scope: FirLocalScope
FILE: [ResolvedTo(IMPORTS)] contextReceivers.kt
public abstract [ResolvedTo(STATUS)] interface Foo : R|kotlin/Any| {
public abstract [ResolvedTo(CONTRACTS)] fun foo(): R|kotlin/Int|
}
public abstract [ResolvedTo(STATUS)] interface Bar : R|kotlin/Any| {
public abstract [ResolvedTo(CONTRACTS)] fun bar(): R|kotlin/Int|
}
context(R|Foo|, R|Bar|)
public final [ResolvedTo(BODY_RESOLVE)] fun test(): R|kotlin/Unit| {
this@R|/test|.R|/Foo.foo|().R|kotlin/Int.plus|(this@R|/test|.R|/Bar.bar|())
}
@@ -27,4 +27,21 @@ Tower Data Context:
Element 9
Scope: FirLocalScope
Element 10
Scope: FirLocalScope
Scope: FirLocalScope
FILE: [ResolvedTo(IMPORTS)] contextReceiversClass.kt
public abstract [ResolvedTo(STATUS)] interface Foo : R|kotlin/Any| {
public abstract [ResolvedTo(CONTRACTS)] fun foo(): R|kotlin/Int|
}
context(R|Foo|)
public final [ResolvedTo(STATUS)] class Test : R|kotlin/Any| {
public [ResolvedTo(STATUS)] constructor(): R|Test| {
LAZY_super<R|kotlin/Any|>
}
public final [ResolvedTo(BODY_RESOLVE)] fun test(): R|kotlin/Unit| {
this@R|/Test|.R|/Foo.foo|()
}
}
@@ -20,4 +20,11 @@ Tower Data Context:
FirNamedFunctionSymbol public final fun R|kotlin/String|.test(): R|kotlin/Unit|
Type: kotlin/String
Element 9
Scope: FirLocalScope
Scope: FirLocalScope
FILE: [ResolvedTo(IMPORTS)] extensionFunction.kt
public final [ResolvedTo(BODY_RESOLVE)] fun R|kotlin/String|.test(): R|kotlin/Unit| {
R|/consume|(this@R|/test|)
}
public final [ResolvedTo(CONTRACTS)] fun consume([ResolvedTo(CONTRACTS)] obj: R|kotlin/Any|): R|kotlin/Unit| {
}
@@ -32,4 +32,20 @@ Tower Data Context:
FirAnonymousFunctionSymbol num@fun R|kotlin/Int|.<anonymous>(): R|kotlin/Unit| <inline=NoInline>
Type: kotlin/Int
Element 14
Scope: FirLocalScope
Scope: FirLocalScope
FILE: [ResolvedTo(IMPORTS)] extensionLambdas.kt
public final [ResolvedTo(BODY_RESOLVE)] fun test(): R|kotlin/Unit| {
R|/block|<R|kotlin/String|>(String(foo), <L> = [ResolvedTo(BODY_RESOLVE)] foo@fun R|kotlin/String|.<anonymous>(): R|kotlin/Unit| <inline=NoInline> {
R|/block|<R|kotlin/Int|>(Int(42), <L> = [ResolvedTo(BODY_RESOLVE)] num@fun R|kotlin/Int|.<anonymous>(): R|kotlin/Unit| <inline=NoInline> {
R|/consume|(this@R|special/anonymous|.R|kotlin/String.length|.R|kotlin/Int.plus|(this@R|special/anonymous|))
}
)
}
)
}
public final [ResolvedTo(CONTRACTS)] fun <[ResolvedTo(CONTRACTS)] T> block([ResolvedTo(CONTRACTS)] reciever: R|T|, [ResolvedTo(CONTRACTS)] block: R|T.() -> kotlin/Unit|): R|kotlin/Unit| {
receiver#.block#()
}
public final [ResolvedTo(CONTRACTS)] fun consume([ResolvedTo(CONTRACTS)] num: R|kotlin/Int|): R|kotlin/Unit| {
}
@@ -20,7 +20,7 @@ Tower Data Context:
Element 8
Scope: FirNestedClassifierScopeImpl
Classifiers:
FirRegularClassSymbol public final inner class Bar<B, F> : R|kotlin/Any|
FirRegularClassSymbol public final inner class Bar<B, Outer(F)> : R|kotlin/Any|
Element 9
Implicit receiver:
FirRegularClassSymbol public final class Foo<F> : R|kotlin/Any|
@@ -31,7 +31,7 @@ Tower Data Context:
FirTypeParameterSymbol B
Element 11
Implicit receiver:
FirRegularClassSymbol public final inner class Bar<B, F> : R|kotlin/Any|
FirRegularClassSymbol public final inner class Bar<B, Outer(F)> : R|kotlin/Any|
Type: test/Foo.Bar<B, F>
Element 12
Scope: FirLocalScope
@@ -39,4 +39,25 @@ Tower Data Context:
FirValueParameterSymbol b: R|B|
FirValueParameterSymbol f: R|F|
Element 13
Scope: FirLocalScope
Scope: FirLocalScope
FILE: [ResolvedTo(IMPORTS)] innerClasses.kt
public final [ResolvedTo(STATUS)] class Foo<[ResolvedTo(STATUS)] F> : R|kotlin/Any| {
public [ResolvedTo(STATUS)] constructor<[ResolvedTo(STATUS)] F>(): R|test/Foo<F>| {
LAZY_super<R|kotlin/Any|>
}
public final inner [ResolvedTo(STATUS)] class Bar<[ResolvedTo(STATUS)] B, [ResolvedTo(STATUS)] Outer(F)> : R|kotlin/Any| {
public [ResolvedTo(STATUS)] test/Foo<F>.constructor<[ResolvedTo(STATUS)] B>(): R|test/Foo.Bar<B, F>| {
LAZY_super<R|kotlin/Any|>
}
public final [ResolvedTo(BODY_RESOLVE)] fun test([ResolvedTo(BODY_RESOLVE)] f: R|F|, [ResolvedTo(BODY_RESOLVE)] b: R|B|): R|kotlin/Unit| {
R|test/consume<Inapplicable(INAPPLICABLE): test/consume>#|(R|<local>/f|)
}
}
}
public final [ResolvedTo(CONTRACTS)] fun consume([ResolvedTo(CONTRACTS)] obj: R|kotlin/Any|): R|kotlin/Unit| {
}
@@ -28,4 +28,18 @@ Tower Data Context:
Properties:
FirValueParameterSymbol n: R|kotlin/Int|
Element 12
Scope: FirLocalScope
Scope: FirLocalScope
FILE: [ResolvedTo(IMPORTS)] lambdaArguments.kt
public final [ResolvedTo(BODY_RESOLVE)] fun test(): R|kotlin/Unit| {
R|/block|<R|kotlin/String|>(String(foo), <L> = [ResolvedTo(BODY_RESOLVE)] block@fun <anonymous>([ResolvedTo(BODY_RESOLVE)] s: R|kotlin/String|): R|kotlin/Unit| <inline=NoInline> {
R|/block|<R|kotlin/Int|>(Int(42), <L> = [ResolvedTo(BODY_RESOLVE)] block@fun <anonymous>([ResolvedTo(BODY_RESOLVE)] n: R|kotlin/Int|): R|kotlin/Unit| <inline=NoInline> {
R|<local>/s|.R|kotlin/String.length|.R|kotlin/Int.plus|(R|<local>/n|)
}
)
}
)
}
public final [ResolvedTo(CONTRACTS)] fun <[ResolvedTo(CONTRACTS)] T> block([ResolvedTo(CONTRACTS)] obj: R|T|, [ResolvedTo(CONTRACTS)] block: R|(T) -> kotlin/Unit|): R|kotlin/Unit| {
block#(obj#)
}
@@ -30,4 +30,25 @@ Tower Data Context:
Properties:
FirValueParameterSymbol b: R|B|
Element 11
Scope: FirLocalScope
Scope: FirLocalScope
FILE: [ResolvedTo(IMPORTS)] nestedClasses.kt
public final [ResolvedTo(STATUS)] class Foo<[ResolvedTo(STATUS)] F> : R|kotlin/Any| {
public [ResolvedTo(STATUS)] constructor<[ResolvedTo(STATUS)] F>(): R|test/Foo<F>| {
LAZY_super<R|kotlin/Any|>
}
public final [ResolvedTo(STATUS)] class Bar<[ResolvedTo(STATUS)] B> : R|kotlin/Any| {
public [ResolvedTo(STATUS)] constructor<[ResolvedTo(STATUS)] B>(): R|test/Foo.Bar<B>| {
LAZY_super<R|kotlin/Any|>
}
public final [ResolvedTo(BODY_RESOLVE)] fun test([ResolvedTo(BODY_RESOLVE)] b: R|B|): R|kotlin/Unit| {
R|test/consume<Inapplicable(INAPPLICABLE): test/consume>#|(R|<local>/b|)
}
}
}
public final [ResolvedTo(CONTRACTS)] fun consume([ResolvedTo(CONTRACTS)] obj: R|kotlin/Any|): R|kotlin/Unit| {
}
@@ -7,4 +7,13 @@ class Foo {
val x = 1.0f
<expr>print(x)</expr>
}
}
class Unrelated {
val unrelatedMember: Boolean
get() = true
}
fun unrelatedFunction(): Int {
return "foo".length
}
@@ -24,4 +24,30 @@ Tower Data Context:
Element 9
Scope: FirLocalScope
Properties:
FirPropertySymbol lval x: R|kotlin/Float|
FirPropertySymbol lval x: R|kotlin/Float|
FILE: [ResolvedTo(IMPORTS)] simple.kt
public final [ResolvedTo(STATUS)] class Foo : R|kotlin/Any| {
public [ResolvedTo(STATUS)] constructor(): R|foo/Foo| {
LAZY_super<R|kotlin/Any|>
}
public final [ResolvedTo(STATUS)] val a: R|kotlin/Int|
public [ResolvedTo(STATUS)] get(): R|kotlin/Int|
public final [ResolvedTo(BODY_RESOLVE)] fun foo([ResolvedTo(BODY_RESOLVE)] p: R|kotlin/String|): R|kotlin/Unit| {
[ResolvedTo(BODY_RESOLVE)] lval x: R|kotlin/Float| = Float(1.0)
<Unresolved name: print>#(R|<local>/x|)
}
}
public? final? [ResolvedTo(RAW_FIR)] class Unrelated : R|kotlin/Any| {
public? [ResolvedTo(RAW_FIR)] constructor(): R|foo/Unrelated| {
LAZY_super<R|kotlin/Any|>
}
public? final? [ResolvedTo(RAW_FIR)] val unrelatedMember: Boolean
public? [ResolvedTo(RAW_FIR)] get(): Boolean { LAZY_BLOCK }
}
public? final? [ResolvedTo(RAW_FIR)] fun unrelatedFunction(): Int { LAZY_BLOCK }
@@ -25,4 +25,18 @@ Smart Casts:
FirValueParameterSymbol obj: R|kotlin/Any|
Types:
Foo
kotlin/Any
kotlin/Any
FILE: [ResolvedTo(IMPORTS)] smartCastArgument.kt
public abstract [ResolvedTo(STATUS)] interface Foo : R|kotlin/Any| {
}
public final [ResolvedTo(BODY_RESOLVE)] fun test([ResolvedTo(BODY_RESOLVE)] obj: R|kotlin/Any|): R|kotlin/Unit| {
when () {
(R|<local>/obj| is R|Foo|) -> {
R|/consume|(R|<local>/obj|)
}
}
}
public final [ResolvedTo(CONTRACTS)] fun consume([ResolvedTo(CONTRACTS)] obj: R|kotlin/Any|): R|kotlin/Unit| {
}
@@ -28,4 +28,25 @@ Smart Casts:
Types:
Foo
kotlin/Any
Bar
Bar
FILE: [ResolvedTo(IMPORTS)] smartCastReceiverArgument.kt
public abstract [ResolvedTo(STATUS)] interface Foo : R|kotlin/Any| {
}
public abstract [ResolvedTo(STATUS)] interface Bar : R|kotlin/Any| {
}
public final [ResolvedTo(BODY_RESOLVE)] fun test([ResolvedTo(BODY_RESOLVE)] obj: R|kotlin/Any|): R|kotlin/Unit| {
when () {
(R|<local>/obj| is R|Foo|) -> {
when () {
(R|<local>/obj| is R|Bar|) -> {
R|<local>/obj|.R|/consume|(R|<local>/obj|)
}
}
}
}
}
public final [ResolvedTo(CONTRACTS)] fun R|Bar|.consume([ResolvedTo(CONTRACTS)] obj: R|Foo|): R|kotlin/Unit| {
}
@@ -51,17 +51,22 @@ abstract class AbstractContextCollectorTest : AbstractAnalysisApiBasedSingleModu
val elementContext = ContextCollector.process(firFile, sessionHolder, targetElement)
?: error("Context not found for element $targetElement")
val actualText = ElementContextRenderer.render(elementContext)
val firRenderer = FirRenderer.withResolvePhase()
val actualText = buildString {
ElementContextRenderer.render(elementContext, this)
appendLine()
append(firRenderer.renderElementAsString(firFile, trim = true))
}
testServices.assertions.assertEqualsToTestDataFileSibling(actualText)
}
}
private object ElementContextRenderer {
fun render(context: ContextCollector.Context): String {
return buildString {
renderTowerDataContext(context.towerDataContext)
renderSmartCasts(context.smartCasts)
}.trim()
fun render(context: ContextCollector.Context, builder: StringBuilder) = with(builder) {
renderTowerDataContext(context.towerDataContext)
renderSmartCasts(context.smartCasts)
}
private fun StringBuilder.renderTowerDataContext(towerDataContext: FirTowerDataContext) {