use of com.puppycrawl.tools.checkstyle.api.DetailAST 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;
}
use of com.puppycrawl.tools.checkstyle.api.DetailAST in project checkstyle by checkstyle.
the class JavadocMethodCheck method searchMatchingTypeParameter.
/**
* Returns true if required type found in type parameters.
* @param typeParams
* list of type parameters
* @param requiredTypeName
* name of required type
* @return true if required type found in type parameters.
*/
private static boolean searchMatchingTypeParameter(List<DetailAST> typeParams, String requiredTypeName) {
// Loop looking for matching type param
final Iterator<DetailAST> typeParamsIt = typeParams.iterator();
boolean found = false;
while (typeParamsIt.hasNext()) {
final DetailAST typeParam = typeParamsIt.next();
if (typeParam.findFirstToken(TokenTypes.IDENT).getText().equals(requiredTypeName)) {
found = true;
typeParamsIt.remove();
break;
}
}
return found;
}
use of com.puppycrawl.tools.checkstyle.api.DetailAST in project checkstyle by checkstyle.
the class JavadocTypeCheck method shouldCheck.
/**
* Whether we should check this node.
* @param ast a given node.
* @return whether we should check a given node.
*/
private boolean shouldCheck(final DetailAST ast) {
final DetailAST mods = ast.findFirstToken(TokenTypes.MODIFIERS);
final Scope declaredScope = ScopeUtils.getScopeFromMods(mods);
final Scope customScope;
if (ScopeUtils.isInInterfaceOrAnnotationBlock(ast)) {
customScope = Scope.PUBLIC;
} else {
customScope = declaredScope;
}
final Scope surroundingScope = ScopeUtils.getSurroundingScope(ast);
return customScope.isIn(scope) && (surroundingScope == null || surroundingScope.isIn(scope)) && (excludeScope == null || !customScope.isIn(excludeScope) || surroundingScope != null && !surroundingScope.isIn(excludeScope));
}
use of com.puppycrawl.tools.checkstyle.api.DetailAST in project checkstyle by checkstyle.
the class JavaNCSSCheck method isVariableDefCountable.
/**
* Checks if a variable definition is countable.
*
* @param ast the AST
* @return true if the variable definition is countable, false otherwise
*/
private static boolean isVariableDefCountable(DetailAST ast) {
boolean countable = false;
//count variable definitions only if they are direct child to a slist or
// object block
final int parentType = ast.getParent().getType();
if (parentType == TokenTypes.SLIST || parentType == TokenTypes.OBJBLOCK) {
final DetailAST prevSibling = ast.getPreviousSibling();
//is countable if no previous sibling is found or
//the sibling is no COMMA.
//This is done because multiple assignment on one line are counted
// as 1
countable = prevSibling == null || prevSibling.getType() != TokenTypes.COMMA;
}
return countable;
}
use of com.puppycrawl.tools.checkstyle.api.DetailAST in project checkstyle by checkstyle.
the class ModifierOrderCheck method isAnnotationOnType.
/**
* Checks whether annotation on type takes place.
* @param modifier modifier token.
* @return true if annotation on type takes place.
*/
private static boolean isAnnotationOnType(DetailAST modifier) {
boolean annotationOnType = false;
final DetailAST modifiers = modifier.getParent();
final DetailAST definition = modifiers.getParent();
final int definitionType = definition.getType();
if (definitionType == TokenTypes.VARIABLE_DEF || definitionType == TokenTypes.PARAMETER_DEF || definitionType == TokenTypes.CTOR_DEF) {
annotationOnType = true;
} else if (definitionType == TokenTypes.METHOD_DEF) {
final DetailAST typeToken = definition.findFirstToken(TokenTypes.TYPE);
final int methodReturnType = typeToken.getLastChild().getType();
if (methodReturnType != TokenTypes.LITERAL_VOID) {
annotationOnType = true;
}
}
return annotationOnType;
}
Aggregations