use of com.intellij.codeInsight.controlflow.ControlFlow in project intellij-community by JetBrains.
the class PyControlFlowBuilderTest method doTest.
private void doTest() {
final String testName = getTestName(false).toLowerCase();
configureByFile(testName + ".py");
final ControlFlow flow = ControlFlowCache.getControlFlow((PyFile) myFile);
final String fullPath = getTestDataPath() + testName + ".txt";
check(fullPath, flow);
}
use of com.intellij.codeInsight.controlflow.ControlFlow in project intellij-community by JetBrains.
the class PyControlFlowBuilderTest method doTestFirstStatement.
private void doTestFirstStatement() {
final String testName = getTestName(false).toLowerCase();
configureByFile(testName + ".py");
final String fullPath = getTestDataPath() + testName + ".txt";
final ControlFlow flow = ControlFlowCache.getControlFlow((ScopeOwner) ((PyFile) myFile).getStatements().get(0));
check(fullPath, flow);
}
use of com.intellij.codeInsight.controlflow.ControlFlow in project intellij-community by JetBrains.
the class PyControlFlowBuilderTest method testSelf.
public void testSelf() {
final String testName = getTestName(false).toLowerCase();
configureByFile(testName + ".py");
final String fullPath = getTestDataPath() + testName + ".txt";
final PyClass pyClass = ((PyFile) myFile).getTopLevelClasses().get(0);
final ControlFlow flow = ControlFlowCache.getControlFlow(pyClass.getMethods()[0]);
check(fullPath, flow);
}
use of com.intellij.codeInsight.controlflow.ControlFlow in project intellij-community by JetBrains.
the class ControlFlowCache method getControlFlow.
public static ControlFlow getControlFlow(@NotNull ScopeOwner element) {
SoftReference<ControlFlow> ref = element.getUserData(CONTROL_FLOW_KEY);
ControlFlow flow = SoftReference.dereference(ref);
if (flow == null) {
flow = new PyControlFlowBuilder().buildControlFlow(element);
element.putUserData(CONTROL_FLOW_KEY, new SoftReference<>(flow));
}
return flow;
}
use of com.intellij.codeInsight.controlflow.ControlFlow in project intellij-community by JetBrains.
the class PyBaseMakeFunctionTopLevelProcessor method analyseScope.
@NotNull
protected AnalysisResult analyseScope(@NotNull ScopeOwner owner) {
final ControlFlow controlFlow = ControlFlowCache.getControlFlow(owner);
final AnalysisResult result = new AnalysisResult();
for (Instruction instruction : controlFlow.getInstructions()) {
if (instruction instanceof ReadWriteInstruction) {
final ReadWriteInstruction readWriteInstruction = (ReadWriteInstruction) instruction;
final PsiElement element = readWriteInstruction.getElement();
if (element == null) {
continue;
}
if (readWriteInstruction.getAccess().isReadAccess()) {
for (PsiElement resolved : PyUtil.multiResolveTopPriority(element, myResolveContext)) {
if (resolved != null) {
if (isInitOrNewMethod(resolved)) {
resolved = ((PyFunction) resolved).getContainingClass();
}
if (isFromEnclosingScope(resolved)) {
result.readsFromEnclosingScope.add(element);
} else if (!belongsToFunction(resolved)) {
myExternalReads.add(resolved);
}
if (resolved instanceof PyParameter && ((PyParameter) resolved).isSelf()) {
if (PsiTreeUtil.getParentOfType(resolved, PyFunction.class) == myFunction) {
result.readsOfSelfParameter.add(element);
} else if (!PsiTreeUtil.isAncestor(myFunction, resolved, true)) {
result.readsOfSelfParametersFromEnclosingScope.add(element);
}
}
}
}
}
if (readWriteInstruction.getAccess().isWriteAccess() && element instanceof PyTargetExpression) {
for (PsiElement resolved : PyUtil.multiResolveTopPriority(element, myResolveContext)) {
if (resolved != null) {
if (element.getParent() instanceof PyNonlocalStatement && isFromEnclosingScope(resolved)) {
result.nonlocalWritesToEnclosingScope.add((PyTargetExpression) element);
}
if (resolved instanceof PyParameter && ((PyParameter) resolved).isSelf() && PsiTreeUtil.getParentOfType(resolved, PyFunction.class) == myFunction) {
result.writesToSelfParameter.add((PyTargetExpression) element);
}
}
}
}
}
}
return result;
}
Aggregations