Refactoring (same logic in ControlFlowInformationProvider / DataFlowValueFactory)
This commit is contained in:
@@ -393,7 +393,7 @@ public class ControlFlowInformationProvider {
|
|||||||
|
|
||||||
// Should return KtDeclarationWithBody or KtClassOrObject
|
// Should return KtDeclarationWithBody or KtClassOrObject
|
||||||
@Nullable
|
@Nullable
|
||||||
private static KtDeclaration getElementParentDeclaration(@NotNull KtElement element) {
|
public static KtDeclaration getElementParentDeclaration(@NotNull KtElement element) {
|
||||||
//noinspection unchecked
|
//noinspection unchecked
|
||||||
return PsiTreeUtil.getParentOfType(element, KtDeclarationWithBody.class, KtClassOrObject.class);
|
return PsiTreeUtil.getParentOfType(element, KtDeclarationWithBody.class, KtClassOrObject.class);
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-15
@@ -22,6 +22,7 @@ import com.intellij.psi.tree.IElementType;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.kotlin.KtNodeTypes;
|
import org.jetbrains.kotlin.KtNodeTypes;
|
||||||
|
import org.jetbrains.kotlin.cfg.ControlFlowInformationProvider;
|
||||||
import org.jetbrains.kotlin.descriptors.*;
|
import org.jetbrains.kotlin.descriptors.*;
|
||||||
import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor;
|
import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor;
|
||||||
import org.jetbrains.kotlin.descriptors.impl.SyntheticFieldDescriptor;
|
import org.jetbrains.kotlin.descriptors.impl.SyntheticFieldDescriptor;
|
||||||
@@ -355,21 +356,11 @@ public class DataFlowValueFactory {
|
|||||||
@NotNull BindingContext bindingContext,
|
@NotNull BindingContext bindingContext,
|
||||||
@NotNull KtElement accessElement
|
@NotNull KtElement accessElement
|
||||||
) {
|
) {
|
||||||
PsiElement parent = accessElement.getParent();
|
KtDeclaration parent = ControlFlowInformationProvider.getElementParentDeclaration(accessElement);
|
||||||
while (parent != null) {
|
if (parent != null) {
|
||||||
// We are inside some declaration
|
DeclarationDescriptor descriptor = bindingContext.get(DECLARATION_TO_DESCRIPTOR, parent);
|
||||||
if (parent instanceof KtDeclarationWithBody || parent instanceof KtClassOrObject) {
|
// Access is at the same declaration: not in closure, lower: in closure
|
||||||
DeclarationDescriptor descriptor = bindingContext.get(DECLARATION_TO_DESCRIPTOR, parent);
|
return !variableContainingDeclaration.equals(descriptor);
|
||||||
if (variableContainingDeclaration.equals(descriptor)) {
|
|
||||||
// Access is at the same declaration: not in closure
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// Access is lower than parent: in closure
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
parent = parent.getParent();
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user