コード例 #1
0
  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;
  }
コード例 #2
0
 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;
 }
コード例 #3
0
 private void processFunction(FunctionTree tree) {
   if (tree.is(Kind.FUNCTION_EXPRESSION) || !endsWithReturn(tree)) {
     incrementComplexity();
   }
 }