@Test public void testNestedIfAllReturning() throws Exception { testSegment(new AbstractProcessor<CtIf>() { @Override public void process(CtIf element) { CtMethod m = element.getParent().getParent(CtMethod.class); if (m != null && m.getSimpleName().equals("nestedIfAllReturning")) if (element.getCondition().toString().contains("a > 0")) { AllBranchesReturn alg = new AllBranchesReturn(); assertTrue(alg.execute(element)); } } }); }
public boolean execute(CtElement element) { ControlFlowBuilder builder = new ControlFlowBuilder(); ControlFlowGraph graph = builder.build(element); graph.simplify(); List<ControlFlowNode> exits = graph.findNodesOfKind(BranchKind.EXIT); int returnCount = 0; int incomingCount = -1; for (ControlFlowNode n : exits) { Set<ControlFlowEdge> edges = graph.incomingEdgesOf(n); incomingCount = edges.size(); for (ControlFlowEdge in : edges) { if (in.getSourceNode().getStatement() != null && in.getSourceNode().getStatement() instanceof CtReturn) { returnCount++; } } } return returnCount == incomingCount || returnCount == 0; }
AllBranchesReturn { public boolean execute(CtElement element) { ControlFlowBuilder builder = new ControlFlowBuilder(); ControlFlowGraph graph = builder.build(element); graph.simplify(); List<ControlFlowNode> exits = graph.findNodesOfKind(BranchKind.EXIT); int returnCount = 0; int incomingCount = -1; for (ControlFlowNode n : exits) { Set<ControlFlowEdge> edges = graph.incomingEdgesOf(n); incomingCount = edges.size(); for (ControlFlowEdge in : edges) { if (in.getSourceNode().getStatement() != null && in.getSourceNode().getStatement() instanceof CtReturn) { returnCount++; } } } return returnCount == incomingCount || returnCount == 0; } }
AllBranchesReturn { public boolean execute(CtElement element) { ControlFlowBuilder builder = new ControlFlowBuilder(); ControlFlowGraph graph = builder.build(element); graph.simplify(); List<ControlFlowNode> exits = graph.findNodesOfKind(BranchKind.EXIT); int returnCount = 0; int incomingCount = -1; for (ControlFlowNode n : exits) { Set<ControlFlowEdge> edges = graph.incomingEdgesOf(n); incomingCount = edges.size(); for (ControlFlowEdge in : edges) { if (in.getSourceNode().getStatement() != null && in.getSourceNode().getStatement() instanceof CtReturn) { returnCount++; } } } return returnCount == incomingCount || returnCount == 0; }  }
AllBranchesReturn { public boolean execute(CtElement element) { ControlFlowBuilder builder = new ControlFlowBuilder(); ControlFlowGraph graph = builder.build(element); graph.simplify(); List<ControlFlowNode> exits = graph.findNodesOfKind(BranchKind.EXIT); int returnCount = 0; int incomingCount = -1; for (ControlFlowNode n : exits) { Set<ControlFlowEdge> edges = graph.incomingEdgesOf(n); incomingCount = edges.size(); for (ControlFlowEdge in : edges) { if (in.getSourceNode().getStatement() != null && in.getSourceNode().getStatement() instanceof CtReturn) { returnCount++; } } } return returnCount == incomingCount || returnCount == 0; }  boolean execute(CtElement element); }
AllBranchesReturn { public boolean execute(CtElement element) { ControlFlowBuilder builder = new ControlFlowBuilder(); ControlFlowGraph graph = builder.build(element); graph.simplify(); List<ControlFlowNode> exits = graph.findNodesOfKind(BranchKind.EXIT); int returnCount = 0; int incomingCount = -1; for (ControlFlowNode n : exits) { Set<ControlFlowEdge> edges = graph.incomingEdgesOf(n); incomingCount = edges.size(); for (ControlFlowEdge in : edges) { if (in.getSourceNode().getStatement() != null && in.getSourceNode().getStatement() instanceof CtReturn) { returnCount++; } } } return returnCount == incomingCount || returnCount == 0; }  boolean execute(CtElement element);  }