Extract Function: Allow to extract local variables which are used outside of extracted fragment

This commit is contained in:
Alexey Sedunov
2014-07-03 18:55:11 +04:00
parent 540e8b8b46
commit d95f6383b7
35 changed files with 439 additions and 93 deletions
@@ -31,6 +31,7 @@ import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue
import org.jetbrains.jet.lang.resolve.OverridingUtil
import org.jetbrains.jet.lang.types.TypeUtils
import org.jetbrains.jet.lang.types.JetType
import org.jetbrains.jet.lang.cfg.pseudocode.instructions.special.LocalFunctionDeclarationInstruction
fun JetExpression.isStatement(pseudocode: Pseudocode): Boolean =
pseudocode.getUsages(pseudocode.getElementValue(this)).isEmpty()
@@ -129,6 +130,13 @@ fun getExpectedTypePredicate(value: PseudoValue, bindingContext: BindingContext)
return and(typePredicates.filterNotNull())
}
public fun Instruction.getPrimaryDeclarationDescriptorIfAny(bindingContext: BindingContext): DeclarationDescriptor? {
return when (this) {
is CallInstruction -> return resolvedCall.getResultingDescriptor()
else -> PseudocodeUtil.extractVariableDescriptorIfAny(this, false, bindingContext)
}
}
private fun Pseudocode.collectValueUsages(): Map<PseudoValue, List<Instruction>> {
val map = HashMap<PseudoValue, MutableList<Instruction>>()
traverseFollowingInstructions(getEnterInstruction(), HashSet(), TraversalOrder.FORWARD) {