Search in sources :

Example 81 with DetailAST

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

the class BlockParentHandler method checkIndentation.

@Override
public void checkIndentation() {
    checkTopLevelToken();
    // separate to allow for eventual configuration
    checkLeftParen(getLeftParen());
    checkRightParen(getLeftParen(), getRightParen());
    if (hasCurlies()) {
        checkLeftCurly();
        checkRightCurly();
    }
    final DetailAST listChild = getListChild();
    if (listChild == null) {
        checkNonListChild();
    } else {
        // NOTE: switch statements usually don't have curlies
        if (!hasCurlies() || !areOnSameLine(getLeftCurly(), getRightCurly())) {
            checkChildren(listChild, getCheckedChildren(), getChildrenExpectedIndent(), true, canChildrenBeNested());
        }
    }
}
Also used : DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST)

Example 82 with DetailAST

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

the class ClassDefHandler method checkIndentation.

@Override
public void checkIndentation() {
    final DetailAST modifiers = getMainAst().findFirstToken(TokenTypes.MODIFIERS);
    if (modifiers.getChildCount() == 0) {
        final DetailAST ident = getMainAst().findFirstToken(TokenTypes.IDENT);
        final int lineStart = getLineStart(ident);
        if (!getIndent().isAcceptable(lineStart)) {
            logError(ident, "ident", lineStart);
        }
    } else {
        checkModifiers();
    }
    checkWrappingIndentation(getMainAst(), getMainAst().getLastChild());
    super.checkIndentation();
}
Also used : DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST)

Example 83 with DetailAST

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

the class CommentsIndentationCheck method getPrevStatementFromSwitchBlock.

/**
     * Gets comment's previous statement from switch block.
     * @param comment {@link TokenTypes#SINGLE_LINE_COMMENT single-line comment}.
     * @return comment's previous statement or null if previous statement is absent.
     */
private static DetailAST getPrevStatementFromSwitchBlock(DetailAST comment) {
    final DetailAST prevStmt;
    final DetailAST parentStatement = comment.getParent();
    if (parentStatement.getType() == TokenTypes.CASE_GROUP) {
        prevStmt = getPrevStatementWhenCommentIsUnderCase(parentStatement);
    } else {
        prevStmt = getPrevCaseToken(parentStatement);
    }
    return prevStmt;
}
Also used : DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST)

Example 84 with DetailAST

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

the class CommentsIndentationCheck method isDistributedReturnStatement.

/**
     * Checks whether the previous statement of a comment is a destributed return statement.
     * @param commentPreviousSibling previous sibling of the comment.
     * @return true if the previous statement of a comment is a destributed return statement.
     */
private static boolean isDistributedReturnStatement(DetailAST commentPreviousSibling) {
    boolean isDistributed = false;
    if (commentPreviousSibling != null && commentPreviousSibling.getType() == TokenTypes.LITERAL_RETURN) {
        final DetailAST firstChild = commentPreviousSibling.getFirstChild();
        final DetailAST nextSibling = firstChild.getNextSibling();
        if (nextSibling != null) {
            isDistributed = true;
        }
    }
    return isDistributed;
}
Also used : DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST)

Example 85 with DetailAST

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

the class CommentsIndentationCheck method isTrailingBlockComment.

/**
     * Checks if current comment block is trailing comment, e.g.:
     * <p>
     * {@code
     * double d = 3.14; /* some comment *&#47;
     * /* some comment *&#47; double d = 18.5;
     * }
     * </p>
     * @param blockComment {@link TokenTypes#BLOCK_COMMENT_BEGIN block comment begin}.
     * @return true if current comment block is trailing comment.
     */
private boolean isTrailingBlockComment(DetailAST blockComment) {
    final String commentLine = getLine(blockComment.getLineNo() - 1);
    final int commentColumnNo = blockComment.getColumnNo();
    final DetailAST nextSibling = blockComment.getNextSibling();
    return !CommonUtils.hasWhitespaceBefore(commentColumnNo, commentLine) || nextSibling != null && nextSibling.getLineNo() == blockComment.getLineNo();
}
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