CFG refactoring: extractVariableDescriptorFrom
(cherry picked from commit 95add79)
This commit is contained in:
committed by
Mikhail Glukhikh
parent
25d8af3112
commit
902232c8ad
@@ -70,7 +70,7 @@ class KotlinSourcePositionProvider: SourcePositionProvider() {
|
||||
val expression = codeFragment.getContentElement()
|
||||
if (expression is KtSimpleNameExpression) {
|
||||
val bindingContext = expression.analyze(BodyResolveMode.PARTIAL)
|
||||
val declarationDescriptor = BindingContextUtils.extractVariableDescriptorIfAny(bindingContext, expression, false)
|
||||
val declarationDescriptor = BindingContextUtils.extractVariableDescriptorFromReference(bindingContext, expression)
|
||||
val sourceElement = declarationDescriptor?.source
|
||||
if (sourceElement is KotlinSourceElement) {
|
||||
val element = sourceElement.getPsi() ?: return null
|
||||
|
||||
+1
-1
@@ -133,7 +133,7 @@ fun KtPostfixExpression.inlineBaseExpressionIfApplicableWithPrompt(editor: Edito
|
||||
|
||||
fun KtExpression.isStableVariable(): Boolean {
|
||||
val context = this.analyze()
|
||||
val descriptor = BindingContextUtils.extractVariableDescriptorIfAny(context, this, false)
|
||||
val descriptor = BindingContextUtils.extractVariableDescriptorFromReference(context, this)
|
||||
return descriptor is VariableDescriptor &&
|
||||
DataFlowValueFactory.isStableValue(descriptor, DescriptorUtils.getContainingModule(descriptor))
|
||||
}
|
||||
|
||||
+2
-2
@@ -92,7 +92,7 @@ private fun List<Instruction>.getModifiedVarDescriptors(bindingContext: BindingC
|
||||
val result = HashMap<VariableDescriptor, MutableList<KtExpression>>()
|
||||
for (instruction in filterIsInstance<WriteValueInstruction>()) {
|
||||
val expression = instruction.element as? KtExpression
|
||||
val descriptor = PseudocodeUtil.extractVariableDescriptorIfAny(instruction, false, bindingContext)
|
||||
val descriptor = PseudocodeUtil.extractVariableDescriptorIfAny(instruction, bindingContext)
|
||||
if (expression != null && descriptor != null) {
|
||||
result.getOrPut(descriptor) { ArrayList() }.add(expression)
|
||||
}
|
||||
@@ -109,7 +109,7 @@ private fun List<Instruction>.getVarDescriptorsAccessedAfterwards(bindingContext
|
||||
traverseFollowingInstructions(instruction, visitedInstructions) {
|
||||
when {
|
||||
it is AccessValueInstruction && it !in this ->
|
||||
PseudocodeUtil.extractVariableDescriptorIfAny(it, false, bindingContext)?.let { accessedAfterwards.add(it) }
|
||||
PseudocodeUtil.extractVariableDescriptorIfAny(it, bindingContext)?.let { accessedAfterwards.add(it) }
|
||||
|
||||
it is LocalFunctionDeclarationInstruction ->
|
||||
doTraversal(it.body.enterInstruction)
|
||||
|
||||
Reference in New Issue
Block a user