@Override public Object visit(ASTMethodDeclaration node, Object data) { if (node.isAbstract()) { return data; } List<ASTReturnStatement> returnNodes = node.findDescendantsOfType(ASTReturnStatement.class); if (returnNodes.size() > 1) { for (Iterator<ASTReturnStatement> i = returnNodes.iterator(); i.hasNext();) { Node problem = i.next(); // skip the last one, it's OK if (!i.hasNext()) { continue; } addViolation(data, problem); } } return data; } }
private String getReturnVariableName(ASTMethodDeclaration node) { List<ASTReturnStatement> rsl = node.findDescendantsOfType(ASTReturnStatement.class); ASTReturnStatement rs = rsl.get(0); List<ASTPrimaryExpression> pel = rs.findDescendantsOfType(ASTPrimaryExpression.class); ASTPrimaryExpression ape = pel.get(0); Node lastChild = ape.jjtGetChild(0); String returnVariableName = null; if (lastChild instanceof ASTPrimaryPrefix) { returnVariableName = getNameFromPrimaryPrefix((ASTPrimaryPrefix) lastChild); } /* * if(lastChild instanceof ASTPrimarySuffix){ returnVariableName = * getNameFromPrimarySuffix((ASTPrimarySuffix) lastChild); } */ return returnVariableName; }
/** * That's a new method. We are going to check each method call inside the * method. * * @return <code>null</code>. */ @Override public Object visit(ASTMethodDeclaration node, Object data) { List<ASTPrimaryExpression> primaryExpressions = node.findDescendantsOfType(ASTPrimaryExpression.class); for (ASTPrimaryExpression expression : primaryExpressions) { List<MethodCall> calls = MethodCall.createMethodCalls(expression); addViolations(calls, (RuleContext) data); } return null; }
@Override public Object visit(ASTMethodDeclaration node, Object data) { final ASTFormalParameters params = node.getFirstDescendantOfType(ASTFormalParameters.class); ASTFormalParameter[] arrs = getArrays(params); checkAll(data, arrs, node.findDescendantsOfType(ASTBlockStatement.class)); return data; }
@Override public Object visit(ASTMethodDeclaration node, Object data) { List<ASTTryStatement> catches = node.findDescendantsOfType(ASTTryStatement.class); List<Node> found = new ArrayList<>(); if (catches.isEmpty()) {
List<ASTReturnStatement> rsl = node.findDescendantsOfType(ASTReturnStatement.class); if (rsl.isEmpty()) { return super.visit(node, data); List<ASTBlockStatement> astBlockStatements = node.findDescendantsOfType(ASTBlockStatement.class); returnVariableName = getReturnVariableName(node); if (!astBlockStatements.isEmpty()) {
if (classOrInterface != null && //Don't analyze enums, which cannot subclass clone() (node.isFinal() || classOrInterface.isFinal())) { if (node.findDescendantsOfType(ASTBlock.class).size() == 1) { final List<ASTBlockStatement> blocks = node.findDescendantsOfType(ASTBlockStatement.class); if (blocks.size() == 1) { final ASTBlockStatement block = blocks.get(0);
List<ASTReturnStatement> rsl = node.findDescendantsOfType(ASTReturnStatement.class); if (rsl.size() != 1) { return super.visit(node, data); return super.visit(node, data); List<ASTIfStatement> isl = node.findDescendantsOfType(ASTIfStatement.class); if (isl.size() == 2) { ASTIfStatement is = isl.get(0);
List<ASTIfStatement> ifStatements = node.findDescendantsOfType(ASTIfStatement.class); for (ASTIfStatement ifStatement : ifStatements) { if (ifStatement.getFirstParentOfType(ASTSynchronizedStatement.class) == null) {
return data; List<ASTReturnStatement> returns = method.findDescendantsOfType(ASTReturnStatement.class); ASTTypeDeclaration td = method.getFirstParentOfType(ASTTypeDeclaration.class); for (ASTReturnStatement ret : returns) {
private boolean checkLocalVariableUsage(ASTMethodDeclaration node, String returnVariableName) { List<ASTLocalVariableDeclaration> locals = node.findDescendantsOfType(ASTLocalVariableDeclaration.class); ASTVariableInitializer initializer = null; for (ASTLocalVariableDeclaration l : locals) { List<ASTName> names = node.findDescendantsOfType(ASTName.class); for (ASTName n : names) { if (!n.hasImageEqualTo(returnVariableName)) {
@Override public Object visit(ASTMethodDeclaration node, Object data) { if (node.isAbstract()) { return data; } List<ASTReturnStatement> returnNodes = node.findDescendantsOfType(ASTReturnStatement.class); if (returnNodes.size() > 1) { for (Iterator<ASTReturnStatement> i = returnNodes.iterator(); i.hasNext();) { Node problem = i.next(); // skip the last one, it's OK if (!i.hasNext()) { continue; } addViolation(data, problem); } } return data; } }
/** * That's a new method. We are going to check each method call inside the * method. * * @return <code>null</code>. */ @Override public Object visit(ASTMethodDeclaration node, Object data) { List<ASTPrimaryExpression> primaryExpressions = node.findDescendantsOfType(ASTPrimaryExpression.class); for (ASTPrimaryExpression expression : primaryExpressions) { List<MethodCall> calls = MethodCall.createMethodCalls(expression); addViolations(calls, (RuleContext) data); } return null; }
private String getReturnVariableName(ASTMethodDeclaration node) { List<ASTReturnStatement> rsl = node.findDescendantsOfType(ASTReturnStatement.class); ASTReturnStatement rs = rsl.get(0); List<ASTPrimaryExpression> pel = rs.findDescendantsOfType(ASTPrimaryExpression.class); ASTPrimaryExpression ape = pel.get(0); Node lastChild = ape.jjtGetChild(0); String returnVariableName = null; if (lastChild instanceof ASTPrimaryPrefix) { returnVariableName = getNameFromPrimaryPrefix((ASTPrimaryPrefix) lastChild); } /* * if(lastChild instanceof ASTPrimarySuffix){ returnVariableName = * getNameFromPrimarySuffix((ASTPrimarySuffix) lastChild); } */ return returnVariableName; }
@Override public Object visit(ASTMethodDeclaration node, Object data) { final ASTFormalParameters params = node.getFirstDescendantOfType(ASTFormalParameters.class); ASTFormalParameter[] arrs = getArrays(params); checkAll(data, arrs, node.findDescendantsOfType(ASTBlockStatement.class)); return data; }
private void checkMathRandom(List<ASTMethodDeclaration> methodDeclarations, Object data) { for (ASTMethodDeclaration methodDeclaration : methodDeclarations) { List<ASTPrimaryPrefix> primaryPrefixes = methodDeclaration.findDescendantsOfType(ASTPrimaryPrefix.class); if (primaryPrefixes == null || primaryPrefixes.isEmpty()) { continue; } for (ASTPrimaryPrefix primaryPrefix : primaryPrefixes) { if (primaryPrefix.getType() != Math.class) { continue; } ASTName name = primaryPrefix.getFirstChildOfType(ASTName.class); if (name == null || name.getImage() == null || !name.getImage().endsWith(MATH_RANDOM_METHOD)) { continue; } addViolationWithMessage(data, primaryPrefix, MESSAGE_KEY_PREFIX + ".violation.msg.math.random"); } } }
@Override public Object visit(ASTMethodDeclaration node, Object data) { List<ASTTryStatement> catches = node.findDescendantsOfType(ASTTryStatement.class); List<Node> found = new ArrayList<>(); if (catches.isEmpty()) {
if (classOrInterface != null && //Don't analyze enums, which cannot subclass clone() (node.isFinal() || classOrInterface.isFinal())) { if (node.findDescendantsOfType(ASTBlock.class).size() == 1) { final List<ASTBlockStatement> blocks = node.findDescendantsOfType(ASTBlockStatement.class); if (blocks.size() == 1) { final ASTBlockStatement block = blocks.get(0);
List<ASTIfStatement> ifStatements = node.findDescendantsOfType(ASTIfStatement.class); for (ASTIfStatement ifStatement : ifStatements) { if (ifStatement.getFirstParentOfType(ASTSynchronizedStatement.class) == null) {
return data; List<ASTReturnStatement> returns = method.findDescendantsOfType(ASTReturnStatement.class); ASTTypeDeclaration td = method.getFirstParentOfType(ASTTypeDeclaration.class); for (ASTReturnStatement ret : returns) {