Package com.puppycrawl.tools.checkstyle.api

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


        if (aAST.getType() == TokenTypes.PACKAGE_DEF) {
            mPkgName = FullIdent.createFullIdent(
                    aAST.getLastChild().getPreviousSibling()).getText();
        }
        else if (aAST.getType() == TokenTypes.IMPORT) {
            final FullIdent imp = FullIdent.createFullIdentBelow(aAST);
            if (fromPackage(imp.getText(), "java.lang")) {
                log(aAST.getLineNo(), aAST.getColumnNo(), "import.lang",
                    imp.getText());
            }
            else if (fromPackage(imp.getText(), mPkgName)) {
                log(aAST.getLineNo(), aAST.getColumnNo(), "import.same",
                    imp.getText());
            }
            // Check for a duplicate import
            for (FullIdent full : mImports) {
                if (imp.getText().equals(full.getText())) {
                    log(aAST.getLineNo(), aAST.getColumnNo(),
                            "import.duplicate", full.getLineNo(),
                            imp.getText());
                }
            }

            mImports.add(imp);
        }
        else {
            // Check for a duplicate static import
            final FullIdent imp =
                FullIdent.createFullIdent(
                    aAST.getLastChild().getPreviousSibling());
            for (FullIdent full : mStaticImports) {
                if (imp.getText().equals(full.getText())) {
                    log(aAST.getLineNo(), aAST.getColumnNo(),
                        "import.duplicate", full.getLineNo(), imp.getText());
                }
            }

            mStaticImports.add(imp);
        }
View Full Code Here


    @Override
    public void visitToken(final DetailAST aAST)
    {
        if (aAST.getType() == TokenTypes.PACKAGE_DEF) {
            final DetailAST nameAST = aAST.getLastChild().getPreviousSibling();
            final FullIdent full = FullIdent.createFullIdent(nameAST);
            if (mRoot == null) {
                log(nameAST, "import.control.missing.file");
            }
            else {
                mInPkg = full.getText();
                mCurrentLeaf = mRoot.locateFinest(mInPkg);
                if (mCurrentLeaf == null) {
                    log(nameAST, "import.control.unknown.pkg");
                }
            }
        }
        else if (mCurrentLeaf != null) {
            final FullIdent imp;
            if (aAST.getType() == TokenTypes.IMPORT) {
                imp = FullIdent.createFullIdentBelow(aAST);
            }
            else {
                // know it is a static import
                imp = FullIdent.createFullIdent(aAST
                        .getFirstChild().getNextSibling());
            }
            final AccessResult access = mCurrentLeaf.checkAccess(imp.getText(),
                    mInPkg);
            if (!AccessResult.ALLOWED.equals(access)) {
                log(aAST, "import.control.disallowed", imp.getText());
            }
        }
    }
View Full Code Here

        // parameter type "Object"?
        final DetailAST paramNode =
            paramsNode.findFirstToken(TokenTypes.PARAMETER_DEF);
        final DetailAST typeNode = paramNode.findFirstToken(TokenTypes.TYPE);
        final FullIdent fullIdent = FullIdent.createFullIdentBelow(typeNode);
        final String name = fullIdent.getText();
        return ("Object".equals(name) || "java.lang.Object".equals(name));
    }
View Full Code Here

        final int lastPos = fname.lastIndexOf(File.separatorChar);
        final String dirname = fname.substring(0, lastPos);

        // Convert the found package name into the expected directory name.
        final DetailAST nameAST = aAST.getLastChild().getPreviousSibling();
        final FullIdent full = FullIdent.createFullIdent(nameAST);
        final String expected = full.getText().replace('.', File.separatorChar);

        // Finally see that the real directory ends with the expected directory
        if (!dirname.endsWith(expected)) {
            log(full.getLineNo(),
                full.getColumnNo(),
                "package.dir.mismatch",
                expected);
        }
    }
View Full Code Here

     * Perform processing for an import token
     * @param aAST the import token
     */
    private void processImport(DetailAST aAST)
    {
        final FullIdent name = FullIdent.createFullIdentBelow(aAST);
        if (name != null) {
            // Note: different from UnusedImportsCheck.processImport(),
            // '.*' imports are also added here
            mImports.add(name);
        }
View Full Code Here

     */
    private void processPackageDef(DetailAST aAST)
    {
        final DetailAST packageNameAST = aAST.getLastChild()
                .getPreviousSibling();
        final FullIdent packageIdent =
                FullIdent.createFullIdent(packageNameAST);
        mPkgName = packageIdent.getText();
    }
View Full Code Here

        {
            // aAST == "new Boolean[]"
            return;
        }

        final FullIdent typeIdent = FullIdent.createFullIdent(typeNameAST);
        final String typeName = typeIdent.getText();
        final int lineNo = aAST.getLineNo();
        final int colNo = aAST.getColumnNo();
        final String fqClassName = getIllegalInstantiation(typeName);
        if (fqClassName != null) {
            log(lineNo, colNo, "instantiation.avoid", fqClassName);
View Full Code Here

        if (!(shouldIgnoreMethod(aDetailAST.getParent().findFirstToken(
                                     TokenTypes.IDENT).getText())))
        {
            while (token != null) {
                if (token.getType() != TokenTypes.COMMA) {
                    final FullIdent ident = FullIdent.createFullIdent(token);
                    if (isIllegalClassName(ident.getText())) {
                        log(token, "illegal.throw", ident.getText());
                    }
                }
                token = token.getNextSibling();
            }
        }
View Full Code Here

    return new int[] { TokenTypes.IMPORT, TokenTypes.STATIC_IMPORT };
  }

  @Override
  public void visitToken(DetailAST aAST) {
    final FullIdent imp;
    if ( aAST.getType() == TokenTypes.IMPORT ) {
      imp = FullIdent.createFullIdentBelow( aAST );
    }
    else {
      // handle case of static imports of method names
      imp = FullIdent.createFullIdent( aAST.getFirstChild().getNextSibling() );
    }
    final String text = imp.getText();
    if ( isIllegalImport( text ) ) {
      final String message = buildError( text );
      log( aAST.getLineNo(), aAST.getColumnNo(), message, text );
    }
  }
View Full Code Here

        if (textWithoutDots == null) {
            // if there are TokenTypes.DOT nodes in subTree.
            final DetailAST parentDotAST = aAST.findFirstToken(TokenTypes.DOT);
            if (parentDotAST != null) {
                final FullIdent dottedPathIdent = FullIdent
                        .createFullIdentBelow(parentDotAST);
                final DetailAST nameAST = parentDotAST.getLastChild();
                result = dottedPathIdent.getText() + "." + nameAST.getText();
            }
        }
        else { // if subtree doesn`t contain dots.
            result = textWithoutDots.getText();
        }
View Full Code Here

TOP

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

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.