use of com.puppycrawl.tools.checkstyle.api.DetailAST in project checkstyle by checkstyle.
the class IllegalInstantiationCheck method processClassDef.
/**
* Collects classes defined in the source file. Required
* to avoid false alarms for local vs. java.lang classes.
*
* @param ast the class def token.
*/
private void processClassDef(DetailAST ast) {
final DetailAST identToken = ast.findFirstToken(TokenTypes.IDENT);
final String className = identToken.getText();
classNames.add(className);
}
use of com.puppycrawl.tools.checkstyle.api.DetailAST in project checkstyle by checkstyle.
the class IllegalTypeCheck method isVerifiable.
/**
* Checks if current method's return type or variable's type is verifiable
* according to <b>memberModifiers</b> option.
* @param methodOrVariableDef METHOD_DEF or VARIABLE_DEF ast node.
* @return true if member is verifiable according to <b>memberModifiers</b> option.
*/
private boolean isVerifiable(DetailAST methodOrVariableDef) {
boolean result = true;
if (memberModifiers != null) {
final DetailAST modifiersAst = methodOrVariableDef.findFirstToken(TokenTypes.MODIFIERS);
result = isContainVerifiableType(modifiersAst);
}
return result;
}
use of com.puppycrawl.tools.checkstyle.api.DetailAST in project checkstyle by checkstyle.
the class IllegalTypeCheck method getNextSubTreeNode.
/**
* Gets the next node of a syntactical tree (child of a current node or
* sibling of a current node, or sibling of a parent of a current node).
* @param currentNodeAst Current node in considering
* @param subTreeRootAst SubTree root
* @return Current node after bypassing, if current node reached the root of a subtree
* method returns null
*/
private static DetailAST getNextSubTreeNode(DetailAST currentNodeAst, DetailAST subTreeRootAst) {
DetailAST currentNode = currentNodeAst;
DetailAST toVisitAst = currentNode.getFirstChild();
while (toVisitAst == null) {
toVisitAst = currentNode.getNextSibling();
if (toVisitAst == null) {
if (currentNode.getParent().equals(subTreeRootAst)) {
break;
}
currentNode = currentNode.getParent();
}
}
return toVisitAst;
}
use of com.puppycrawl.tools.checkstyle.api.DetailAST in project checkstyle by checkstyle.
the class IllegalTypeCheck method checkClassName.
/**
* Checks type of given method, parameter or variable.
* @param ast node to check.
*/
private void checkClassName(DetailAST ast) {
final DetailAST type = ast.findFirstToken(TokenTypes.TYPE);
final FullIdent ident = CheckUtils.createFullType(type);
if (isMatchingClassName(ident.getText())) {
log(ident.getLineNo(), ident.getColumnNo(), MSG_KEY, ident.getText());
}
}
use of com.puppycrawl.tools.checkstyle.api.DetailAST in project checkstyle by checkstyle.
the class IllegalTypeCheck method isStarImport.
/**
* Checks if current import is star import. E.g.:
* <p>
* {@code
* import java.util.*;
* }
* </p>
* @param importAst {@link TokenTypes#IMPORT Import}
* @return true if it is star import
*/
private static boolean isStarImport(DetailAST importAst) {
boolean result = false;
DetailAST toVisit = importAst;
while (toVisit != null) {
toVisit = getNextSubTreeNode(toVisit, importAst);
if (toVisit != null && toVisit.getType() == TokenTypes.STAR) {
result = true;
break;
}
}
return result;
}
Aggregations