public static int getNumberOfLines(FunctionTree declaration) { if (!declaration.body().is(Kind.BLOCK)) { return 0; } return LineVisitor.linesOfCode(declaration); }
public static int getNumberOfLines(FunctionTree declaration) { if (!declaration.body().is(Kind.BLOCK)) { return 0; } return LineVisitor.linesOfCode(declaration); }
private void checkCaseClause(SwitchCaseClauseTree clause) { int lines = LineVisitor.linesOfCode(clause); if (lines > max) { context().newIssue(this, clause.caseToken(), String.format(MESSAGE, lines, max)); } } }
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)); } }
@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); } } }
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); }