public static int linesOfCode(Tree tree) { return new LineVisitor(tree).getLinesOfCodeNumber(); }
@Override public void visitScript(ScriptTree tree) { // ignore opening tag this.scan(tree.statements()); }
public LineVisitor(CompilationUnitTree tree) { this.visitCompilationUnit(tree); }
private void setLineAndCommentMeasures() { LineVisitor lineVisitor = new LineVisitor(context().tree()); ExecutableLineVisitor executableLineVisitor = new ExecutableLineVisitor(context().tree()); CommentLineVisitor commentVisitor = new CommentLineVisitor(context().tree()); fileMeasures.setLinesOfCodeNumber(lineVisitor.getLinesOfCodeNumber()); fileMeasures.setCommentLinesNumber(commentVisitor.commentLineNumber()); Set<Integer> linesOfCode = lineVisitor.getLinesOfCode(); linesOfCode.forEach(lineOfCode -> fileLinesContext.setIntValue(CoreMetrics.NCLOC_DATA_KEY, lineOfCode, 1)); executableLineVisitor.getExecutableLines().forEach(line -> fileLinesContext.setIntValue(CoreMetrics.EXECUTABLE_LINES_DATA_KEY, line, 1)); fileLinesContext.save(); }
public static int getNumberOfLines(FunctionTree declaration) { if (!declaration.body().is(Kind.BLOCK)) { return 0; } return LineVisitor.linesOfCode(declaration); }
@Test public void test_lines_of_code() throws Exception { LineVisitor lineVisitor = new LineVisitor(parse("metrics/lines_of_code.php")); Set<Integer> linesOfCode = lineVisitor.getLinesOfCode(); assertThat(linesOfCode).hasSize(7); assertThat(linesOfCode).contains(13, 17, 19, 20, 21, 22, 23); }
private void setLineAndCommentMeasures() { LineVisitor lineVisitor = new LineVisitor(context().tree()); ExecutableLineVisitor executableLineVisitor = new ExecutableLineVisitor(context().tree()); CommentLineVisitor commentVisitor = new CommentLineVisitor(context().tree()); fileMeasures.setLinesOfCodeNumber(lineVisitor.getLinesOfCodeNumber()); fileMeasures.setCommentLinesNumber(commentVisitor.commentLineNumber()); Set<Integer> linesOfCode = lineVisitor.getLinesOfCode(); linesOfCode.forEach(lineOfCode -> fileLinesContext.setIntValue(CoreMetrics.NCLOC_DATA_KEY, lineOfCode, 1)); executableLineVisitor.getExecutableLines().forEach(line -> fileLinesContext.setIntValue(CoreMetrics.EXECUTABLE_LINES_DATA_KEY, line, 1)); fileLinesContext.save(); }
public static int getNumberOfLines(FunctionTree declaration) { if (!declaration.body().is(Kind.BLOCK)) { return 0; } return LineVisitor.linesOfCode(declaration); }
public static int linesOfCode(Tree tree) { return new LineVisitor(tree).getLinesOfCodeNumber(); }
private void checkCaseClause(SwitchCaseClauseTree clause) { int lines = LineVisitor.linesOfCode(clause); if (lines > max) { context().newIssue(this, clause.caseToken(), String.format(MESSAGE, lines, max)); } } }
@Override public void visitScript(ScriptTree tree) { // ignore opening tag this.scan(tree.statements()); }
public LineVisitor(CompilationUnitTree tree) { this.visitCompilationUnit(tree); }
@Test public void test_lines_of_code_number() throws Exception { LineVisitor lineVisitor = new LineVisitor(parse("metrics/lines_of_code.php")); assertThat(lineVisitor.getLinesOfCodeNumber()).isEqualTo(7); }
private void checkCaseClause(SwitchCaseClauseTree clause) { int lines = LineVisitor.linesOfCode(clause); if (lines > max) { context().newIssue(this, clause.caseToken(), String.format(MESSAGE, lines, max)); } } }
@Override public void visitCompilationUnit(CompilationUnitTree tree) { int numberOfLines = LineVisitor.linesOfCode(tree); if (numberOfLines > max) { String fileName = context().getPhpFile().filename(); context().newFileIssue(this, String.format(MESSAGE, fileName, numberOfLines, max)); } }
private void checkClass(ClassTree tree) { int numberOfLines = LineVisitor.linesOfCode(tree); if (numberOfLines > maximumLinesThreshold) { String message; if (tree.is(Tree.Kind.ANONYMOUS_CLASS)) { message = String.format(MESSAGE_ANONYMOUS_CLASS, numberOfLines, maximumLinesThreshold); } else { message = String.format(MESSAGE, ((ClassDeclarationTree) tree).name().text(), numberOfLines, maximumLinesThreshold); } context().newIssue(this, tree.classToken(), message); } } }
@Override public void visitCompilationUnit(CompilationUnitTree tree) { int numberOfLines = LineVisitor.linesOfCode(tree); if (numberOfLines > max) { String fileName = context().getPhpFile().filename(); context().newFileIssue(this, String.format(MESSAGE, fileName, numberOfLines, max)); } }
private void checkClass(ClassTree tree) { int numberOfLines = LineVisitor.linesOfCode(tree); if (numberOfLines > maximumLinesThreshold) { String message; if (tree.is(Tree.Kind.ANONYMOUS_CLASS)) { message = String.format(MESSAGE_ANONYMOUS_CLASS, numberOfLines, maximumLinesThreshold); } else { message = String.format(MESSAGE, ((ClassDeclarationTree) tree).name().text(), numberOfLines, maximumLinesThreshold); } context().newIssue(this, tree.classToken(), message); } } }
@Test public void test_lines_of_code_number_on_tree() throws Exception { CompilationUnitTree cut = parse("metrics/lines_of_code.php"); Optional<ClassDeclarationTree> firstClassTree = cut.script().statements().stream() .filter(statement -> statement.is(Tree.Kind.CLASS_DECLARATION)) .map(ClassDeclarationTree.class::cast) .findFirst(); assertThat(firstClassTree).isPresent(); assertThat(LineVisitor.linesOfCode(firstClassTree.get())).isEqualTo(4); }