public static int getNumberOfLines(FunctionTree declaration) { Tree body = declaration.body(); if (!body.is(Kind.BLOCK)) { return 0; } BlockTree block = (BlockTree) body; int firstLine = block.openCurlyBraceToken().line(); int lastLine = block.closeCurlyBraceToken().line(); return lastLine - firstLine + 1; }
private static boolean endsWithReturn(FunctionTree function) { Tree body = function.body(); if (body.is(Kind.BLOCK)) { BlockTree block = (BlockTree) body; List<StatementTree> statements = block.statements(); if (statements.isEmpty()) { return false; } return statements.get(statements.size() - 1).is(Kind.RETURN_STATEMENT); } return false; }
private void processFunction(FunctionTree tree) { if (tree.is(Kind.FUNCTION_EXPRESSION) || !endsWithReturn(tree)) { incrementComplexity(); } }