Search in sources :

Example 1 with FullIdent

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

the class AvoidStaticImportCheck method visitToken.

@Override
public void visitToken(final DetailAST ast) {
    final DetailAST startingDot = ast.getFirstChild().getNextSibling();
    final FullIdent name = FullIdent.createFullIdent(startingDot);
    if (!isExempt(name.getText())) {
        log(startingDot.getLineNo(), MSG_KEY, name.getText());
    }
}
Also used : DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST) FullIdent(com.puppycrawl.tools.checkstyle.api.FullIdent)

Example 2 with FullIdent

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

the class ImportOrderCheck method visitToken.

// -@cs[CyclomaticComplexity] SWITCH was transformed into IF-ELSE.
@Override
public void visitToken(DetailAST ast) {
    final FullIdent ident;
    final boolean isStatic;
    if (ast.getType() == TokenTypes.IMPORT) {
        ident = FullIdent.createFullIdentBelow(ast);
        isStatic = false;
    } else {
        ident = FullIdent.createFullIdent(ast.getFirstChild().getNextSibling());
        isStatic = true;
    }
    final boolean isStaticAndNotLastImport = isStatic && !lastImportStatic;
    final boolean isLastImportAndNonStatic = lastImportStatic && !isStatic;
    // https://github.com/checkstyle/checkstyle/issues/1387
    if (option == ImportOrderOption.TOP) {
        if (isLastImportAndNonStatic) {
            lastGroup = Integer.MIN_VALUE;
            lastImport = "";
        }
        doVisitToken(ident, isStatic, isStaticAndNotLastImport);
    } else if (option == ImportOrderOption.BOTTOM) {
        if (isStaticAndNotLastImport) {
            lastGroup = Integer.MIN_VALUE;
            lastImport = "";
        }
        doVisitToken(ident, isStatic, isLastImportAndNonStatic);
    } else if (option == ImportOrderOption.ABOVE) {
        // previous non-static but current is static
        doVisitToken(ident, isStatic, isStaticAndNotLastImport);
    } else if (option == ImportOrderOption.UNDER) {
        doVisitToken(ident, isStatic, isLastImportAndNonStatic);
    } else if (option == ImportOrderOption.INFLOW) {
        // "previous" argument is useless here
        doVisitToken(ident, isStatic, true);
    } else {
        throw new IllegalStateException("Unexpected option for static imports: " + option);
    }
    lastImportLine = ast.findFirstToken(TokenTypes.SEMI).getLineNo();
    lastImportStatic = isStatic;
    beforeFirstImport = false;
}
Also used : FullIdent(com.puppycrawl.tools.checkstyle.api.FullIdent)

Example 3 with FullIdent

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

the class JavadocMethodCheck method getThrows.

/**
     * Computes the exception nodes for a method.
     *
     * @param ast the method node.
     * @return the list of exception nodes for ast.
     */
private List<ExceptionInfo> getThrows(DetailAST ast) {
    final List<ExceptionInfo> returnValue = new ArrayList<>();
    final DetailAST throwsAST = ast.findFirstToken(TokenTypes.LITERAL_THROWS);
    if (throwsAST != null) {
        DetailAST child = throwsAST.getFirstChild();
        while (child != null) {
            if (child.getType() == TokenTypes.IDENT || child.getType() == TokenTypes.DOT) {
                final FullIdent ident = FullIdent.createFullIdent(child);
                final ExceptionInfo exceptionInfo = new ExceptionInfo(createClassInfo(new Token(ident), getCurrentClassName()));
                returnValue.add(exceptionInfo);
            }
            child = child.getNextSibling();
        }
    }
    return returnValue;
}
Also used : DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST) ArrayList(java.util.ArrayList) FullIdent(com.puppycrawl.tools.checkstyle.api.FullIdent)

Example 4 with FullIdent

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

the class AbstractClassCouplingCheck method visitPackageDef.

/**
     * Stores package of current class we check.
     * @param pkg package definition.
     */
private void visitPackageDef(DetailAST pkg) {
    final FullIdent ident = FullIdent.createFullIdent(pkg.getLastChild().getPreviousSibling());
    packageName = ident.getText();
}
Also used : FullIdent(com.puppycrawl.tools.checkstyle.api.FullIdent)

Example 5 with FullIdent

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

the class PackageDeclarationCheck method visitToken.

@Override
public void visitToken(DetailAST ast) {
    defined = true;
    if (matchDirectoryStructure) {
        final DetailAST packageNameAst = ast.getLastChild().getPreviousSibling();
        final FullIdent fullIdent = FullIdent.createFullIdent(packageNameAst);
        final String packageName = fullIdent.getText().replace('.', File.separatorChar);
        final String directoryName = getDirectoryName();
        if (!directoryName.endsWith(packageName)) {
            log(fullIdent.getLineNo(), MSG_KEY_MISMATCH, packageName);
        }
    }
}
Also used : DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST) FullIdent(com.puppycrawl.tools.checkstyle.api.FullIdent)

Aggregations

FullIdent (com.puppycrawl.tools.checkstyle.api.FullIdent)18 DetailAST (com.puppycrawl.tools.checkstyle.api.DetailAST)13 AST (antlr.collections.AST)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1