From 60d7a4e5e9ce23098c52824f15556d708195b7c1 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Mon, 16 Jan 2012 17:11:01 +0100 Subject: [PATCH] include read of superclass expression in control flow graph --- .../codeInsight/controlflow/PyControlFlowBuilder.java | 7 +++++-- python/testData/codeInsight/controlflow/superclass.py | 9 +++++++++ python/testData/codeInsight/controlflow/superclass.txt | 9 +++++++++ .../com/jetbrains/python/PyControlFlowBuilderTest.java | 4 ++++ 4 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 python/testData/codeInsight/controlflow/superclass.py create mode 100644 python/testData/codeInsight/controlflow/superclass.txt diff --git a/python/src/com/jetbrains/python/codeInsight/controlflow/PyControlFlowBuilder.java b/python/src/com/jetbrains/python/codeInsight/controlflow/PyControlFlowBuilder.java index a75992c02dea..7a4fb4b1cb31 100644 --- a/python/src/com/jetbrains/python/codeInsight/controlflow/PyControlFlowBuilder.java +++ b/python/src/com/jetbrains/python/codeInsight/controlflow/PyControlFlowBuilder.java @@ -46,6 +46,9 @@ public class PyControlFlowBuilder extends PyRecursiveElementVisitor { public void visitPyClass(final PyClass node) { // Create node and stop here myBuilder.startNode(node); + for (PsiElement element : node.getSuperClassExpressions()) { + element.accept(this); + } final ReadWriteInstruction instruction = ReadWriteInstruction.write(myBuilder, node, node.getName()); myBuilder.addNode(instruction); myBuilder.checkPending(instruction); @@ -436,10 +439,10 @@ public class PyControlFlowBuilder extends PyRecursiveElementVisitor { pendingBackup.addAll(myBuilder.pending); myBuilder.pending = emptyMutableList(); myBuilder.flowAbrupted(); - final Instruction exceptInstrcution = myBuilder.startNode(exceptPart); + final Instruction exceptInstruction = myBuilder.startNode(exceptPart); exceptPart.accept(this); myBuilder.addPendingEdge(node, myBuilder.prevInstruction); - exceptInstructions.add(exceptInstrcution); + exceptInstructions.add(exceptInstruction); } for (Pair pair : pendingBackup) { myBuilder.addPendingEdge(pair.first, pair.second); diff --git a/python/testData/codeInsight/controlflow/superclass.py b/python/testData/codeInsight/controlflow/superclass.py new file mode 100644 index 000000000000..84d8efda61d9 --- /dev/null +++ b/python/testData/codeInsight/controlflow/superclass.py @@ -0,0 +1,9 @@ +class Foo: + def __init__(self): + pass + +class Bar(Foo): + pass + +Bar() +# \ No newline at end of file diff --git a/python/testData/codeInsight/controlflow/superclass.txt b/python/testData/codeInsight/controlflow/superclass.txt new file mode 100644 index 000000000000..83ea10db6864 --- /dev/null +++ b/python/testData/codeInsight/controlflow/superclass.txt @@ -0,0 +1,9 @@ +0(1) element: null +1(2) element: PyClass: Foo +2(3) WRITE ACCESS: Foo +3(4) element: PyClass: Bar +4(5) READ ACCESS: Foo +5(6) WRITE ACCESS: Bar +6(7) element: PyExpressionStatement +7(8) READ ACCESS: Bar +8() element: null \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/PyControlFlowBuilderTest.java b/python/testSrc/com/jetbrains/python/PyControlFlowBuilderTest.java index c07f6c603805..36a4c8fadfd5 100644 --- a/python/testSrc/com/jetbrains/python/PyControlFlowBuilderTest.java +++ b/python/testSrc/com/jetbrains/python/PyControlFlowBuilderTest.java @@ -152,6 +152,10 @@ public class PyControlFlowBuilderTest extends LightMarkedTestCase { public void testManyIfs() { doTest(); } + + public void testSuperclass() { + doTest(); + } public void testQualifiedSelfReference() { final String testName = getTestName(false).toLowerCase();