Search in sources :

Example 61 with DetailAST

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

the class PackageDefHandler method checkIndentation.

@Override
public void checkIndentation() {
    final int columnNo = expandedTabsColumnNo(getMainAst());
    if (!getIndent().isAcceptable(columnNo) && isOnStartOfLine(getMainAst())) {
        logError(getMainAst(), "", columnNo);
    }
    final DetailAST semi = getMainAst().findFirstToken(TokenTypes.SEMI);
    checkWrappingIndentation(getMainAst(), semi);
}
Also used : DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST)

Example 62 with DetailAST

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

the class SynchronizedHandler method checkSynchronizedExpr.

/**
     * Check indentation of expression we synchronized on.
     */
private void checkSynchronizedExpr() {
    final DetailAST syncAst = getMainAst().findFirstToken(TokenTypes.LPAREN).getNextSibling();
    final IndentLevel expected = new IndentLevel(getIndent(), getBasicOffset());
    checkExpressionSubtree(syncAst, expected, false, false);
}
Also used : DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST)

Example 63 with DetailAST

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

the class WhileHandler method checkCondExpr.

/**
     * Check the indentation of the conditional expression.
     */
private void checkCondExpr() {
    final DetailAST condAst = getMainAst().findFirstToken(TokenTypes.EXPR);
    final IndentLevel expected = new IndentLevel(getIndent(), getBasicOffset());
    checkExpressionSubtree(condAst, expected, false, false);
}
Also used : DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST)

Example 64 with DetailAST

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

the class JavadocMethodCheck method hasAllowedAnnotations.

/**
     * Some javadoc.
     * @param methodDef Some javadoc.
     * @return Some javadoc.
     */
private boolean hasAllowedAnnotations(DetailAST methodDef) {
    final DetailAST modifiersNode = methodDef.findFirstToken(TokenTypes.MODIFIERS);
    DetailAST annotationNode = modifiersNode.findFirstToken(TokenTypes.ANNOTATION);
    while (annotationNode != null && annotationNode.getType() == TokenTypes.ANNOTATION) {
        DetailAST identNode = annotationNode.findFirstToken(TokenTypes.IDENT);
        if (identNode == null) {
            identNode = annotationNode.findFirstToken(TokenTypes.DOT).findFirstToken(TokenTypes.IDENT);
        }
        if (allowedAnnotations.contains(identNode.getText())) {
            return true;
        }
        annotationNode = annotationNode.getNextSibling();
    }
    return false;
}
Also used : DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST)

Example 65 with DetailAST

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

the class JavadocMethodCheck method calculateScope.

/**
     * Returns the scope for the method/constructor at the specified AST. If
     * the method is in an interface or annotation block, the scope is assumed
     * to be public.
     *
     * @param ast the token of the method/constructor
     * @return the scope of the method/constructor
     */
private static Scope calculateScope(final DetailAST ast) {
    final DetailAST mods = ast.findFirstToken(TokenTypes.MODIFIERS);
    final Scope declaredScope = ScopeUtils.getScopeFromMods(mods);
    if (ScopeUtils.isInInterfaceOrAnnotationBlock(ast)) {
        return Scope.PUBLIC;
    } else {
        return declaredScope;
    }
}
Also used : Scope(com.puppycrawl.tools.checkstyle.api.Scope) 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