private void computeExecutableLines(List<? extends Tree> trees) { if(trees.isEmpty()) { return; } // rely on cfg to get every instructions and get most of the token. CFG cfg = CFG.buildCFG(trees); cfg.blocks() .stream() .flatMap(b->b.elements().stream()) .forEach( t -> { if (t.is(NEW_CLASS)) { NewClassTree newClassTree = (NewClassTree) t; new ExecutableLinesTokenVisitor().scanTree(newClassTree.identifier()); executableLines.add(newClassTree.newKeyword().line()); } else if (t.is(TRY_STATEMENT)) { // add last token of try statements executableLines.add(t.lastToken().line()); } else { executableLines.add(t.firstToken().line()); } } ); }
private List<? extends Tree> visitVariable(VariableTree variableTree) { ExpressionTree initializer = variableTree.initializer(); if(initializer != null && !isConstant(variableTree)) { return Lists.newArrayList(initializer); } if(variableTree.parent().is(CATCH)) { // catch variable are counted as executable lines new ExecutableLinesTokenVisitor().scanTree(variableTree); } return Collections.emptyList(); }
private void computeExecutableLines(List<? extends Tree> trees) { if(trees.isEmpty()) { return; } // rely on cfg to get every instructions and get most of the token. CFG cfg = CFG.buildCFG(trees); cfg.blocks() .stream() .flatMap(b->b.elements().stream()) .forEach( t -> { if (t.is(NEW_CLASS)) { NewClassTree newClassTree = (NewClassTree) t; new ExecutableLinesTokenVisitor().scanTree(newClassTree.identifier()); executableLines.add(newClassTree.newKeyword().line()); } else if (t.is(TRY_STATEMENT)) { // add last token of try statements executableLines.add(t.lastToken().line()); } else { executableLines.add(t.firstToken().line()); } } ); }
private List<? extends Tree> visitVariable(VariableTree variableTree) { ExpressionTree initializer = variableTree.initializer(); if(initializer != null && !isConstant(variableTree)) { return Lists.newArrayList(initializer); } if(variableTree.parent().is(CATCH)) { // catch variable are counted as executable lines new ExecutableLinesTokenVisitor().scanTree(variableTree); } return Collections.emptyList(); }