-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Special handling of inline function to track values from individual c…
…alls
- Loading branch information
1 parent
269420a
commit a09a9a6
Showing
29 changed files
with
420 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
idea/src/org/jetbrains/kotlin/idea/slicer/KotlinSliceAnalysisMode.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. | ||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. | ||
*/ | ||
|
||
package org.jetbrains.kotlin.idea.slicer | ||
|
||
import org.jetbrains.kotlin.idea.findUsages.handlers.SliceUsageProcessor | ||
import org.jetbrains.kotlin.psi.KtElement | ||
import org.jetbrains.kotlin.psi.KtNamedFunction | ||
import org.jetbrains.kotlin.psi.psiUtil.createSmartPointer | ||
|
||
data class KotlinSliceAnalysisMode(val behaviourStack: List<Behaviour>, val inlineCallStack: List<InlineFunctionCall>) { | ||
fun withBehaviour(behaviour: Behaviour) = copy(behaviourStack = behaviourStack + behaviour) | ||
|
||
fun withInlineFunctionCall( | ||
callElement: KtElement, | ||
function: KtNamedFunction | ||
) = copy(inlineCallStack = inlineCallStack + InlineFunctionCall(callElement, function)) | ||
|
||
fun dropBehaviour(): KotlinSliceAnalysisMode { | ||
check(behaviourStack.isNotEmpty()) | ||
return copy(behaviourStack = behaviourStack.dropLast(1)) | ||
} | ||
|
||
fun popInlineFunctionCall(function: KtNamedFunction): Pair<KotlinSliceAnalysisMode?, KtElement?> { | ||
val last = inlineCallStack.lastOrNull() | ||
if (last?.function != function) return null to null | ||
val newMode = copy(inlineCallStack = inlineCallStack.dropLast(1)) | ||
return newMode to last.callElement | ||
} | ||
|
||
val currentBehaviour: Behaviour? | ||
get() = behaviourStack.lastOrNull() | ||
|
||
interface Behaviour { | ||
fun processUsages(element: KtElement, parent: KotlinSliceUsage, uniqueProcessor: SliceUsageProcessor) | ||
|
||
val slicePresentationPrefix: String | ||
val testPresentationPrefix: String | ||
|
||
override fun equals(other: Any?): Boolean | ||
override fun hashCode(): Int | ||
} | ||
|
||
class InlineFunctionCall(callElement: KtElement, function: KtNamedFunction) { | ||
private val callElementPointer = callElement.createSmartPointer() | ||
private val functionPointer = function.createSmartPointer() | ||
|
||
val callElement: KtElement? | ||
get() = callElementPointer.element | ||
|
||
val function: KtNamedFunction? | ||
get() = functionPointer.element | ||
|
||
override fun equals(other: Any?): Boolean { | ||
if (this === other) return true | ||
return other is InlineFunctionCall && other.callElement == callElement && other.function == function | ||
} | ||
|
||
override fun hashCode() = 0 | ||
} | ||
|
||
companion object { | ||
val Default = KotlinSliceAnalysisMode(emptyList(), emptyList()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.