Skip to content

Commit

Permalink
Parameter to receiver
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinkip committed Apr 17, 2020
1 parent 04d4f74 commit fdfae52
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
6 changes: 3 additions & 3 deletions idea/src/org/jetbrains/kotlin/idea/slicer/OutflowSlicer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -156,17 +156,17 @@ class OutflowSlicer(
expressionWithValue.processPseudocodeUsages { pseudoValue, instruction ->
when (instruction) {
is WriteValueInstruction -> {
if (!processIfReceiverValue(instruction, pseudoValue, mode)) {
if (!pseudoValue.processIfReceiverValue(instruction, mode)) {
instruction.target.accessedDescriptor?.originalSource?.getPsi()?.passToProcessor()
}
}

is ReadValueInstruction -> {
processIfReceiverValue(instruction, pseudoValue, mode)
pseudoValue.processIfReceiverValue(instruction, mode)
}

is CallInstruction -> {
if (!processIfReceiverValue(instruction, pseudoValue, mode)) {
if (!pseudoValue.processIfReceiverValue(instruction, mode)) {
val parameterDescriptor = instruction.arguments[pseudoValue] ?: return@processPseudocodeUsages
val parameter = parameterDescriptor.originalSource.getPsi()
if (parameter != null) {
Expand Down
11 changes: 3 additions & 8 deletions idea/src/org/jetbrains/kotlin/idea/slicer/Slicer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -257,20 +257,16 @@ abstract class Slicer(
pseudocode.getUsages(receiverPseudoValue).forEach { receiverUseInstruction ->
if (receiverUseInstruction is KtElementInstruction) {
// TODO: make sure it processes correct receiver!!
processIfReceiverValue(receiverUseInstruction, receiverPseudoValue, mode)
receiverPseudoValue.processIfReceiverValue(receiverUseInstruction, mode)
}
}
}
}
}
}

protected fun processIfReceiverValue(
instruction: KtElementInstruction,
receiverPseudoValue: PseudoValue,
mode: KotlinSliceAnalysisMode,
): Boolean {
val receiverValue = (instruction as? InstructionWithReceivers)?.receiverValues?.get(receiverPseudoValue) ?: return false
protected fun PseudoValue.processIfReceiverValue(instruction: KtElementInstruction, mode: KotlinSliceAnalysisMode): Boolean {
val receiverValue = (instruction as? InstructionWithReceivers)?.receiverValues?.get(this) ?: return false
val resolvedCall = instruction.element.resolveToCall() ?: return true
val descriptor = resolvedCall.resultingDescriptor

Expand Down Expand Up @@ -309,7 +305,6 @@ abstract class Slicer(
}
}


return true
}

Expand Down

0 comments on commit fdfae52

Please sign in to comment.