include reads of decorators in control flow graph

This commit is contained in:
Dmitry Jemerov
2012-01-16 18:21:30 +01:00
parent 2c36d0f7f8
commit 85257c075a
5 changed files with 33 additions and 4 deletions
@@ -39,12 +39,21 @@ public class PyControlFlowBuilder extends PyRecursiveElementVisitor {
// Create node and stop here
myBuilder.startNode(node);
visitDefaultParameterValues(node.getParameterList());
visitDecorators(node.getDecoratorList());
final ReadWriteInstruction instruction = ReadWriteInstruction.write(myBuilder, node, node.getName());
myBuilder.addNode(instruction);
myBuilder.checkPending(instruction);
}
private void visitDecorators(PyDecoratorList list) {
if (list != null) {
for (PyDecorator decorator : list.getDecorators()) {
decorator.accept(this);
}
}
}
private void visitDefaultParameterValues(PyParameterList parameterList) {
ParamHelper.walkDownParamArray(parameterList.getParameters(), new ParamHelper.ParamVisitor() {
@Override
@@ -64,6 +73,7 @@ public class PyControlFlowBuilder extends PyRecursiveElementVisitor {
for (PsiElement element : node.getSuperClassExpressions()) {
element.accept(this);
}
visitDecorators(node.getDecoratorList());
final ReadWriteInstruction instruction = ReadWriteInstruction.write(myBuilder, node, node.getName());
myBuilder.addNode(instruction);
myBuilder.checkPending(instruction);
@@ -0,0 +1,4 @@
class C:
@classmethod
def foo():
pass
@@ -0,0 +1,5 @@
0(1) element: null
1(2) element: PyFunction('foo')
2(3) READ ACCESS: classmethod
3(4) WRITE ACCESS: foo
4() element: null
@@ -2,9 +2,10 @@
1(2) element: PyExpressionStatement
2(3) element: PySetCompExpression
3(4) element: PyCallExpression: range
4(5,9) READ ACCESS: range
4(5,10) READ ACCESS: range
5(6) element: PyTargetExpression: i
6(7) WRITE ACCESS: i
7(8) element: PyParenthesizedExpression
8(5,9) element: PyLambdaExpression
9() element: null
8(9) element: PyLambdaExpression
9(5,10) READ ACCESS: i
10() element: null
@@ -7,6 +7,7 @@ import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.jetbrains.python.codeInsight.controlflow.ControlFlowCache;
import com.jetbrains.python.codeInsight.controlflow.ScopeOwner;
import com.jetbrains.python.fixtures.LightMarkedTestCase;
import com.jetbrains.python.psi.PyClass;
import com.jetbrains.python.psi.PyFile;
@@ -164,6 +165,10 @@ public class PyControlFlowBuilderTest extends LightMarkedTestCase {
public void testLambdaDefaultParameter() {
doTest();
}
public void testDecorator() {
doTestFirstStatement();
}
public void testQualifiedSelfReference() {
final String testName = getTestName(false).toLowerCase();
@@ -192,10 +197,14 @@ public class PyControlFlowBuilderTest extends LightMarkedTestCase {
}
public void testFunction() {
doTestFirstStatement();
}
private void doTestFirstStatement() {
final String testName = getTestName(false).toLowerCase();
configureByFile(testName + ".py");
final String fullPath = getTestDataPath() + testName + ".txt";
final ControlFlow flow = ControlFlowCache.getControlFlow((PyFunction)((PyFile)myFile).getStatements().get(0));
final ControlFlow flow = ControlFlowCache.getControlFlow((ScopeOwner)((PyFile)myFile).getStatements().get(0));
check(fullPath, flow);
}