use of com.puppycrawl.tools.checkstyle.api.DetailAST in project checkstyle by checkstyle.
the class SynchronizedHandler method checkSynchronizedExpr.
/**
* Check indentation of expression we synchronized on.
*/
private void checkSynchronizedExpr() {
final DetailAST syncAst = getMainAst().findFirstToken(TokenTypes.LPAREN).getNextSibling();
final IndentLevel expected = new IndentLevel(getIndent(), getBasicOffset());
checkExpressionSubtree(syncAst, expected, false, false);
}
use of com.puppycrawl.tools.checkstyle.api.DetailAST in project checkstyle by checkstyle.
the class WhileHandler method checkCondExpr.
/**
* Check the indentation of the conditional expression.
*/
private void checkCondExpr() {
final DetailAST condAst = getMainAst().findFirstToken(TokenTypes.EXPR);
final IndentLevel expected = new IndentLevel(getIndent(), getBasicOffset());
checkExpressionSubtree(condAst, expected, false, false);
}
use of com.puppycrawl.tools.checkstyle.api.DetailAST in project checkstyle by checkstyle.
the class JavadocMethodCheck method hasAllowedAnnotations.
/**
* Some javadoc.
* @param methodDef Some javadoc.
* @return Some javadoc.
*/
private boolean hasAllowedAnnotations(DetailAST methodDef) {
final DetailAST modifiersNode = methodDef.findFirstToken(TokenTypes.MODIFIERS);
DetailAST annotationNode = modifiersNode.findFirstToken(TokenTypes.ANNOTATION);
while (annotationNode != null && annotationNode.getType() == TokenTypes.ANNOTATION) {
DetailAST identNode = annotationNode.findFirstToken(TokenTypes.IDENT);
if (identNode == null) {
identNode = annotationNode.findFirstToken(TokenTypes.DOT).findFirstToken(TokenTypes.IDENT);
}
if (allowedAnnotations.contains(identNode.getText())) {
return true;
}
annotationNode = annotationNode.getNextSibling();
}
return false;
}
use of com.puppycrawl.tools.checkstyle.api.DetailAST in project checkstyle by checkstyle.
the class JavadocMethodCheck method calculateScope.
/**
* Returns the scope for the method/constructor at the specified AST. If
* the method is in an interface or annotation block, the scope is assumed
* to be public.
*
* @param ast the token of the method/constructor
* @return the scope of the method/constructor
*/
private static Scope calculateScope(final DetailAST ast) {
final DetailAST mods = ast.findFirstToken(TokenTypes.MODIFIERS);
final Scope declaredScope = ScopeUtils.getScopeFromMods(mods);
if (ScopeUtils.isInInterfaceOrAnnotationBlock(ast)) {
return Scope.PUBLIC;
} else {
return declaredScope;
}
}
use of com.puppycrawl.tools.checkstyle.api.DetailAST in project checkstyle by checkstyle.
the class JavadocMethodCheck method checkParamTags.
/**
* Checks a set of tags for matching parameters.
*
* @param tags the tags to check
* @param parent the node which takes the parameters
* @param reportExpectedTags whether we should report if do not find
* expected tag
*/
private void checkParamTags(final List<JavadocTag> tags, final DetailAST parent, boolean reportExpectedTags) {
final List<DetailAST> params = getParameters(parent);
final List<DetailAST> typeParams = CheckUtils.getTypeParameters(parent);
// Loop over the tags, checking to see they exist in the params.
final ListIterator<JavadocTag> tagIt = tags.listIterator();
while (tagIt.hasNext()) {
final JavadocTag tag = tagIt.next();
if (!tag.isParamTag()) {
continue;
}
tagIt.remove();
final String arg1 = tag.getFirstArg();
boolean found = removeMatchingParam(params, arg1);
if (CommonUtils.startsWithChar(arg1, '<') && CommonUtils.endsWithChar(arg1, '>')) {
found = searchMatchingTypeParameter(typeParams, arg1.substring(1, arg1.length() - 1));
}
// Handle extra JavadocTag
if (!found) {
log(tag.getLineNo(), tag.getColumnNo(), MSG_UNUSED_TAG, "@param", arg1);
}
}
// the user has chosen to suppress these problems
if (!allowMissingParamTags && reportExpectedTags) {
for (DetailAST param : params) {
log(param, MSG_EXPECTED_TAG, JavadocTagInfo.PARAM.getText(), param.getText());
}
for (DetailAST typeParam : typeParams) {
log(typeParam, MSG_EXPECTED_TAG, JavadocTagInfo.PARAM.getText(), "<" + typeParam.findFirstToken(TokenTypes.IDENT).getText() + ">");
}
}
}
Aggregations