diff --git a/spoon-control-flow/src/main/java/fr/inria/controlflow/ControlFlowBuilder.java b/spoon-control-flow/src/main/java/fr/inria/controlflow/ControlFlowBuilder.java index aef9d87689b..fbf881d0215 100644 --- a/spoon-control-flow/src/main/java/fr/inria/controlflow/ControlFlowBuilder.java +++ b/spoon-control-flow/src/main/java/fr/inria/controlflow/ControlFlowBuilder.java @@ -443,8 +443,8 @@ public void visitCtConditional(CtConditional conditional) { } @Override - public void visitCtConstructor(CtConstructor c) { - + public void visitCtConstructor(CtConstructor constructor) { + constructor.getBody().accept(this); } @Override diff --git a/spoon-control-flow/src/test/java/fr/inria/controlflow/ForwardFlowBuilderVisitorTest.java b/spoon-control-flow/src/test/java/fr/inria/controlflow/ForwardFlowBuilderVisitorTest.java index 89f0f387dfd..2ddc71abbd1 100644 --- a/spoon-control-flow/src/test/java/fr/inria/controlflow/ForwardFlowBuilderVisitorTest.java +++ b/spoon-control-flow/src/test/java/fr/inria/controlflow/ForwardFlowBuilderVisitorTest.java @@ -25,15 +25,17 @@ import org.junit.jupiter.api.Test; import spoon.processing.AbstractProcessor; import spoon.processing.ProcessingManager; +import spoon.reflect.declaration.CtConstructor; import spoon.reflect.declaration.CtMethod; import spoon.reflect.factory.Factory; import spoon.support.QueueProcessingManager; import java.io.PrintWriter; +import java.net.URISyntaxException; -import static fr.inria.controlflow.BranchKind.BRANCH; -import static fr.inria.controlflow.BranchKind.STATEMENT; +import static fr.inria.controlflow.BranchKind.*; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; /** * Created by marodrig on 14/10/2015. @@ -331,6 +333,30 @@ public void testInvocation() throws Exception { testEdges(graph, 1, 0, 0, null); } + @Test + public void testConstructor() throws URISyntaxException, ClassNotFoundException, IllegalAccessException, InstantiationException { + ControlFlowBuilder visitor = new ControlFlowBuilder(); + + Factory factory = new SpoonMetaFactory().buildNewFactory(this.getClass().getResource("/control-flow").toURI().getPath(), 17); + ProcessingManager pm = new QueueProcessingManager(factory); + pm.addProcessor(new AbstractProcessor>() { + @Override + public void process(CtConstructor element) { + if (!element.getBody().getStatements().isEmpty()) { + visitor.build(element); + } + } + + }); + pm.process(factory.getModel().getRootPackage()); + + ControlFlowGraph graph = visitor.getResult(); + ControlFlowNode entryNode = graph.findNodesOfKind(BEGIN).get(0); + ControlFlowNode exitNode = graph.getExitNode(); + + assertFalse(graph.containsEdge(entryNode, exitNode), "Graph is missing statements"); + } + @Test public void testtestCase() throws Exception { //branchCount, stmntCount, totalCount diff --git a/spoon-control-flow/src/test/resources/control-flow/ControlFlowArithmetic.java b/spoon-control-flow/src/test/resources/control-flow/ControlFlowArithmetic.java index 6f369c94a44..776f57bb71b 100644 --- a/spoon-control-flow/src/test/resources/control-flow/ControlFlowArithmetic.java +++ b/spoon-control-flow/src/test/resources/control-flow/ControlFlowArithmetic.java @@ -383,6 +383,10 @@ public int simple(int a) { return 10 * a; } + public ControlFlowArithmetic() { + int a = 1; + } + ///////////////////////////////////////////////////////////////////////////////////////////