Package com.puppycrawl.tools.checkstyle.api

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


    @Override
    public void visitToken(DetailAST aAST)
    {
        if (mustCheckName(aAST)) {
            final DetailAST nameAST = aAST.findFirstToken(TokenTypes.IDENT);
            if (!getRegexp().matcher(nameAST.getText()).find()) {
                log(nameAST.getLineNo(),
                    nameAST.getColumnNo(),
                    "name.invalidPattern",
                    nameAST.getText(),
                    getFormat());
            }
        }
    }
View Full Code Here


    }

    @Override
    public void visitToken(DetailAST aAST)
    {
        final DetailAST objBlock = aAST.findFirstToken(TokenTypes.OBJBLOCK);
        DetailAST child = (DetailAST) objBlock.getFirstChild();
        boolean hasMethodOrField = false;
        boolean hasNonStaticMethodOrField = false;
        boolean hasDefaultCtor = true;
        boolean hasPublicCtor = false;

        while (child != null) {
            final int type = child.getType();
            if (type == TokenTypes.METHOD_DEF
                    || type == TokenTypes.VARIABLE_DEF)
            {
                hasMethodOrField = true;
                final DetailAST modifiers =
                    child.findFirstToken(TokenTypes.MODIFIERS);
                final boolean isStatic =
                    modifiers.branchContains(TokenTypes.LITERAL_STATIC);
                final boolean isPrivate =
                    modifiers.branchContains(TokenTypes.LITERAL_PRIVATE);

                if (!isStatic && !isPrivate) {
                    hasNonStaticMethodOrField = true;
                }
            }
            if (type == TokenTypes.CTOR_DEF) {
                hasDefaultCtor = false;
                final DetailAST modifiers =
                    child.findFirstToken(TokenTypes.MODIFIERS);
                if (!modifiers.branchContains(TokenTypes.LITERAL_PRIVATE)
                    && !modifiers.branchContains(TokenTypes.LITERAL_PROTECTED))
                {
                    // treat package visible as public
                    // for the purpose of this Check
                    hasPublicCtor = true;
                }
View Full Code Here

    @Override
    protected final boolean mustCheckName(DetailAST aAST)
    {
        boolean retVal = false;

        final DetailAST modifiersAST =
            aAST.findFirstToken(TokenTypes.MODIFIERS);
        final boolean isStatic = (modifiersAST != null)
            && modifiersAST.branchContains(TokenTypes.LITERAL_STATIC);
        final boolean isFinal = (modifiersAST != null)
            && modifiersAST.branchContains(TokenTypes.FINAL);

        if ((isStatic  && isFinal)
            || ScopeUtils.inInterfaceOrAnnotationBlock(aAST))
        {
            // Handle the serialVersionUID and serialPersistentFields  constants
            // which are used for Serialization. Cannot enforce rules on it. :-)
            final DetailAST nameAST = aAST.findFirstToken(TokenTypes.IDENT);
            if ((nameAST != null)
                && !("serialVersionUID".equals(nameAST.getText()))
                && !("serialPersistentFields".equals(nameAST.getText())))
            {
                retVal = true;
            }
        }
View Full Code Here

    private void visitClassDef(DetailAST aClass)
    {
        // we are not use inner classes because they can not
        // have static methods
        if (mClassDepth == 0) {
            final DetailAST ident = aClass.findFirstToken(TokenTypes.IDENT);
            mCurrentClass = mPackage.getText() + "." + ident.getText();
            mClassDepth++;
        }
    }
View Full Code Here

     * @param aMethod the METHOD_DEF node
     * @return true if check passed, false otherwise
     */
    private boolean checkName(DetailAST aMethod)
    {
        final DetailAST ident = aMethod.findFirstToken(TokenTypes.IDENT);
        return "main".equals(ident.getText());
    }
View Full Code Here

     * @param aMethod the METHOD_DEF node
     * @return true if check passed, false otherwise
     */
    private boolean checkModifiers(DetailAST aMethod)
    {
        final DetailAST modifiers =
            aMethod.findFirstToken(TokenTypes.MODIFIERS);

        return modifiers.branchContains(TokenTypes.LITERAL_PUBLIC)
            && modifiers.branchContains(TokenTypes.LITERAL_STATIC);
    }
View Full Code Here

    }

    @Override
    protected final boolean mustCheckName(DetailAST aAST)
    {
        final DetailAST modifiersAST =
            aAST.findFirstToken(TokenTypes.MODIFIERS);
        final boolean isStatic = (modifiersAST != null)
            && modifiersAST.branchContains(TokenTypes.LITERAL_STATIC);
        final boolean isFinal = (modifiersAST != null)
            && modifiersAST.branchContains(TokenTypes.FINAL);

        return (isStatic
                && !isFinal
                && !ScopeUtils.inInterfaceOrAnnotationBlock(aAST));
    }
View Full Code Here

     * @param aMethod the METHOD_DEF node
     * @return true if check passed, false otherwise
     */
    private boolean checkType(DetailAST aMethod)
    {
        final DetailAST type =
            (DetailAST) aMethod.findFirstToken(TokenTypes.TYPE).getFirstChild();
        return type.getType() == TokenTypes.LITERAL_VOID;
    }
View Full Code Here

    }

    @Override
    public void visitToken(DetailAST aAST)
    {
        final DetailAST objBlock =
                aAST.findFirstToken(TokenTypes.OBJBLOCK);
        final DetailAST methodDef =
                objBlock.findFirstToken(TokenTypes.METHOD_DEF);
        final DetailAST variableDef =
                objBlock.findFirstToken(TokenTypes.VARIABLE_DEF);
        final boolean methodRequired =
                !mAllowMarkerInterfaces || (variableDef != null);

        if ((methodDef == null) && methodRequired) {
View Full Code Here

     * @param aMethod the METHOD_DEF node
     * @return true if check passed, false otherwise
     */
    private boolean checkParams(DetailAST aMethod)
    {
        final DetailAST params = aMethod.findFirstToken(TokenTypes.PARAMETERS);
        if (params.getChildCount() != 1) {
            return false;
        }
        final DetailAST paramType = ((DetailAST) params.getFirstChild())
            .findFirstToken(TokenTypes.TYPE);
        final DetailAST arrayDecl =
            paramType.findFirstToken(TokenTypes.ARRAY_DECLARATOR);
        if (arrayDecl == null) {
            return false;
        }

        final DetailAST arrayType = (DetailAST) arrayDecl.getFirstChild();

        if ((arrayType.getType() == TokenTypes.IDENT)
            || (arrayType.getType() == TokenTypes.DOT))
        {
            final FullIdent type = FullIdent.createFullIdent(arrayType);
            return ("String".equals(type.getText())
                    || "java.lang.String".equals(type.getText()));
        }
View Full Code Here

TOP

Related Classes of com.puppycrawl.tools.checkstyle.api.DetailAST

Copyright © 2018 www.massapicom. 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.