Examples of DetailAST


Examples of com.puppycrawl.tools.checkstyle.api.DetailAST

    public void visitToken(DetailAST aAST)
    {
        switch (aAST.getType()) {
        case TokenTypes.PARAMETER_DEF :
        case TokenTypes.VARIABLE_DEF : {
            final DetailAST nameAST = aAST.findFirstToken(TokenTypes.IDENT);
            this.mFrames.current().addName(nameAST.getText());
            break;
        }
        case TokenTypes.CLASS_DEF :
        case TokenTypes.INTERFACE_DEF :
        case TokenTypes.ENUM_DEF :
        case TokenTypes.ANNOTATION_DEF : {
            final DetailAST nameAST = aAST.findFirstToken(TokenTypes.IDENT);
            this.mFrames.current().addName(nameAST.getText());
            this.mFrames.enter(new ClassFrame());
            break;
        }
        case TokenTypes.SLIST :
            this.mFrames.enter(new BlockFrame());
View Full Code Here

Examples of com.puppycrawl.tools.checkstyle.api.DetailAST

     * @return whether a token follows an empty for iterator
     */
    private boolean isFollowsEmptyForIterator(DetailAST aAST)
    {
        boolean followsEmptyForIterator = false;
        final DetailAST parent = aAST.getParent();
        //Only traditional for statements are examined, not for-each statements
        if ((parent != null)
            && (parent.getType() == TokenTypes.LITERAL_FOR)
            && (parent.findFirstToken(TokenTypes.FOR_EACH_CLAUSE) == null))
        {
            final DetailAST forIterator =
                parent.findFirstToken(TokenTypes.FOR_ITERATOR);
            followsEmptyForIterator = (forIterator.getChildCount() == 0)
                && (aAST == forIterator.getNextSibling());
        }
        return followsEmptyForIterator;
    }
View Full Code Here

Examples of com.puppycrawl.tools.checkstyle.api.DetailAST

    }

    @Override
    public void visitToken(DetailAST aAST)
    {
        final DetailAST slistAST = aAST.findFirstToken(TokenTypes.SLIST);
        boolean isElseIf = false;
        if ((aAST.getType() == TokenTypes.LITERAL_ELSE)
            && (aAST.findFirstToken(TokenTypes.LITERAL_IF) != null))
        {
            isElseIf = true;
View Full Code Here

Examples of com.puppycrawl.tools.checkstyle.api.DetailAST

     * @return whether a token preceeds an empty for initializer
     */
    private boolean isPreceedsEmptyForInit(DetailAST aAST)
    {
        boolean preceedsEmptyForInintializer = false;
        final DetailAST parent = aAST.getParent();
        //Only traditional for statements are examined, not for-each statements
        if ((parent != null)
            && (parent.getType() == TokenTypes.LITERAL_FOR)
            && (parent.findFirstToken(TokenTypes.FOR_EACH_CLAUSE) == null))
        {
            final DetailAST forIterator =
                    parent.findFirstToken(TokenTypes.FOR_INIT);
            preceedsEmptyForInintializer = (forIterator.getChildCount() == 0)
                    && (aAST == forIterator.getPreviousSibling());
        }
        return preceedsEmptyForInintializer;
    }
View Full Code Here

Examples of com.puppycrawl.tools.checkstyle.api.DetailAST

    }

    @Override
    public void visitToken(DetailAST aAST)
    {
        final DetailAST openingBrace = aAST.findFirstToken(TokenTypes.SLIST);
        if (openingBrace != null) {
            final DetailAST closingBrace =
                openingBrace.findFirstToken(TokenTypes.RCURLY);
            int length =
                closingBrace.getLineNo() - openingBrace.getLineNo() + 1;

            if (!mCountEmpty) {
                final FileContents contents = getFileContents();
                final int lastLine = closingBrace.getLineNo();
                for (int i = openingBrace.getLineNo() - 1; i < lastLine; i++) {
                    if (contents.lineIsBlank(i) || contents.lineIsComment(i)) {
                        length--;
                    }
                }
View Full Code Here

Examples of com.puppycrawl.tools.checkstyle.api.DetailAST

    @Override
    public void visitToken(DetailAST aAST)
    {
        final Object[] message;
        final DetailAST targetAST;
        if (aAST.getType() == TokenTypes.TYPECAST) {
            targetAST = aAST.findFirstToken(TokenTypes.RPAREN);
            // TODO: i18n
            message = new Object[]{"cast"};
        }
        else {
            targetAST = aAST;
            message = new Object[]{aAST.getText()};
        }
        final String line = getLines()[targetAST.getLineNo() - 1];
        final int after =
            targetAST.getColumnNo() + targetAST.getText().length();

        if (after < line.length()) {

            final char charAfter = line.charAt(after);
            if ((targetAST.getType() == TokenTypes.SEMI)
                && ((charAfter == ';') || (charAfter == ')')))
            {
                return;
            }
            if (!Character.isWhitespace(charAfter)) {
                //empty FOR_ITERATOR?
                if (targetAST.getType() == TokenTypes.SEMI) {
                    final DetailAST sibling =
                        (DetailAST) targetAST.getNextSibling();
                    if ((sibling != null)
                        && (sibling.getType() == TokenTypes.FOR_ITERATOR)
                        && (sibling.getChildCount() == 0))
                    {
                        return;
                    }
                }
                log(targetAST.getLineNo(),
View Full Code Here

Examples of com.puppycrawl.tools.checkstyle.api.DetailAST

    @Override
    public void visitToken(DetailAST aAST)
    {
        final int type = aAST.getType();
        final boolean surrounded = isSurrounded(aAST);
        final DetailAST parent = aAST.getParent();

        if ((type == TokenTypes.ASSIGN)
            && (parent.getType() == TokenTypes.ANNOTATION_MEMBER_VALUE_PAIR))
        {
            // shouldn't process assign in annotation pairs
            return;
        }

        // An identifier surrounded by parentheses.
        if (surrounded && (type == TokenTypes.IDENT)) {
            mParentToSkip = aAST.getParent();
            log(aAST, "unnecessary.paren.ident", aAST.getText());
            return;
        }

        // A literal (numeric or string) surrounded by parentheses.
        if (surrounded && inTokenList(type, LITERALS)) {
            mParentToSkip = aAST.getParent();
            if (type == TokenTypes.STRING_LITERAL) {
                log(aAST, "unnecessary.paren.string",
                    chopString(aAST.getText()));
            }
            else {
                log(aAST, "unnecessary.paren.literal", aAST.getText());
            }
            return;
        }

        // The rhs of an assignment surrounded by parentheses.
        if (inTokenList(type, ASSIGNMENTS)) {
            mAssignDepth++;
            final DetailAST last = aAST.getLastChild();
            if (last.getType() == TokenTypes.RPAREN) {
                log(aAST, "unnecessary.paren.assign");
            }
        }
    }
View Full Code Here

Examples of com.puppycrawl.tools.checkstyle.api.DetailAST

    }

    @Override
    public void visitToken(DetailAST aAST)
    {
        final DetailAST parenAST;
        if ((aAST.getType() == TokenTypes.METHOD_CALL)) {
            parenAST = aAST;
        }
        else {
            parenAST = aAST.findFirstToken(TokenTypes.LPAREN);
            // array construction => parenAST == null
            if (parenAST == null) {
                return;
            }
        }

        final String line = getLines()[parenAST.getLineNo() - 1];
        if (Utils.whitespaceBefore(parenAST.getColumnNo(), line)) {
            if (!mAllowLineBreaks) {
                log(parenAST, "line.previous", parenAST.getText());
            }
        }
        else {
            final int before = parenAST.getColumnNo() - 1;
            if ((PadOption.NOSPACE == getAbstractOption())
                && (Character.isWhitespace(line.charAt(before))))
            {
                log(parenAST , "ws.preceded", parenAST.getText());
            }
            else if ((PadOption.SPACE == getAbstractOption())
                     && !Character.isWhitespace(line.charAt(before)))
            {
                log(parenAST, "ws.notPreceded", parenAST.getText());
            }
        }
    }
View Full Code Here

Examples of com.puppycrawl.tools.checkstyle.api.DetailAST

    @Override
    public void leaveToken(DetailAST aAST)
    {
        final int type = aAST.getType();
        final DetailAST parent = aAST.getParent();

        if ((type == TokenTypes.ASSIGN)
            && (parent.getType() == TokenTypes.ANNOTATION_MEMBER_VALUE_PAIR))
        {
            // shouldn't process assign in annotation pairs
            return;
        }
View Full Code Here

Examples of com.puppycrawl.tools.checkstyle.api.DetailAST

     * @return <code>true</code> if <code>aAST</code> is surrounded by
     *         parentheses.
     */
    private boolean isSurrounded(DetailAST aAST)
    {
        final DetailAST prev = aAST.getPreviousSibling();
        final DetailAST next = (DetailAST) aAST.getNextSibling();

        return (prev != null) && (prev.getType() == TokenTypes.LPAREN)
            && (next != null) && (next.getType() == TokenTypes.RPAREN);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.