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());
}
}
}
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();
}
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;
}
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;
}
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 */
* /* some comment */ 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();
}
Aggregations