Search in sources :

Example 96 with DetailAST

use of com.puppycrawl.tools.checkstyle.api.DetailAST in project checkstyle by checkstyle.

the class IllegalInstantiationCheck method processClassDef.

/**
     * Collects classes defined in the source file. Required
     * to avoid false alarms for local vs. java.lang classes.
     *
     * @param ast the class def token.
     */
private void processClassDef(DetailAST ast) {
    final DetailAST identToken = ast.findFirstToken(TokenTypes.IDENT);
    final String className = identToken.getText();
    classNames.add(className);
}
Also used : DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST)

Example 97 with DetailAST

use of com.puppycrawl.tools.checkstyle.api.DetailAST in project checkstyle by checkstyle.

the class IllegalTypeCheck method isVerifiable.

/**
     * Checks if current method's return type or variable's type is verifiable
     * according to <b>memberModifiers</b> option.
     * @param methodOrVariableDef METHOD_DEF or VARIABLE_DEF ast node.
     * @return true if member is verifiable according to <b>memberModifiers</b> option.
     */
private boolean isVerifiable(DetailAST methodOrVariableDef) {
    boolean result = true;
    if (memberModifiers != null) {
        final DetailAST modifiersAst = methodOrVariableDef.findFirstToken(TokenTypes.MODIFIERS);
        result = isContainVerifiableType(modifiersAst);
    }
    return result;
}
Also used : DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST)

Example 98 with DetailAST

use of com.puppycrawl.tools.checkstyle.api.DetailAST in project checkstyle by checkstyle.

the class IllegalTypeCheck method getNextSubTreeNode.

/**
     * Gets the next node of a syntactical tree (child of a current node or
     * sibling of a current node, or sibling of a parent of a current node).
     * @param currentNodeAst Current node in considering
     * @param subTreeRootAst SubTree root
     * @return Current node after bypassing, if current node reached the root of a subtree
     *        method returns null
     */
private static DetailAST getNextSubTreeNode(DetailAST currentNodeAst, DetailAST subTreeRootAst) {
    DetailAST currentNode = currentNodeAst;
    DetailAST toVisitAst = currentNode.getFirstChild();
    while (toVisitAst == null) {
        toVisitAst = currentNode.getNextSibling();
        if (toVisitAst == null) {
            if (currentNode.getParent().equals(subTreeRootAst)) {
                break;
            }
            currentNode = currentNode.getParent();
        }
    }
    return toVisitAst;
}
Also used : DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST)

Example 99 with DetailAST

use of com.puppycrawl.tools.checkstyle.api.DetailAST in project checkstyle by checkstyle.

the class IllegalTypeCheck method checkClassName.

/**
     * Checks type of given method, parameter or variable.
     * @param ast node to check.
     */
private void checkClassName(DetailAST ast) {
    final DetailAST type = ast.findFirstToken(TokenTypes.TYPE);
    final FullIdent ident = CheckUtils.createFullType(type);
    if (isMatchingClassName(ident.getText())) {
        log(ident.getLineNo(), ident.getColumnNo(), MSG_KEY, ident.getText());
    }
}
Also used : DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST) FullIdent(com.puppycrawl.tools.checkstyle.api.FullIdent)

Example 100 with DetailAST

use of com.puppycrawl.tools.checkstyle.api.DetailAST in project checkstyle by checkstyle.

the class IllegalTypeCheck method isStarImport.

/**
     * Checks if current import is star import. E.g.:
     * <p>
     * {@code
     * import java.util.*;
     * }
     * </p>
     * @param importAst {@link TokenTypes#IMPORT Import}
     * @return true if it is star import
     */
private static boolean isStarImport(DetailAST importAst) {
    boolean result = false;
    DetailAST toVisit = importAst;
    while (toVisit != null) {
        toVisit = getNextSubTreeNode(toVisit, importAst);
        if (toVisit != null && toVisit.getType() == TokenTypes.STAR) {
            result = true;
            break;
        }
    }
    return result;
}
Also used : DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST)

Aggregations

DetailAST (com.puppycrawl.tools.checkstyle.api.DetailAST)397 Test (org.junit.Test)74 CommonHiddenStreamToken (antlr.CommonHiddenStreamToken)14 FullIdent (com.puppycrawl.tools.checkstyle.api.FullIdent)14 ArrayList (java.util.ArrayList)13 AST (antlr.collections.AST)8 Method (java.lang.reflect.Method)7 LinkedList (java.util.LinkedList)7 Scope (com.puppycrawl.tools.checkstyle.api.Scope)6 HashSet (java.util.HashSet)6 FileContents (com.puppycrawl.tools.checkstyle.api.FileContents)5 ArrayDeque (java.util.ArrayDeque)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 DetailNode (com.puppycrawl.tools.checkstyle.api.DetailNode)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 AbstractCheck (com.puppycrawl.tools.checkstyle.api.AbstractCheck)3 CheckstyleException (com.puppycrawl.tools.checkstyle.api.CheckstyleException)3 TokenTypes (com.puppycrawl.tools.checkstyle.api.TokenTypes)3 SimpleEntry (java.util.AbstractMap.SimpleEntry)3 HashMap (java.util.HashMap)3