use of com.puppycrawl.tools.checkstyle.api.DetailAST in project checkstyle by checkstyle.
the class VisibilityModifierCheck method findMatchingAnnotation.
/**
* Checks whether the AST is annotated with
* an annotation containing the passed in regular
* expression and return the AST representing that
* annotation.
*
* <p>
* This method will not look for imports or package
* statements to detect the passed in annotation.
* </p>
*
* <p>
* To check if an AST contains a passed in annotation
* taking into account fully-qualified names
* (ex: java.lang.Override, Override)
* this method will need to be called twice. Once for each
* name given.
* </p>
*
* @param variableDef {@link TokenTypes#VARIABLE_DEF variable def node}.
* @return the AST representing the first such annotation or null if
* no such annotation was found
*/
private DetailAST findMatchingAnnotation(DetailAST variableDef) {
DetailAST matchingAnnotation = null;
final DetailAST holder = AnnotationUtility.getAnnotationHolder(variableDef);
for (DetailAST child = holder.getFirstChild(); child != null; child = child.getNextSibling()) {
if (child.getType() == TokenTypes.ANNOTATION) {
final DetailAST ast = child.getFirstChild();
final String name = FullIdent.createFullIdent(ast.getNextSibling()).getText();
if (ignoreAnnotationCanonicalNames.contains(name) || ignoreAnnotationShortNames.contains(name)) {
matchingAnnotation = child;
break;
}
}
}
return matchingAnnotation;
}
use of com.puppycrawl.tools.checkstyle.api.DetailAST in project checkstyle by checkstyle.
the class VisibilityModifierCheck 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) && currentNode.getParent().getColumnNo() == subTreeRootAst.getColumnNo()) {
break;
}
currentNode = currentNode.getParent();
}
}
return toVisitAst;
}
use of com.puppycrawl.tools.checkstyle.api.DetailAST in project checkstyle by checkstyle.
the class VisibilityModifierCheck method getModifiers.
/**
* Returns the set of modifier Strings for a VARIABLE_DEF or CLASS_DEF AST.
* @param defAST AST for a variable or class definition.
* @return the set of modifier Strings for defAST.
*/
private static Set<String> getModifiers(DetailAST defAST) {
final AST modifiersAST = defAST.findFirstToken(TokenTypes.MODIFIERS);
final Set<String> modifiersSet = new HashSet<>();
if (modifiersAST != null) {
AST modifier = modifiersAST.getFirstChild();
while (modifier != null) {
modifiersSet.add(modifier.getText());
modifier = modifier.getNextSibling();
}
}
return modifiersSet;
}
use of com.puppycrawl.tools.checkstyle.api.DetailAST 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());
}
}
use of com.puppycrawl.tools.checkstyle.api.DetailAST in project checkstyle by checkstyle.
the class PackageDefHandler method checkIndentation.
@Override
public void checkIndentation() {
final int columnNo = expandedTabsColumnNo(getMainAst());
if (!getIndent().isAcceptable(columnNo) && isOnStartOfLine(getMainAst())) {
logError(getMainAst(), "", columnNo);
}
final DetailAST semi = getMainAst().findFirstToken(TokenTypes.SEMI);
checkWrappingIndentation(getMainAst(), semi);
}
Aggregations