Search in sources :

Example 11 with DetailAST

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

the class AbstractExpressionHandler method findSubtreeLines.

/**
     * Find the set of lines for a given subtree.
     *
     * @param lines          the set of lines to add to
     * @param tree           the subtree to examine
     * @param allowNesting   whether or not to allow nested subtrees
     */
protected final void findSubtreeLines(LineSet lines, DetailAST tree, boolean allowNesting) {
    if (!indentCheck.getHandlerFactory().isHandledType(tree.getType())) {
        final int lineNum = tree.getLineNo();
        final Integer colNum = lines.getStartColumn(lineNum);
        final int thisLineColumn = expandedTabsColumnNo(tree);
        if (colNum == null || thisLineColumn < colNum) {
            lines.addLineAndCol(lineNum, thisLineColumn);
        }
        // check children
        for (DetailAST node = tree.getFirstChild(); node != null; node = node.getNextSibling()) {
            findSubtreeLines(lines, node, allowNesting);
        }
    }
}
Also used : DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST)

Example 12 with DetailAST

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

the class ArrayInitHandler method getIndentImpl.

@Override
protected IndentLevel getIndentImpl() {
    final DetailAST parentAST = getMainAst().getParent();
    final int type = parentAST.getType();
    if (type == TokenTypes.LITERAL_NEW || type == TokenTypes.ASSIGN) {
        // note: assumes new or assignment is line to align with
        return new IndentLevel(getLineStart(parentAST));
    } else {
        // at this point getParent() is instance of BlockParentHandler
        return ((BlockParentHandler) getParent()).getChildrenExpectedIndent();
    }
}
Also used : DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST)

Example 13 with DetailAST

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

the class BlockParentHandler method checkNonListChild.

/**
     * Check the indentation level of a child that is not a list of statements.
     */
private void checkNonListChild() {
    final DetailAST nonList = getNonListChild();
    if (nonList != null) {
        final IndentLevel expected = new IndentLevel(getIndent(), getBasicOffset());
        checkExpressionSubtree(nonList, expected, false, false);
    }
}
Also used : DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST)

Example 14 with DetailAST

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

the class BlockParentHandler method checkLeftCurly.

/**
     * Check the indentation of the left curly brace.
     */
protected void checkLeftCurly() {
    // the lcurly can either be at the correct indentation, or nested
    // with a previous expression
    final DetailAST lcurly = getLeftCurly();
    final int lcurlyPos = expandedTabsColumnNo(lcurly);
    if (!curlyIndent().isAcceptable(lcurlyPos) && isOnStartOfLine(lcurly)) {
        logError(lcurly, "lcurly", lcurlyPos, curlyIndent());
    }
}
Also used : DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST)

Example 15 with DetailAST

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

the class JavadocMethodCheck method getThrows.

/**
     * Computes the exception nodes for a method.
     *
     * @param ast the method node.
     * @return the list of exception nodes for ast.
     */
private List<ExceptionInfo> getThrows(DetailAST ast) {
    final List<ExceptionInfo> returnValue = new ArrayList<>();
    final DetailAST throwsAST = ast.findFirstToken(TokenTypes.LITERAL_THROWS);
    if (throwsAST != null) {
        DetailAST child = throwsAST.getFirstChild();
        while (child != null) {
            if (child.getType() == TokenTypes.IDENT || child.getType() == TokenTypes.DOT) {
                final FullIdent ident = FullIdent.createFullIdent(child);
                final ExceptionInfo exceptionInfo = new ExceptionInfo(createClassInfo(new Token(ident), getCurrentClassName()));
                returnValue.add(exceptionInfo);
            }
            child = child.getNextSibling();
        }
    }
    return returnValue;
}
Also used : DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST) ArrayList(java.util.ArrayList) FullIdent(com.puppycrawl.tools.checkstyle.api.FullIdent)

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