Skip to content

Commit

Permalink
Handling of method references
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinkip committed Apr 17, 2020
1 parent 7dd30eb commit 63095f9
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 35 deletions.
19 changes: 16 additions & 3 deletions idea/src/org/jetbrains/kotlin/idea/slicer/InflowSlicer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,23 @@ class InflowSlicer(
val referencedDescriptor = bindingContext[BindingContext.REFERENCE_TARGET, callableRefExpr.callableReference] ?: return
val referencedDeclaration = (referencedDescriptor as? DeclarationDescriptorWithSource)?.originalSource?.getPsi()
?: return
if (currentBehaviour is LambdaResultInflowBehaviour) {
referencedDeclaration.passToProcessor(mode.dropBehaviour())
when (currentBehaviour) {
is LambdaResultInflowBehaviour -> {
referencedDeclaration.passToProcessor(mode.dropBehaviour())
}

is LambdaArgumentInflowBehaviour -> {
val parameter = (referencedDeclaration as? KtCallableDeclaration)
?.valueParameters?.getOrNull(currentBehaviour.argumentIndex)
parameter?.passToProcessor(mode.dropBehaviour())
}

is LambdaReceiverInflowBehaviour -> {
val parameter = (referencedDeclaration as? KtCallableDeclaration)
?.valueParameters?.getOrNull(0)
parameter?.passToProcessor(mode.dropBehaviour())
}
}
//TODO: LambdaArgumentInflowBehaviour
}

else -> return
Expand Down
3 changes: 3 additions & 0 deletions idea/testData/slicer/outflow/letResult.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ fun foo(<caret>p: String) {
val it = "a"
it
}

val v4 = p.let(::zoo)
}

fun bar(s: String) = s
fun zoo(s: String) = s

inline fun <T, R> T.let(block: (T) -> R): R {
return block(this)
Expand Down
45 changes: 29 additions & 16 deletions idea/testData/slicer/outflow/letResult.results.txt
Original file line number Diff line number Diff line change
@@ -1,35 +1,48 @@
3 fun foo(<bold>p: String</bold>) {
4 val v1 = <bold>p</bold>.let { value -> bar(value) }
16 (INLINE CALL let) inline fun <T, R> <bold>T</bold>.let(block: (T) -> R): R {
17 (INLINE CALL let) return block(<bold>this</bold>)
16 (INLINE CALL let) [LAMBDA ARGUMENT IN] inline fun <T, R> T.let(<bold>block: (T) -> R</bold>): R {
19 (INLINE CALL let) inline fun <T, R> <bold>T</bold>.let(block: (T) -> R): R {
20 (INLINE CALL let) return block(<bold>this</bold>)
19 (INLINE CALL let) [LAMBDA ARGUMENT IN] inline fun <T, R> T.let(<bold>block: (T) -> R</bold>): R {
4 [LAMBDA ARGUMENT IN] val v1 = p.let <bold>{ value -> bar(value) }</bold>
4 val v1 = p.let { <bold>value</bold> -> bar(value) }
4 val v1 = p.let { value -> bar(<bold>value</bold>) }
14 fun bar(<bold>s: String</bold>) = s
14 fun bar(s: String) = <bold>s</bold>
14 fun <bold>bar(s: String) = s</bold>
16 fun bar(<bold>s: String</bold>) = s
16 fun bar(s: String) = <bold>s</bold>
16 fun <bold>bar(s: String) = s</bold>
4 val v1 = p.let { value -> <bold>bar(value)</bold> }
4 val v1 = p.let <bold>{ value -> bar(value) }</bold>
4 [LAMBDA CALLS] val v1 = p.let <bold>{ value -> bar(value) }</bold>
16 (INLINE CALL let) [LAMBDA CALLS] inline fun <T, R> T.let(<bold>block: (T) -> R</bold>): R {
17 (INLINE CALL let) return <bold>block(this)</bold>
19 (INLINE CALL let) [LAMBDA CALLS] inline fun <T, R> T.let(<bold>block: (T) -> R</bold>): R {
20 (INLINE CALL let) return <bold>block(this)</bold>
4 val v1 = p.<bold>let { value -> bar(value) }</bold>
4 val <bold>v1 = p.let { value -> bar(value) }</bold>
6 val v2 = <bold>p</bold>.let { it }
16 (INLINE CALL let) inline fun <T, R> <bold>T</bold>.let(block: (T) -> R): R {
17 (INLINE CALL let) return block(<bold>this</bold>)
16 (INLINE CALL let) [LAMBDA ARGUMENT IN] inline fun <T, R> T.let(<bold>block: (T) -> R</bold>): R {
19 (INLINE CALL let) inline fun <T, R> <bold>T</bold>.let(block: (T) -> R): R {
20 (INLINE CALL let) return block(<bold>this</bold>)
19 (INLINE CALL let) [LAMBDA ARGUMENT IN] inline fun <T, R> T.let(<bold>block: (T) -> R</bold>): R {
6 [LAMBDA ARGUMENT IN] val v2 = p.let <bold>{ it }</bold>
6 val v2 = p.let { <bold>it</bold> }
6 val v2 = p.let <bold>{ it }</bold>
6 [LAMBDA CALLS] val v2 = p.let <bold>{ it }</bold>
16 (INLINE CALL let) [LAMBDA CALLS] inline fun <T, R> T.let(<bold>block: (T) -> R</bold>): R {
17 (INLINE CALL let) return <bold>block(this)</bold>
19 (INLINE CALL let) [LAMBDA CALLS] inline fun <T, R> T.let(<bold>block: (T) -> R</bold>): R {
20 (INLINE CALL let) return <bold>block(this)</bold>
6 val v2 = p.<bold>let { it }</bold>
6 val <bold>v2 = p.let { it }</bold>
8 val v3 = <bold>p</bold>.let {
16 (INLINE CALL let) inline fun <T, R> <bold>T</bold>.let(block: (T) -> R): R {
17 (INLINE CALL let) return block(<bold>this</bold>)
16 (INLINE CALL let) [LAMBDA ARGUMENT IN] inline fun <T, R> T.let(<bold>block: (T) -> R</bold>): R {
19 (INLINE CALL let) inline fun <T, R> <bold>T</bold>.let(block: (T) -> R): R {
20 (INLINE CALL let) return block(<bold>this</bold>)
19 (INLINE CALL let) [LAMBDA ARGUMENT IN] inline fun <T, R> T.let(<bold>block: (T) -> R</bold>): R {
8 [LAMBDA ARGUMENT IN] val v3 = p.let <bold>{</bold>
13 val v4 = <bold>p</bold>.let(::zoo)
19 (INLINE CALL let) inline fun <T, R> <bold>T</bold>.let(block: (T) -> R): R {
20 (INLINE CALL let) return block(<bold>this</bold>)
19 (INLINE CALL let) [LAMBDA ARGUMENT IN] inline fun <T, R> T.let(<bold>block: (T) -> R</bold>): R {
13 [LAMBDA ARGUMENT IN] val v4 = p.let(<bold>::zoo</bold>)
17 fun zoo(<bold>s: String</bold>) = s
17 fun zoo(s: String) = <bold>s</bold>
17 fun <bold>zoo(s: String) = s</bold>
13 [LAMBDA CALLS] val v4 = p.let(<bold>::zoo</bold>)
19 (INLINE CALL let) [LAMBDA CALLS] inline fun <T, R> T.let(<bold>block: (T) -> R</bold>): R {
20 (INLINE CALL let) return <bold>block(this)</bold>
13 val v4 = p.<bold>let(::zoo)</bold>
13 val <bold>v4 = p.let(::zoo)</bold>
3 changes: 3 additions & 0 deletions idea/testData/slicer/outflow/withResult.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ fun String.foo(<caret>p: String) {
val v2 = with(p) { bar(this) }

val v3 = with(p) { this@foo }

val v4 = with(p, ::zoo)
}

fun bar(s: String) = s
fun zoo(s: String) = s

inline fun <T, R> with(receiver: T, block: T.() -> R): R {
return receiver.block()
Expand Down
45 changes: 29 additions & 16 deletions idea/testData/slicer/outflow/withResult.results.txt
Original file line number Diff line number Diff line change
@@ -1,34 +1,47 @@
3 fun String.foo(<bold>p: String</bold>) {
4 val v1 = with(<bold>p</bold>) { this }
13 (INLINE CALL with) inline fun <T, R> with(<bold>receiver: T</bold>, block: T.() -> R): R {
14 (INLINE CALL with) return <bold>receiver</bold>.block()
13 (INLINE CALL with) [LAMBDA RECEIVER IN] inline fun <T, R> with(receiver: T, <bold>block: T.() -> R</bold>): R {
16 (INLINE CALL with) inline fun <T, R> with(<bold>receiver: T</bold>, block: T.() -> R): R {
17 (INLINE CALL with) return <bold>receiver</bold>.block()
16 (INLINE CALL with) [LAMBDA RECEIVER IN] inline fun <T, R> with(receiver: T, <bold>block: T.() -> R</bold>): R {
4 [LAMBDA RECEIVER IN] val v1 = with(p) <bold>{ this }</bold>
4 val v1 = with(p) { <bold>this</bold> }
4 val v1 = with(p) <bold>{ this }</bold>
4 [LAMBDA CALLS] val v1 = with(p) <bold>{ this }</bold>
13 (INLINE CALL with) [LAMBDA CALLS] inline fun <T, R> with(receiver: T, <bold>block: T.() -> R</bold>): R {
14 (INLINE CALL with) return receiver.<bold>block()</bold>
16 (INLINE CALL with) [LAMBDA CALLS] inline fun <T, R> with(receiver: T, <bold>block: T.() -> R</bold>): R {
17 (INLINE CALL with) return receiver.<bold>block()</bold>
4 val v1 = <bold>with(p) { this }</bold>
4 val <bold>v1 = with(p) { this }</bold>
6 val v2 = with(<bold>p</bold>) { bar(this) }
13 (INLINE CALL with) inline fun <T, R> with(<bold>receiver: T</bold>, block: T.() -> R): R {
14 (INLINE CALL with) return <bold>receiver</bold>.block()
13 (INLINE CALL with) [LAMBDA RECEIVER IN] inline fun <T, R> with(receiver: T, <bold>block: T.() -> R</bold>): R {
16 (INLINE CALL with) inline fun <T, R> with(<bold>receiver: T</bold>, block: T.() -> R): R {
17 (INLINE CALL with) return <bold>receiver</bold>.block()
16 (INLINE CALL with) [LAMBDA RECEIVER IN] inline fun <T, R> with(receiver: T, <bold>block: T.() -> R</bold>): R {
6 [LAMBDA RECEIVER IN] val v2 = with(p) <bold>{ bar(this) }</bold>
6 val v2 = with(p) { bar(<bold>this</bold>) }
11 fun bar(<bold>s: String</bold>) = s
11 fun bar(s: String) = <bold>s</bold>
11 fun <bold>bar(s: String) = s</bold>
13 fun bar(<bold>s: String</bold>) = s
13 fun bar(s: String) = <bold>s</bold>
13 fun <bold>bar(s: String) = s</bold>
6 val v2 = with(p) { <bold>bar(this)</bold> }
6 val v2 = with(p) <bold>{ bar(this) }</bold>
6 [LAMBDA CALLS] val v2 = with(p) <bold>{ bar(this) }</bold>
13 (INLINE CALL with) [LAMBDA CALLS] inline fun <T, R> with(receiver: T, <bold>block: T.() -> R</bold>): R {
14 (INLINE CALL with) return receiver.<bold>block()</bold>
16 (INLINE CALL with) [LAMBDA CALLS] inline fun <T, R> with(receiver: T, <bold>block: T.() -> R</bold>): R {
17 (INLINE CALL with) return receiver.<bold>block()</bold>
6 val v2 = <bold>with(p) { bar(this) }</bold>
6 val <bold>v2 = with(p) { bar(this) }</bold>
8 val v3 = with(<bold>p</bold>) { this@foo }
13 (INLINE CALL with) inline fun <T, R> with(<bold>receiver: T</bold>, block: T.() -> R): R {
14 (INLINE CALL with) return <bold>receiver</bold>.block()
13 (INLINE CALL with) [LAMBDA RECEIVER IN] inline fun <T, R> with(receiver: T, <bold>block: T.() -> R</bold>): R {
16 (INLINE CALL with) inline fun <T, R> with(<bold>receiver: T</bold>, block: T.() -> R): R {
17 (INLINE CALL with) return <bold>receiver</bold>.block()
16 (INLINE CALL with) [LAMBDA RECEIVER IN] inline fun <T, R> with(receiver: T, <bold>block: T.() -> R</bold>): R {
8 [LAMBDA RECEIVER IN] val v3 = with(p) <bold>{ this@foo }</bold>
10 val v4 = with(<bold>p</bold>, ::zoo)
16 (INLINE CALL with) inline fun <T, R> with(<bold>receiver: T</bold>, block: T.() -> R): R {
17 (INLINE CALL with) return <bold>receiver</bold>.block()
16 (INLINE CALL with) [LAMBDA RECEIVER IN] inline fun <T, R> with(receiver: T, <bold>block: T.() -> R</bold>): R {
10 [LAMBDA RECEIVER IN] val v4 = with(p, <bold>::zoo</bold>)
14 fun zoo(<bold>s: String</bold>) = s
14 fun zoo(s: String) = <bold>s</bold>
14 fun <bold>zoo(s: String) = s</bold>
10 [LAMBDA CALLS] val v4 = with(p, <bold>::zoo</bold>)
16 (INLINE CALL with) [LAMBDA CALLS] inline fun <T, R> with(receiver: T, <bold>block: T.() -> R</bold>): R {
17 (INLINE CALL with) return receiver.<bold>block()</bold>
10 val v4 = <bold>with(p, ::zoo)</bold>
10 val <bold>v4 = with(p, ::zoo)</bold>

0 comments on commit 63095f9

Please sign in to comment.