Search in sources :

Example 11 with FullIdent

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

the class AbstractTypeAwareCheck method processTypeParams.

/**
     * Process type params (if any) for given class, enum or method.
     * @param ast class, enum or method to process.
     */
private void processTypeParams(DetailAST ast) {
    final DetailAST params = ast.findFirstToken(TokenTypes.TYPE_PARAMETERS);
    final Map<String, AbstractClassInfo> paramsMap = new HashMap<>();
    typeParams.push(paramsMap);
    if (params != null) {
        for (DetailAST child = params.getFirstChild(); child != null; child = child.getNextSibling()) {
            if (child.getType() == TokenTypes.TYPE_PARAMETER) {
                final String alias = child.findFirstToken(TokenTypes.IDENT).getText();
                final DetailAST bounds = child.findFirstToken(TokenTypes.TYPE_UPPER_BOUNDS);
                if (bounds != null) {
                    final FullIdent name = FullIdent.createFullIdentBelow(bounds);
                    final AbstractClassInfo classInfo = createClassInfo(new Token(name), currentClassName);
                    paramsMap.put(alias, classInfo);
                }
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST) FullIdent(com.puppycrawl.tools.checkstyle.api.FullIdent)

Example 12 with FullIdent

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

the class CheckUtils method createFullType.

/**
     * Creates {@code FullIdent} for given type node.
     * @param typeAST a type node.
     * @return {@code FullIdent} for given type.
     */
public static FullIdent createFullType(DetailAST typeAST) {
    final DetailAST arrayDeclaratorAST = typeAST.findFirstToken(TokenTypes.ARRAY_DECLARATOR);
    final FullIdent fullType;
    if (arrayDeclaratorAST == null) {
        fullType = createFullTypeNoArrays(typeAST);
    } else {
        fullType = createFullTypeNoArrays(arrayDeclaratorAST);
    }
    return fullType;
}
Also used : DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST) FullIdent(com.puppycrawl.tools.checkstyle.api.FullIdent)

Example 13 with FullIdent

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

the class PackageNameCheck method visitToken.

@Override
public void visitToken(DetailAST ast) {
    final DetailAST nameAST = ast.getLastChild().getPreviousSibling();
    final FullIdent full = FullIdent.createFullIdent(nameAST);
    if (!format.matcher(full.getText()).find()) {
        log(full.getLineNo(), full.getColumnNo(), MSG_KEY, full.getText(), format.pattern());
    }
}
Also used : DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST) FullIdent(com.puppycrawl.tools.checkstyle.api.FullIdent)

Example 14 with FullIdent

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

the class AvoidStarImportCheck method logsStarredImportViolation.

/**
     * Gets the full import identifier.  If the import is a starred import and
     * it's not excluded then a violation is logged.
     * @param startingDot the starting dot for the import statement
     */
private void logsStarredImportViolation(DetailAST startingDot) {
    final FullIdent name = FullIdent.createFullIdent(startingDot);
    final String importText = name.getText();
    if (importText.endsWith(STAR_IMPORT_SUFFIX) && !excludes.contains(importText)) {
        log(startingDot.getLineNo(), MSG_KEY, importText);
    }
}
Also used : FullIdent(com.puppycrawl.tools.checkstyle.api.FullIdent)

Example 15 with FullIdent

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

the class IllegalCatchCheck method visitToken.

@Override
public void visitToken(DetailAST detailAST) {
    final DetailAST parameterDef = detailAST.findFirstToken(TokenTypes.PARAMETER_DEF);
    final DetailAST excTypeParent = parameterDef.findFirstToken(TokenTypes.TYPE);
    final List<DetailAST> excTypes = getAllExceptionTypes(excTypeParent);
    for (DetailAST excType : excTypes) {
        final FullIdent ident = FullIdent.createFullIdent(excType);
        if (illegalClassNames.contains(ident.getText())) {
            log(detailAST, MSG_KEY, ident.getText());
        }
    }
}
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