use of com.puppycrawl.tools.checkstyle.api.DetailAST in project checkstyle by checkstyle.
the class AbstractSuperCheck method isSuperCallInOverridingMethod.
/**
* Determines whether a super call in overriding method.
*
* @param ast The AST node of a 'dot operator' in 'super' call.
* @return true if super call in overriding method.
*/
private boolean isSuperCallInOverridingMethod(DetailAST ast) {
boolean inOverridingMethod = false;
DetailAST dotAst = ast;
while (dotAst.getType() != TokenTypes.CTOR_DEF && dotAst.getType() != TokenTypes.INSTANCE_INIT) {
if (dotAst.getType() == TokenTypes.METHOD_DEF) {
inOverridingMethod = isOverridingMethod(dotAst);
break;
}
dotAst = dotAst.getParent();
}
return inOverridingMethod;
}
use of com.puppycrawl.tools.checkstyle.api.DetailAST in project checkstyle by checkstyle.
the class CovariantEqualsCheck method visitToken.
@Override
public void visitToken(DetailAST ast) {
equalsMethods.clear();
// examine method definitions for equals methods
final DetailAST objBlock = ast.findFirstToken(TokenTypes.OBJBLOCK);
if (objBlock != null) {
DetailAST child = objBlock.getFirstChild();
boolean hasEqualsObject = false;
while (child != null) {
if (child.getType() == TokenTypes.METHOD_DEF && CheckUtils.isEqualsMethod(child)) {
if (isFirstParameterObject(child)) {
hasEqualsObject = true;
} else {
equalsMethods.add(child);
}
}
child = child.getNextSibling();
}
// report equals method definitions
if (!hasEqualsObject) {
for (DetailAST equalsAST : equalsMethods) {
final DetailAST nameNode = equalsAST.findFirstToken(TokenTypes.IDENT);
log(nameNode.getLineNo(), nameNode.getColumnNo(), MSG_KEY);
}
}
}
}
use of com.puppycrawl.tools.checkstyle.api.DetailAST in project checkstyle by checkstyle.
the class CovariantEqualsCheck method isFirstParameterObject.
/**
* Tests whether a method's first parameter is an Object.
* @param methodDefAst the method definition AST to test.
* Precondition: ast is a TokenTypes.METHOD_DEF node.
* @return true if ast has first parameter of type Object.
*/
private static boolean isFirstParameterObject(DetailAST methodDefAst) {
final DetailAST paramsNode = methodDefAst.findFirstToken(TokenTypes.PARAMETERS);
// parameter type "Object"?
final DetailAST paramNode = paramsNode.findFirstToken(TokenTypes.PARAMETER_DEF);
final DetailAST typeNode = paramNode.findFirstToken(TokenTypes.TYPE);
final FullIdent fullIdent = FullIdent.createFullIdentBelow(typeNode);
final String name = fullIdent.getText();
return "Object".equals(name) || "java.lang.Object".equals(name);
}
use of com.puppycrawl.tools.checkstyle.api.DetailAST in project checkstyle by checkstyle.
the class DeclarationOrderCheck method isForwardReference.
/**
* Checks whether an identifier references a field which has been already defined in class.
* @param fieldDef a field definition.
* @return true if an identifier references a field which has been already defined in class.
*/
private boolean isForwardReference(DetailAST fieldDef) {
final DetailAST exprStartIdent = fieldDef.findFirstToken(TokenTypes.IDENT);
final Set<DetailAST> exprIdents = getAllTokensOfType(exprStartIdent, TokenTypes.IDENT);
boolean forwardReference = false;
for (DetailAST ident : exprIdents) {
if (classFieldNames.contains(ident.getText())) {
forwardReference = true;
break;
}
}
return forwardReference;
}
use of com.puppycrawl.tools.checkstyle.api.DetailAST in project checkstyle by checkstyle.
the class FallThroughCheck method checkIf.
/**
* Checks if a given IF terminated by return, throw or,
* if allowed break, continue.
* @param ast IF to check
* @param useBreak should we consider break as terminator.
* @param useContinue should we consider continue as terminator.
* @return true if IF is terminated.
*/
private boolean checkIf(final DetailAST ast, boolean useBreak, boolean useContinue) {
final DetailAST thenStmt = ast.findFirstToken(TokenTypes.RPAREN).getNextSibling();
final DetailAST elseStmt = thenStmt.getNextSibling();
boolean isTerminated = isTerminated(thenStmt, useBreak, useContinue);
if (isTerminated && elseStmt != null) {
isTerminated = isTerminated(elseStmt.getFirstChild(), useBreak, useContinue);
} else if (elseStmt == null) {
isTerminated = false;
}
return isTerminated;
}
Aggregations