[LL FIR] AbstractInBlockModificationTest: cover getNonLocalReanalyzableContainingDeclaration

^KT-60518
This commit is contained in:
Dmitrii Gridin
2023-07-18 15:23:56 +02:00
committed by Space Team
parent c2fd245ca1
commit f0d8a1cbe9
84 changed files with 126 additions and 117 deletions
@@ -1,9 +1,9 @@
import kotlin.contracts.InvocationKind import kotlin.contracts.InvocationKind
inline fun f<caret>oo(block: () -> Unit) { inline fun foo(block: () -> Unit) {
kotlin.contracts.contract { kotlin.contracts.contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE) callsInPlace(block, InvocationKind.EXACTLY_ONCE)
} }
block() <expr>block()</expr>
} }
@@ -2,6 +2,6 @@ class MyProducer {
fun produce(): Int = 4 fun produce(): Int = 4
} }
fun MyProducer.test<caret>Fun(param1: Int = produce()) { fun MyProducer.testFun(param1: Int = produce()) {
<expr>42</expr>
} }
@@ -1,5 +1,6 @@
BEFORE MODIFICATION: BEFORE MODIFICATION:
public final [ResolvedTo(BODY_RESOLVE)] fun R|MyProducer|.testFun([ResolvedTo(BODY_RESOLVE)] param1: R|kotlin/Int| = this@R|/testFun|.R|/MyProducer.produce|()): R|kotlin/Unit| { public final [ResolvedTo(BODY_RESOLVE)] fun R|MyProducer|.testFun([ResolvedTo(BODY_RESOLVE)] param1: R|kotlin/Int| = this@R|/testFun|.R|/MyProducer.produce|()): R|kotlin/Unit| {
Int(42)
} }
AFTER MODIFICATION: AFTER MODIFICATION:
@@ -1,5 +1,5 @@
fun test<caret>Fun(param1: Int, param2: String = "str", param3: List<Int> = myList()) { fun testFun(param1: Int, param2: String = "str", param3: List<Int> = myList()) {
<expr>42</expr>
} }
fun myList(): List<Int> fun myList(): List<Int>
@@ -1,5 +1,6 @@
BEFORE MODIFICATION: BEFORE MODIFICATION:
public final [ResolvedTo(BODY_RESOLVE)] fun testFun([ResolvedTo(BODY_RESOLVE)] param1: R|kotlin/Int|, [ResolvedTo(BODY_RESOLVE)] param2: R|kotlin/String| = String(str), [ResolvedTo(BODY_RESOLVE)] param3: R|kotlin/collections/List<kotlin/Int>| = R|/myList|()): R|kotlin/Unit| { public final [ResolvedTo(BODY_RESOLVE)] fun testFun([ResolvedTo(BODY_RESOLVE)] param1: R|kotlin/Int|, [ResolvedTo(BODY_RESOLVE)] param2: R|kotlin/String| = String(str), [ResolvedTo(BODY_RESOLVE)] param3: R|kotlin/collections/List<kotlin/Int>| = R|/myList|()): R|kotlin/Unit| {
Int(42)
} }
AFTER MODIFICATION: AFTER MODIFICATION:
@@ -1,12 +1,12 @@
import kotlin.contracts.contract import kotlin.contracts.contract
class A { class A {
fun <caret>x() { fun x() {
contract { contract {
req req
} }
val a = doSmth("str") val a = <expr>doSmth("str")</expr>
} }
} }
@@ -1,8 +1,9 @@
import kotlin.contracts.* import kotlin.contracts.*
class A { class A {
fun passLa<caret>mbdaValue(l: ContractBuilder.() -> Unit) { fun passLambdaValue(l: ContractBuilder.() -> Unit) {
contract(l) contract(l)
<expr>42</expr>
} }
} }
@@ -8,6 +8,7 @@ public final [ResolvedTo(BODY_RESOLVE)] fun passLambdaValue([ResolvedTo(BODY_RES
contract#(l#) contract#(l#)
} }
Int(42)
} }
AFTER MODIFICATION: AFTER MODIFICATION:
@@ -8,6 +8,7 @@ public final [ResolvedTo(BODY_RESOLVE)] fun passLambdaValue([ResolvedTo(BODY_RES
R|kotlin/contracts/contract|(R|<local>/l|) R|kotlin/contracts/contract|(R|<local>/l|)
} }
Int(42)
} }
AFTER MODIFICATION: AFTER MODIFICATION:
@@ -1,10 +1,10 @@
class A { class A {
fun <caret>x() { fun x() {
contract { contract {
req req
} }
val a = doSmth("str") val <expr>a</expr> = doSmth("str")
} }
} }
@@ -1,6 +1,6 @@
class A { class A {
fun <caret>x(): Int { fun x(): Int {
return doSmth("str") return <expr>doSmth</expr>("str")
} }
} }
@@ -1,6 +1,6 @@
class A { class A {
fun <caret>x() { fun x() {
val a = doSmth("str") val <expr>a</expr> = doSmth("str")
} }
} }
@@ -1,6 +1,6 @@
class A { class A {
fun <caret>() { fun () {
val a = doSmth("str") val <expr>a</expr> = doSmth("str")
} }
} }
@@ -1,5 +1,5 @@
class A { class A {
fun <caret>x(): Int = doSmth("str") fun x(): Int = <expr>doSmth</expr>("str")
} }
fun doSmth(i: String) = 4 fun doSmth(i: String) = 4
@@ -1,5 +1,5 @@
class A { class A {
fun <caret>(): Int = doSmth("str") fun (): Int = <expr>doSmth</expr>("str")
} }
fun doSmth(i: String) = 4 fun doSmth(i: String) = 4
@@ -1,5 +1,5 @@
class A { class A {
fun <caret>() = doSmth("str") fun () = <expr>doSmth</expr>("str")
} }
fun doSmth(i: String) = 4 fun doSmth(i: String) = 4
@@ -1 +1 @@
IN-BLOCK MODIFICATION IS NOT APPLICABLE FOR THIS KtNamedFunction DECLARATION IN-BLOCK MODIFICATION IS NOT APPLICABLE FOR THIS PLACE
@@ -1,5 +1,5 @@
class A { class A {
fun <caret>x() = doSmth("str") fun x() = <expr>doSmth</expr>("str")
} }
fun doSmth(i: String) = 4 fun doSmth(i: String) = 4
@@ -1 +1 @@
IN-BLOCK MODIFICATION IS NOT APPLICABLE FOR THIS KtNamedFunction DECLARATION IN-BLOCK MODIFICATION IS NOT APPLICABLE FOR THIS PLACE
@@ -2,12 +2,12 @@ import kotlin.contracts.contract
class A { class A {
var x: Int var x: Int
ge<caret>t() { get() {
contract { contract {
req req
} }
fun doSmth(i: String) = 4 fun <expr>doSmth</expr>(i: String) = 4
return doSmth("str") return doSmth("str")
} }
set(value) = Unit set(value) = Unit
@@ -2,12 +2,12 @@ import kotlin.contracts.contract
class A { class A {
var : Int var : Int
ge<caret>t() { get() {
contract { contract {
req req
} }
fun doSmth(i: String) = 4 fun <expr>doSmth</expr>(i: String) = 4
return doSmth("str") return doSmth("str")
} }
set(value) = Unit set(value) = Unit
@@ -1,7 +1,7 @@
class A { class A {
val x: Int val x: Int
ge<caret>t() { get() {
fun doSmth(i: String) = 4 fun doSmth(i: String) = <expr>4</expr>
return doSmth("str") return doSmth("str")
} }
} }
@@ -1,5 +1,5 @@
class A { class A {
val x: Int ge<caret>t() = doSmth("str") val x: Int get() = <expr>doSmth</expr>("str")
} }
fun doSmth(i: String) = 4 fun doSmth(i: String) = 4
@@ -1,5 +1,5 @@
class A { class A {
val : Int ge<caret>t() = doSmth("str") val : Int get() = <expr>doSmth</expr>("str")
} }
fun doSmth(i: String) = 4 fun doSmth(i: String) = 4
@@ -1,7 +1,7 @@
class A { class A {
val x val x
g<caret>et() { get() {
return doSmth("str") return <expr>doSmth</expr>("str")
} }
} }
@@ -1,5 +1,5 @@
class A { class A {
val x ge<caret>t() = doSmth("str") val x get() = <expr>doSmth</expr>("str")
} }
fun doSmth(i: String) = 4 fun doSmth(i: String) = 4
@@ -1 +1 @@
IN-BLOCK MODIFICATION IS NOT APPLICABLE FOR THIS KtPropertyAccessor DECLARATION IN-BLOCK MODIFICATION IS NOT APPLICABLE FOR THIS PLACE
@@ -1,6 +1,6 @@
class A { class A {
val <caret>x: Int by lazy { val x: Int by lazy {
fun doSmth(i: String) = 4 fun <expr>doSmth</expr>(i: String) = 4
doSmth("str") doSmth("str")
} }
} }
@@ -1 +1 @@
IN-BLOCK MODIFICATION IS NOT APPLICABLE FOR THIS KtProperty DECLARATION IN-BLOCK MODIFICATION IS NOT APPLICABLE FOR THIS PLACE
@@ -1,6 +1,6 @@
class A { class A {
val <caret>: Int by lazy { val : Int by lazy {
fun doSmth(i: String) = 4 fun doSmth(i: String) = 4
doSmth("str") <expr>doSmth</expr>("str")
} }
} }
@@ -1 +1 @@
IN-BLOCK MODIFICATION IS NOT APPLICABLE FOR THIS KtProperty DECLARATION IN-BLOCK MODIFICATION IS NOT APPLICABLE FOR THIS PLACE
@@ -1,3 +1,3 @@
class A { class A {
val <caret>x: Int by ErrorDelegate() val x: Int by <expr>ErrorDelegate</expr>()
} }
@@ -1 +1 @@
IN-BLOCK MODIFICATION IS NOT APPLICABLE FOR THIS KtProperty DECLARATION IN-BLOCK MODIFICATION IS NOT APPLICABLE FOR THIS PLACE
@@ -1,6 +1,6 @@
class A { class A {
val x<caret>: Int = run { val x: Int = run {
fun doSmth(i: String) = 4 fun doSmth(i: String) = 4
doSmth("str") <expr>doSmth</expr>("str")
} }
} }
@@ -1 +1 @@
IN-BLOCK MODIFICATION IS NOT APPLICABLE FOR THIS KtProperty DECLARATION IN-BLOCK MODIFICATION IS NOT APPLICABLE FOR THIS PLACE
@@ -1,6 +1,6 @@
class A { class A {
val <caret>: Int = run { val : Int = run {
fun doSmth(i: String) = 4 fun doSmth(i: String) = 4
doSmth("str") <expr>doSmth</expr>("str")
} }
} }
@@ -1 +1 @@
IN-BLOCK MODIFICATION IS NOT APPLICABLE FOR THIS KtProperty DECLARATION IN-BLOCK MODIFICATION IS NOT APPLICABLE FOR THIS PLACE
@@ -1,6 +1,6 @@
class A { class A {
val <caret>x by lazy { val x by lazy {
fun doSmth(i: String) = 4 fun doSmth(i: String) = 4
doSmth("str") <expr>doSmth</expr>("str")
} }
} }
@@ -1 +1 @@
IN-BLOCK MODIFICATION IS NOT APPLICABLE FOR THIS KtProperty DECLARATION IN-BLOCK MODIFICATION IS NOT APPLICABLE FOR THIS PLACE
@@ -1,3 +1,3 @@
class A { class A {
val <caret>x by ErrorDelegate() val x by <expr>ErrorDelegate</expr>()
} }
@@ -1 +1 @@
IN-BLOCK MODIFICATION IS NOT APPLICABLE FOR THIS KtProperty DECLARATION IN-BLOCK MODIFICATION IS NOT APPLICABLE FOR THIS PLACE
@@ -1,5 +1,5 @@
class A { class A {
val x<caret> = run { val x = run {
doSmth("str") <expr>doSmth</expr>("str")
} }
} }
@@ -1 +1 @@
IN-BLOCK MODIFICATION IS NOT APPLICABLE FOR THIS KtProperty DECLARATION IN-BLOCK MODIFICATION IS NOT APPLICABLE FOR THIS PLACE
@@ -1,7 +1,7 @@
class A { class A {
var x: Int = 1 var x: Int = 1
se<caret>t(value) { set(value) {
doSmth(value) <expr>doSmth</expr>(value)
} }
} }
@@ -1,7 +1,7 @@
class A { class A {
var : Int = 1 var : Int = 1
se<caret>t(value) { set(value) {
doSmth(value) <expr>doSmth</expr>(value)
} }
} }
@@ -1,6 +1,6 @@
class A { class A {
var x: Int = 1 var x: Int = 1
se<caret>t(value) = doSmth(value) set(value) = <expr>doSmth</expr>(value)
} }
fun doSmth(i: String) = 4 fun doSmth(i: String) = 4
@@ -1,6 +1,6 @@
class A { class A {
var : Int = 1 var : Int = 1
se<caret>t(value) = doSmth(value) set(value) = <expr>doSmth</expr>(value)
} }
fun doSmth(i: String) = 4 fun doSmth(i: String) = 4
@@ -1,8 +1,8 @@
class A { class A {
var x var x
get() = 1 get() = 1
s<caret>et(value) { set(value) {
doSmth(value) <expr>doSmth</expr>(value)
} }
} }
@@ -1,7 +1,7 @@
class A { class A {
var x var x
get() = 1 get() = 1
s<caret>et(value) = doSmth(value) set(value) = <expr>doSmth</expr>(value)
} }
fun doSmth(i: String) = 4 fun doSmth(i: String) = 4
@@ -1,9 +1,9 @@
fun fo<caret>o(arg: Any?, num: Int?, block: () -> Unit) contract [ fun foo(arg: Any?, num: Int?, block: () -> Unit) contract [
returns() implies (arg is String), returns() implies (arg is String),
returns() implies (num != null), returns() implies (num != null),
callsInPlace(block, InvocationKind.EXACTLY_ONCE) callsInPlace(block, InvocationKind.EXACTLY_ONCE)
] { ] {
require(arg is String) require(arg is String)
require(num != null) require(num != null)
block() <expr>block</expr>()
} }
@@ -1,5 +1,5 @@
fun <caret>() { fun () {
val a = doSmth("str") val a = <expr>doSmth</expr>("str")
} }
fun doSmth(i: String) = 4 fun doSmth(i: String) = 4
@@ -1,5 +1,5 @@
fun fo<caret>o(): Int { fun foo(): Int {
return doSmth("str") return <expr>doSmth</expr>("str")
} }
fun doSmth(i: String) = 4 fun doSmth(i: String) = 4
@@ -1,3 +1,3 @@
fun f<caret>oo(): Int = doSmth("str") fun foo(): Int = <expr>doSmth</expr>("str")
fun doSmth(i: String) = 4 fun doSmth(i: String) = 4
@@ -1,3 +1,3 @@
fun <caret>(): Int = doSmth("str") fun (): Int = <expr>doSmth</expr>("str")
fun doSmth(i: String) = 4 fun doSmth(i: String) = 4
@@ -1,3 +1,3 @@
fun <caret>() = doSmth("str") fun () = <expr>doSmth</expr>("str")
fun doSmth(i: String) = 4 fun doSmth(i: String) = 4
@@ -1 +1 @@
IN-BLOCK MODIFICATION IS NOT APPLICABLE FOR THIS KtNamedFunction DECLARATION IN-BLOCK MODIFICATION IS NOT APPLICABLE FOR THIS PLACE
@@ -1,5 +1,5 @@
fun f<caret>oo() { fun foo() {
doSmth("str") <expr>doSmth</expr>("str")
} }
fun doSmth(i: String) = 4 fun doSmth(i: String) = 4
@@ -1,3 +1,3 @@
fun fo<caret>o() = doSmth("str") fun foo() = <expr>doSmth</expr>("str")
fun doSmth(i: String) = 4 fun doSmth(i: String) = 4
@@ -1 +1 @@
IN-BLOCK MODIFICATION IS NOT APPLICABLE FOR THIS KtNamedFunction DECLARATION IN-BLOCK MODIFICATION IS NOT APPLICABLE FOR THIS PLACE
@@ -1,5 +1,5 @@
val x: Int val x: Int
ge<caret>t() { get() {
fun doSmth(i: String) = 4 fun doSmth(i: String) = 4
return doSmth("str") return <expr>doSmth</expr>("str")
} }
@@ -1,5 +1,5 @@
val : Int val : Int
ge<caret>t() { get() {
fun doSmth(i: String) = 4 fun doSmth(i: String) = 4
return doSmth("str") return <expr>doSmth</expr>("str")
} }
@@ -1,3 +1,3 @@
val x: Int g<caret>et() = doSmth("str") val x: Int get() = <expr>doSmth</expr>("str")
fun doSmth(i: String) = 4 fun doSmth(i: String) = 4
@@ -1,3 +1,3 @@
val : Int g<caret>et() = doSmth("str") val : Int get() = <expr>doSmth</expr>("str")
fun doSmth(i: String) = 4 fun doSmth(i: String) = 4
@@ -1,6 +1,6 @@
val x val x
g<caret>et() { get() {
return doSmth("str") return <expr>doSmth</expr>("str")
} }
fun doSmth(i: String) = 4 fun doSmth(i: String) = 4
@@ -1,3 +1,3 @@
val x get<caret>() = doSmth("str") val x get() = <expr>doSmth</expr>("str")
fun doSmth(i: String) = 4 fun doSmth(i: String) = 4
@@ -1 +1 @@
IN-BLOCK MODIFICATION IS NOT APPLICABLE FOR THIS KtPropertyAccessor DECLARATION IN-BLOCK MODIFICATION IS NOT APPLICABLE FOR THIS PLACE
@@ -1,4 +1,4 @@
val x<caret>: Int by lazy { val x: Int by lazy {
fun doSmth(i: String) = 4 fun doSmth(i: String) = 4
doSmth("str") <expr>doSmth</expr>("str")
} }
@@ -1,4 +1,4 @@
val <caret>: Int by lazy { val : Int by lazy {
fun doSmth(i: String) = 4 fun doSmth(i: String) = 4
doSmth("str") <expr>doSmth</expr>("str")
} }
@@ -1 +1 @@
val x<caret>: Int by ErrorDelegate() val x: Int by <expr>ErrorDelegate</expr>()
@@ -1,3 +1,3 @@
val <caret>x: Int = doSmth("str") val x: Int = <expr>doSmth</expr>("str")
fun doSmth(i: String) = 4 fun doSmth(i: String) = 4
@@ -1,3 +1,3 @@
val <caret>: Int = doSmth("str") val : Int = <expr>doSmth</expr>("str")
fun doSmth(i: String) = 4 fun doSmth(i: String) = 4
@@ -1,4 +1,4 @@
val x<caret> by lazy { val x by lazy {
fun doSmth(i: String) = 4 fun doSmth(i: String) = 4
doSmth("str") <expr>doSmth</expr>("str")
} }
@@ -1 +1 @@
IN-BLOCK MODIFICATION IS NOT APPLICABLE FOR THIS KtProperty DECLARATION IN-BLOCK MODIFICATION IS NOT APPLICABLE FOR THIS PLACE
@@ -1 +1 @@
val x<caret> by ErrorDelegate() val x by <expr>ErrorDelegate</expr>()
@@ -1 +1 @@
IN-BLOCK MODIFICATION IS NOT APPLICABLE FOR THIS KtProperty DECLARATION IN-BLOCK MODIFICATION IS NOT APPLICABLE FOR THIS PLACE
@@ -1,3 +1,3 @@
val x<caret> = doSmth("str") val x = <expr>doSmth</expr>("str")
fun doSmth(i: String) = 4 fun doSmth(i: String) = 4
@@ -1 +1 @@
IN-BLOCK MODIFICATION IS NOT APPLICABLE FOR THIS KtProperty DECLARATION IN-BLOCK MODIFICATION IS NOT APPLICABLE FOR THIS PLACE
@@ -1,6 +1,6 @@
var x: Int = 1 var x: Int = 1
se<caret>t(value) { set(value) {
doSmth(value) <expr>doSmth</expr>(value)
} }
fun doSmth(i: String): Unit = 4 fun doSmth(i: String): Unit = 4
@@ -1,6 +1,6 @@
var : Int = 1 var : Int = 1
se<caret>t(value) { set(value) {
doSmth(value) <expr>doSmth</expr>(value)
} }
fun doSmth(i: String): Unit = 4 fun doSmth(i: String): Unit = 4
@@ -1,4 +1,4 @@
var x: Int = 1 var x: Int = 1
se<caret>t(value) = doSmth(value) set(value) = <expr>doSmth</expr>(value)
fun doSmth(i: String): Unit = 4 fun doSmth(i: String): Unit = 4
@@ -1,4 +1,4 @@
var : Int = 1 var : Int = 1
se<caret>t(value) = doSmth(value) set(value) = <expr>doSmth</expr>(value)
fun doSmth(i: String): Unit = 4 fun doSmth(i: String): Unit = 4
@@ -1,7 +1,7 @@
val x val x
get() = 1 get() = 1
se<caret>t(value) { set(value) {
doSmth(value) <expr>doSmth</expr>(value)
} }
fun doSmth(i: String) = 4 fun doSmth(i: String) = 4
@@ -1,5 +1,5 @@
val x val x
get() = 1 get() = 1
se<caret>t(value) = doSmth(value) set(value) = <expr>doSmth</expr>(value)
fun doSmth(i: String) = 4 fun doSmth(i: String) = 4
@@ -24,9 +24,13 @@ import org.jetbrains.kotlin.test.services.assertions
abstract class AbstractInBlockModificationTest : AbstractLowLevelApiSingleFileTest() { abstract class AbstractInBlockModificationTest : AbstractLowLevelApiSingleFileTest() {
override fun doTestByFileStructure(ktFile: KtFile, moduleStructure: TestModuleStructure, testServices: TestServices) { override fun doTestByFileStructure(ktFile: KtFile, moduleStructure: TestModuleStructure, testServices: TestServices) {
val declaration = testServices.expressionMarkerProvider.getElementOfTypeAtCaret<KtDeclaration>(ktFile) val selectedElement = testServices.expressionMarkerProvider.getSelectedElementOfTypeByDirective(
val isSupposedToBeModified = declaration.isReanalyzableContainer() ktFile = ktFile,
val actual = if (isSupposedToBeModified) { module = moduleStructure.modules.last(),
)
val declaration = selectedElement.getNonLocalReanalyzableContainingDeclaration()
val actual = if (declaration != null) {
resolveWithCaches(ktFile) { firSession -> resolveWithCaches(ktFile) { firSession ->
val firDeclarationBefore = declaration.getOrBuildFirOfType<FirDeclaration>(firSession) val firDeclarationBefore = declaration.getOrBuildFirOfType<FirDeclaration>(firSession)
val declarationTextBefore = firDeclarationBefore.render() val declarationTextBefore = firDeclarationBefore.render()
@@ -52,7 +56,7 @@ abstract class AbstractInBlockModificationTest : AbstractLowLevelApiSingleFileTe
"BEFORE MODIFICATION:\n$declarationTextBefore\nAFTER MODIFICATION:\n$declarationTextAfterModification" "BEFORE MODIFICATION:\n$declarationTextBefore\nAFTER MODIFICATION:\n$declarationTextAfterModification"
} }
} else { } else {
"IN-BLOCK MODIFICATION IS NOT APPLICABLE FOR THIS ${declaration::class.simpleName} DECLARATION" "IN-BLOCK MODIFICATION IS NOT APPLICABLE FOR THIS PLACE"
} }
testServices.assertions.assertEqualsToTestDataFileSibling(actual) testServices.assertions.assertEqualsToTestDataFileSibling(actual)