Search in sources :

Example 1 with ASTReturnStatement

use of net.sourceforge.pmd.lang.ecmascript.ast.ASTReturnStatement in project pmd by pmd.

the class ConsistentReturnRule method visit.

@Override
public Object visit(ASTFunctionNode functionNode, Object data) {
    List<ASTReturnStatement> returnStatements = functionNode.findDescendantsOfType(ASTReturnStatement.class);
    Boolean hasResult = null;
    for (ASTReturnStatement returnStatement : returnStatements) {
        // Return for this function?
        if (functionNode == returnStatement.getFirstParentOfType(ASTFunctionNode.class)) {
            if (hasResult == null) {
                hasResult = Boolean.valueOf(returnStatement.hasResult());
            } else {
                // Return has different result from previous return?
                if (hasResult.booleanValue() != returnStatement.hasResult()) {
                    addViolation(data, functionNode);
                    break;
                }
            }
        }
    }
    return data;
}
Also used : ASTFunctionNode(net.sourceforge.pmd.lang.ecmascript.ast.ASTFunctionNode) ASTReturnStatement(net.sourceforge.pmd.lang.ecmascript.ast.ASTReturnStatement)

Aggregations

ASTFunctionNode (net.sourceforge.pmd.lang.ecmascript.ast.ASTFunctionNode)1 ASTReturnStatement (net.sourceforge.pmd.lang.ecmascript.ast.ASTReturnStatement)1