Search in sources :

Example 16 with FullIdent

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

the class IllegalInstantiationCheck method postProcessLiteralNew.

/**
     * Processes one of the collected "new" tokens when walking tree
     * has finished.
     * @param newTokenAst the "new" token.
     */
private void postProcessLiteralNew(DetailAST newTokenAst) {
    final DetailAST typeNameAst = newTokenAst.getFirstChild();
    final AST nameSibling = typeNameAst.getNextSibling();
    if (nameSibling.getType() != TokenTypes.ARRAY_DECLARATOR) {
        // ast != "new Boolean[]"
        final FullIdent typeIdent = FullIdent.createFullIdent(typeNameAst);
        final String typeName = typeIdent.getText();
        final int lineNo = newTokenAst.getLineNo();
        final int colNo = newTokenAst.getColumnNo();
        final String fqClassName = getIllegalInstantiation(typeName);
        if (fqClassName != null) {
            log(lineNo, colNo, MSG_KEY, fqClassName);
        }
    }
}
Also used : AST(antlr.collections.AST) DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST) DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST) FullIdent(com.puppycrawl.tools.checkstyle.api.FullIdent)

Example 17 with FullIdent

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

the class IllegalInstantiationCheck method processPackageDef.

/**
     * Perform processing for an package token.
     * @param ast the package token
     */
private void processPackageDef(DetailAST ast) {
    final DetailAST packageNameAST = ast.getLastChild().getPreviousSibling();
    final FullIdent packageIdent = FullIdent.createFullIdent(packageNameAST);
    pkgName = packageIdent.getText();
}
Also used : DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST) FullIdent(com.puppycrawl.tools.checkstyle.api.FullIdent)

Example 18 with FullIdent

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

the class IllegalThrowsCheck method visitToken.

@Override
public void visitToken(DetailAST detailAST) {
    final DetailAST methodDef = detailAST.getParent();
    DetailAST token = detailAST.getFirstChild();
    // Check if the method with the given name should be ignored.
    if (!isIgnorableMethod(methodDef)) {
        while (token != null) {
            if (token.getType() != TokenTypes.COMMA) {
                final FullIdent ident = FullIdent.createFullIdent(token);
                if (illegalClassNames.contains(ident.getText())) {
                    log(token, MSG_KEY, ident.getText());
                }
            }
            token = token.getNextSibling();
        }
    }
}
Also used : DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST) FullIdent(com.puppycrawl.tools.checkstyle.api.FullIdent)

Aggregations

FullIdent (com.puppycrawl.tools.checkstyle.api.FullIdent)18 DetailAST (com.puppycrawl.tools.checkstyle.api.DetailAST)13 AST (antlr.collections.AST)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1