[kotlin] Provide CFG facade for the extract function refactoring

This is the first implementation of a control flow graph facade for the
extract function IDE refactoring. The exact contents of
'KtDataFlowExitPointSnapshot' will be refined later.

^KT-65762 Fixed
This commit is contained in:
Yan Zhulanow
2024-03-05 01:44:32 +09:00
committed by Space Team
parent b032e647f7
commit 0fec50135f
165 changed files with 4351 additions and 1 deletions
@@ -0,0 +1,5 @@
fun test() {
<expr>fun(n: Int): Int {
return n + 1
}</expr>
}
@@ -0,0 +1,14 @@
KtDataFlowExitPointSnapshot:
defaultExpressionInfo = DefaultExpressionInfo:
expression = fun(n: Int): Int {
return n + 1
}
type = kotlin.Function1<kotlin.Int, kotlin.Int>
hasEscapingJumps = false
hasJumps = false
hasMultipleJumpKinds = false
hasMultipleJumpTargets = false
loopJumpExpressions = []
returnValueType = null
valuedReturnExpressions = []
variableReassignments = []
@@ -0,0 +1,5 @@
fun test() {
<expr>object {
fun foo() {}
}</expr>
}
@@ -0,0 +1,14 @@
KtDataFlowExitPointSnapshot:
defaultExpressionInfo = DefaultExpressionInfo:
expression = object {
fun foo() {}
}
type = <anonymous>
hasEscapingJumps = false
hasJumps = false
hasMultipleJumpKinds = false
hasMultipleJumpTargets = false
loopJumpExpressions = []
returnValueType = null
valuedReturnExpressions = []
variableReassignments = []
@@ -0,0 +1,17 @@
fun test() {
buildFoo {
<expr>value</expr> = produceString()
}
}
fun buildFoo(builder: Foo.() -> Unit): Foo {
val foo = Foo()
foo.builder()
return foo
}
fun Foo {
var value: String? = null
}
fun produceString(): String = ""
@@ -0,0 +1,10 @@
KtDataFlowExitPointSnapshot:
defaultExpressionInfo = null
hasEscapingJumps = false
hasJumps = false
hasMultipleJumpKinds = false
hasMultipleJumpTargets = false
loopJumpExpressions = []
returnValueType = null
valuedReturnExpressions = []
variableReassignments = []
@@ -0,0 +1,17 @@
fun test() {
buildFoo {
value = <expr>produceString()</expr>
}
}
fun buildFoo(builder: Foo.() -> Unit): Foo {
val foo = Foo()
foo.builder()
return foo
}
fun Foo {
var value: String? = null
}
fun produceString(): String = ""
@@ -0,0 +1,12 @@
KtDataFlowExitPointSnapshot:
defaultExpressionInfo = DefaultExpressionInfo:
expression = produceString()
type = kotlin.String
hasEscapingJumps = false
hasJumps = false
hasMultipleJumpKinds = false
hasMultipleJumpTargets = false
loopJumpExpressions = []
returnValueType = null
valuedReturnExpressions = []
variableReassignments = []
@@ -0,0 +1,7 @@
fun test(foo: Foo) {
foo.<expr>bar()</expr>
}
class Foo {
fun bar(): String {}
}
@@ -0,0 +1,12 @@
KtDataFlowExitPointSnapshot:
defaultExpressionInfo = DefaultExpressionInfo:
expression = bar()
type = kotlin.String
hasEscapingJumps = false
hasJumps = false
hasMultipleJumpKinds = false
hasMultipleJumpTargets = false
loopJumpExpressions = []
returnValueType = null
valuedReturnExpressions = []
variableReassignments = []
@@ -0,0 +1,7 @@
fun test() {
<expr>call()</expr>
}
fun call(): Foo? {
return null
}
@@ -0,0 +1,12 @@
KtDataFlowExitPointSnapshot:
defaultExpressionInfo = DefaultExpressionInfo:
expression = call()
type = ERROR CLASS: Symbol not found for Foo?
hasEscapingJumps = false
hasJumps = false
hasMultipleJumpKinds = false
hasMultipleJumpTargets = false
loopJumpExpressions = []
returnValueType = null
valuedReturnExpressions = []
variableReassignments = []
@@ -0,0 +1,9 @@
fun test(flag: Boolean) {
if (flag) <expr>{
consume(1)
}</expr> else {
consume(2)
}
}
fun consume(n: Int) {}
@@ -0,0 +1,10 @@
KtDataFlowExitPointSnapshot:
defaultExpressionInfo = null
hasEscapingJumps = false
hasJumps = false
hasMultipleJumpKinds = false
hasMultipleJumpTargets = false
loopJumpExpressions = []
returnValueType = null
valuedReturnExpressions = []
variableReassignments = []
@@ -0,0 +1,9 @@
// FILE: JavaClass.java
class FooJava {
String call() {}
}
// FILE: main.kt
fun text(foo: FooJava) {
<expr>foo.call()</expr>
}
@@ -0,0 +1,12 @@
KtDataFlowExitPointSnapshot:
defaultExpressionInfo = DefaultExpressionInfo:
expression = foo.call()
type = kotlin.String!
hasEscapingJumps = false
hasJumps = false
hasMultipleJumpKinds = false
hasMultipleJumpTargets = false
loopJumpExpressions = []
returnValueType = null
valuedReturnExpressions = []
variableReassignments = []
@@ -0,0 +1,6 @@
fun test(n: Int) <expr>{
consume(1)
consume(n)
}</expr>
fun consume(n: Int) {}
@@ -0,0 +1,10 @@
KtDataFlowExitPointSnapshot:
defaultExpressionInfo = null
hasEscapingJumps = false
hasJumps = false
hasMultipleJumpKinds = false
hasMultipleJumpTargets = false
loopJumpExpressions = []
returnValueType = null
valuedReturnExpressions = []
variableReassignments = []
@@ -0,0 +1,5 @@
fun test() {
<expr>call(1, "foo")</expr>
}
fun call(n: Int, text: String): Int = n
@@ -0,0 +1,12 @@
KtDataFlowExitPointSnapshot:
defaultExpressionInfo = DefaultExpressionInfo:
expression = call(1, "foo")
type = kotlin.Int
hasEscapingJumps = false
hasJumps = false
hasMultipleJumpKinds = false
hasMultipleJumpTargets = false
loopJumpExpressions = []
returnValueType = null
valuedReturnExpressions = []
variableReassignments = []
@@ -0,0 +1,7 @@
fun test(bar: String) {
consume("foo" <expr>join</expr> bar)
}
infix fun String.join(other: String): String = this + other
fun consume(text: String) {}
@@ -0,0 +1,10 @@
KtDataFlowExitPointSnapshot:
defaultExpressionInfo = null
hasEscapingJumps = false
hasJumps = false
hasMultipleJumpKinds = false
hasMultipleJumpTargets = false
loopJumpExpressions = []
returnValueType = null
valuedReturnExpressions = []
variableReassignments = []
@@ -0,0 +1,3 @@
fun test() {
<expr>{ n: Int -> n + 1 }</expr>
}
@@ -0,0 +1,12 @@
KtDataFlowExitPointSnapshot:
defaultExpressionInfo = DefaultExpressionInfo:
expression = { n: Int -> n + 1 }
type = kotlin.Function1<kotlin.Int, kotlin.Int>
hasEscapingJumps = false
hasJumps = false
hasMultipleJumpKinds = false
hasMultipleJumpTargets = false
loopJumpExpressions = []
returnValueType = null
valuedReturnExpressions = []
variableReassignments = []
@@ -0,0 +1,7 @@
fun test() {
<expr>call()</expr>
}
fun call(): String? {
return null
}
@@ -0,0 +1,12 @@
KtDataFlowExitPointSnapshot:
defaultExpressionInfo = DefaultExpressionInfo:
expression = call()
type = kotlin.String?
hasEscapingJumps = false
hasJumps = false
hasMultipleJumpKinds = false
hasMultipleJumpTargets = false
loopJumpExpressions = []
returnValueType = null
valuedReturnExpressions = []
variableReassignments = []
@@ -0,0 +1,5 @@
// WITH_STDLIB
fun test(): Pair<String, Int> {
return <expr>kotlin</expr>.Pair("foo", 1)
}
@@ -0,0 +1,10 @@
KtDataFlowExitPointSnapshot:
defaultExpressionInfo = null
hasEscapingJumps = false
hasJumps = false
hasMultipleJumpKinds = false
hasMultipleJumpTargets = false
loopJumpExpressions = []
returnValueType = null
valuedReturnExpressions = []
variableReassignments = []
@@ -0,0 +1,5 @@
fun <T> test(t: T) {
val a = <expr>foo<T>(t)</expr>
}
fun <T> foo(obj: T): Int = 0
@@ -0,0 +1,12 @@
KtDataFlowExitPointSnapshot:
defaultExpressionInfo = DefaultExpressionInfo:
expression = foo<T>(t)
type = kotlin.Int
hasEscapingJumps = false
hasJumps = false
hasMultipleJumpKinds = false
hasMultipleJumpTargets = false
loopJumpExpressions = []
returnValueType = null
valuedReturnExpressions = []
variableReassignments = []
@@ -0,0 +1,5 @@
suspend fun test() {
<expr>call(1, "foo")</expr>
}
suspend fun call(n: Int, text: String): Int = n
@@ -0,0 +1,12 @@
KtDataFlowExitPointSnapshot:
defaultExpressionInfo = DefaultExpressionInfo:
expression = call(1, "foo")
type = kotlin.Int
hasEscapingJumps = false
hasJumps = false
hasMultipleJumpKinds = false
hasMultipleJumpTargets = false
loopJumpExpressions = []
returnValueType = null
valuedReturnExpressions = []
variableReassignments = []
@@ -0,0 +1,9 @@
fun test() {
<expr>Foo</expr>.Bar().bar()
}
class Foo {
class Bar {
fun bar() {}
}
}
@@ -0,0 +1,10 @@
KtDataFlowExitPointSnapshot:
defaultExpressionInfo = null
hasEscapingJumps = false
hasJumps = false
hasMultipleJumpKinds = false
hasMultipleJumpTargets = false
loopJumpExpressions = []
returnValueType = null
valuedReturnExpressions = []
variableReassignments = []
@@ -0,0 +1,7 @@
fun test() {
<expr>consume(1)
val x = 2</expr>
consume(x)
}
fun consume(n: Int) {}
@@ -0,0 +1,10 @@
KtDataFlowExitPointSnapshot:
defaultExpressionInfo = null
hasEscapingJumps = false
hasJumps = false
hasMultipleJumpKinds = false
hasMultipleJumpTargets = false
loopJumpExpressions = []
returnValueType = null
valuedReturnExpressions = []
variableReassignments = []
@@ -0,0 +1,11 @@
fun test() {
var x = 0
<expr>consume(x)
while (cond()) {
consume(++x)
}</expr>
}
fun cond(): Boolean = true
fun consume(n: Int) {}
@@ -0,0 +1,15 @@
KtDataFlowExitPointSnapshot:
defaultExpressionInfo = null
hasEscapingJumps = false
hasJumps = false
hasMultipleJumpKinds = false
hasMultipleJumpTargets = false
loopJumpExpressions = []
returnValueType = null
valuedReturnExpressions = []
variableReassignments = [
VariableReassignment:
expression = ++x
isAugmented = true
variable = var x: kotlin.Int
]