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..1a133b646e1 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 @@ -798,7 +798,11 @@ public void visitCtSwitchExpression(CtSwitchExpression switchExpres @Override public void visitCtSynchronized(CtSynchronized synchro) { + ControlFlowNode expressionNode = new ControlFlowNode(synchro.getExpression(), result, BranchKind.STATEMENT); + tryAddEdge(lastNode, expressionNode); + lastNode = expressionNode; + synchro.getBlock().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..59c880b7d1b 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 @@ -331,6 +331,11 @@ public void testInvocation() throws Exception { testEdges(graph, 1, 0, 0, null); } + @Test + public void testSynchronized() throws Exception { + testMethod("synchronization", true, 0, 2, 8); + } + @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..cbb34a185b6 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,12 @@ public int simple(int a) { return 10 * a; } + public void synchronization() { + synchronized (new Object()) { + int a = 0; + } + } + ///////////////////////////////////////////////////////////////////////////////////////////