Search in sources :

Example 1 with AbstractApexNode

use of net.sourceforge.pmd.lang.apex.ast.AbstractApexNode in project pmd by pmd.

the class ApexCRUDViolationRule method recursivelyEvaluateCRUDMethodCalls.

private void recursivelyEvaluateCRUDMethodCalls(final AbstractApexNode<?> self, final Set<ASTMethodCallExpression> innerMethodCalls, final ASTBlockStatement blockStatement) {
    if (blockStatement != null) {
        int numberOfStatements = blockStatement.jjtGetNumChildren();
        for (int i = 0; i < numberOfStatements; i++) {
            Node n = blockStatement.jjtGetChild(i);
            if (n instanceof ASTIfElseBlockStatement) {
                List<ASTBlockStatement> innerBlocks = n.findDescendantsOfType(ASTBlockStatement.class);
                for (ASTBlockStatement innerBlock : innerBlocks) {
                    recursivelyEvaluateCRUDMethodCalls(self, innerMethodCalls, innerBlock);
                }
            }
            AbstractApexNode<?> match = n.getFirstDescendantOfType(self.getClass());
            if (Objects.equal(match, self)) {
                break;
            }
            ASTMethodCallExpression methodCall = n.getFirstDescendantOfType(ASTMethodCallExpression.class);
            if (methodCall != null) {
                mapCallToMethodDecl(self, innerMethodCalls, Arrays.asList(methodCall));
            }
        }
    }
}
Also used : ASTIfElseBlockStatement(net.sourceforge.pmd.lang.apex.ast.ASTIfElseBlockStatement) AbstractApexNode(net.sourceforge.pmd.lang.apex.ast.AbstractApexNode) Node(net.sourceforge.pmd.lang.ast.Node) ASTBlockStatement(net.sourceforge.pmd.lang.apex.ast.ASTBlockStatement) ASTMethodCallExpression(net.sourceforge.pmd.lang.apex.ast.ASTMethodCallExpression)

Aggregations

ASTBlockStatement (net.sourceforge.pmd.lang.apex.ast.ASTBlockStatement)1 ASTIfElseBlockStatement (net.sourceforge.pmd.lang.apex.ast.ASTIfElseBlockStatement)1 ASTMethodCallExpression (net.sourceforge.pmd.lang.apex.ast.ASTMethodCallExpression)1 AbstractApexNode (net.sourceforge.pmd.lang.apex.ast.AbstractApexNode)1 Node (net.sourceforge.pmd.lang.ast.Node)1