Package com.puppycrawl.tools.checkstyle.api

Examples of com.puppycrawl.tools.checkstyle.api.DetailAST


    final String fileName = aFile.getPath();

    try {
      final FileContents contents = new FileContents(fileName, aLines
          .toArray(new String[aLines.size()]));
      final DetailAST rootAST = TreeWalker.parse(contents);
      walk(rootAST, contents);
    } catch (final RecognitionException re) {
      Utils.getExceptionLogger()
          .debug("RecognitionException occured.", re);
      getMessageCollector().add(
View Full Code Here


      return;
    }

    notifyVisit(aAST);

    final DetailAST child = aAST.getFirstChild();
    if (child != null) {
      processRec(child);
    }

    notifyLeave(aAST);

    final DetailAST sibling = aAST.getNextSibling();
    if (sibling != null) {
      processRec(sibling);
    }
  }
View Full Code Here

   * Uses iterative algorithm.
   *
   * @param aRoot the root of tree for process
   */
  private void processIter(DetailAST aRoot) {
    DetailAST curNode = aRoot;
    while (curNode != null) {
      notifyVisit(curNode);
      DetailAST toVisit = curNode.getFirstChild();
      while ((curNode != null) && (toVisit == null)) {
        notifyLeave(curNode);
        toVisit = curNode.getNextSibling();
        if (toVisit == null) {
          curNode = curNode.getParent();
View Full Code Here

  private boolean isApi(DetailAST ast) {
    if ("serialVersionUID".equals(getName(ast))) {
      // this should not be considered API
      return false;
    }
    DetailAST modifiers = ast.findFirstToken(TokenTypes.MODIFIERS);
    if (null != modifiers) {
      if (isAllMethods) {
        // if public then it is API
        if (isInterface || null != modifiers.findFirstToken(TokenTypes.LITERAL_PUBLIC)) {
          return true;
        }
      }
      DetailAST check = modifiers.getFirstChild();
      while (null != check) {
        if (TokenTypes.ANNOTATION == check.getType() && "Api".equals(getName(check))) {
          return true;
        }
        check = check.getNextSibling();
      }
    }
    return false;
  }
View Full Code Here

  private String getSignature(DetailAST ast) {
    String returnType = "";
    String name = getName(ast);
    String parameters = "";
    if (TokenTypes.METHOD_DEF == ast.getType() || TokenTypes.VARIABLE_DEF == ast.getType()) {
      DetailAST modifiersAst = ast.findFirstToken(TokenTypes.MODIFIERS);
      if (null != modifiersAst) {
        if (null != modifiersAst.findFirstToken(TokenTypes.LITERAL_STATIC)) {
          returnType += "static ";
        }
        if (null != modifiersAst.findFirstToken(TokenTypes.FINAL)) {
          returnType += "final ";
        }
      }
      returnType += getTypeAsString(ast.findFirstToken(TokenTypes.TYPE)) + " ";
    }
    if (TokenTypes.METHOD_DEF == ast.getType() || TokenTypes.CTOR_DEF == ast.getType()) {
      DetailAST parametersAst = ast.findFirstToken(TokenTypes.PARAMETERS);
      if (null != parametersAst) {
        DetailAST check = parametersAst.getFirstChild();
        while (null != check) {
          if (TokenTypes.PARAMETER_DEF == check.getType()) {
            parameters += getTypeAsString(check.findFirstToken(TokenTypes.TYPE)) + ", ";
          }
          check = check.getNextSibling();
        }
        parameters = "(" + parameters + ")";
      }
    }
    return returnType + name + parameters;
View Full Code Here

  }

  private String getTypeAsString(DetailAST typeAst) {
    String type = "";
    if (null != typeAst) {
      DetailAST ast = typeAst.getFirstChild();
      if (TokenTypes.ARRAY_DECLARATOR == ast.getType()) {
        type += getTypeAsString(ast);
        type += "[]";
      } else {
        type += ast.getText();
        if (TokenTypes.IDENT == ast.getType()) {
          ast = ast.getNextSibling();
          if (null != ast && TokenTypes.TYPE_ARGUMENTS == ast.getType()) {
            DetailAST genAst = ast.getFirstChild();
            while (null != genAst) {
              if (TokenTypes.TYPE_ARGUMENT == genAst.getType()) {
                type += getTypeAsString(genAst);
              } else {
                type += genAst.getText();
              }
              genAst = genAst.getNextSibling();
            }
          }
        }
      }
    }
View Full Code Here

    }
    return type;
  }

  private void checkClassAnnotation(DetailAST ast) {
    DetailAST check = ast.getFirstChild();
    if (TokenTypes.MODIFIERS == check.getType()) {
      check = check.getFirstChild();
      while (null != check) {
        if (TokenTypes.ANNOTATION == check.getType() && "Api".equals(getName(check))) {
          isAnnotated = true;
          classSince = getSince(ast);
          DetailAST param = getToken(TokenTypes.ANNOTATION_MEMBER_VALUE_PAIR, check);
          if (null != param) {
            DetailAST expr = param.getLastChild();
            isAllMethods = "true".equals(expr.getFirstChild().getText());
          }
        }
        check = check.getNextSibling();
      }
    }
View Full Code Here

      }
    }
  }

  private String getName(DetailAST ast) {
    DetailAST check = ast.getFirstChild();
    String name = null;
    while (null == name && null != check) {
      if (TokenTypes.IDENT == check.getType()) {
        name = check.getText();
      }
      check = check.getNextSibling();
    }
    return name;
  }
View Full Code Here

    }
    return name;
  }

  private DetailAST getToken(int type, DetailAST ast) {
    DetailAST check = ast.getFirstChild();
    while (null != check) {
      if (type == check.getType()) {
        return check;
      }
      check = check.getNextSibling();
    }
    return null;
  }
View Full Code Here

      case TokenTypes.DOT:
        return getPackage(ast.getFirstChild()) + "." + getPackage(ast.getLastChild());
      case TokenTypes.IDENT:
        return ast.getText();
      case TokenTypes.PACKAGE_DEF:
        DetailAST check = ast.getFirstChild();
        String name = null;
        while (null == name && null != check) {
          name = getPackage(check);
          check = check.getNextSibling();
        }
        return name;
      default:
        return null;
    }
View Full Code Here

TOP

Related Classes of com.puppycrawl.tools.checkstyle.api.DetailAST

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.