Search in sources :

Example 11 with ASTBinaryExpression

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

the class ApexXSSFromURLParamRule method processVariableAssignments.

private void processVariableAssignments(AbstractApexNode<?> node, Object data, final boolean reverseOrder) {
    ASTMethodCallExpression methodCallAssignment = node.getFirstChildOfType(ASTMethodCallExpression.class);
    if (methodCallAssignment != null) {
        String varType = null;
        if (node instanceof ASTVariableDeclaration) {
            varType = ((ASTVariableDeclaration) node).getNode().getLocalInfo().getType().getApexName();
        }
        if (varType == null || !"id".equalsIgnoreCase(varType)) {
            processInlineMethodCalls(methodCallAssignment, data, false);
        }
    }
    List<ASTVariableExpression> nodes = node.findChildrenOfType(ASTVariableExpression.class);
    switch(nodes.size()) {
        case 1:
            {
                // Look for: foo + bar
                final List<ASTBinaryExpression> ops = node.findChildrenOfType(ASTBinaryExpression.class);
                if (!ops.isEmpty()) {
                    for (ASTBinaryExpression o : ops) {
                        processBinaryExpression(o, data);
                    }
                }
            }
            break;
        case 2:
            {
                // Look for: foo = bar;
                final ASTVariableExpression right = reverseOrder ? nodes.get(0) : nodes.get(1);
                if (urlParameterStrings.contains(Helper.getFQVariableName(right))) {
                    addViolation(data, right);
                }
            }
            break;
        default:
            break;
    }
}
Also used : ASTVariableExpression(net.sourceforge.pmd.lang.apex.ast.ASTVariableExpression) ASTBinaryExpression(net.sourceforge.pmd.lang.apex.ast.ASTBinaryExpression) ASTVariableDeclaration(net.sourceforge.pmd.lang.apex.ast.ASTVariableDeclaration) List(java.util.List) ASTMethodCallExpression(net.sourceforge.pmd.lang.apex.ast.ASTMethodCallExpression)

Aggregations

ASTBinaryExpression (net.sourceforge.pmd.lang.apex.ast.ASTBinaryExpression)11 ASTVariableExpression (net.sourceforge.pmd.lang.apex.ast.ASTVariableExpression)9 ASTMethodCallExpression (net.sourceforge.pmd.lang.apex.ast.ASTMethodCallExpression)5 ASTLiteralExpression (net.sourceforge.pmd.lang.apex.ast.ASTLiteralExpression)2 ASTVariableDeclaration (net.sourceforge.pmd.lang.apex.ast.ASTVariableDeclaration)2 StandardFieldInfo (apex.jorje.semantic.symbol.member.variable.StandardFieldInfo)1 Field (java.lang.reflect.Field)1 HashSet (java.util.HashSet)1 List (java.util.List)1 ASTAssignmentExpression (net.sourceforge.pmd.lang.apex.ast.ASTAssignmentExpression)1 ASTField (net.sourceforge.pmd.lang.apex.ast.ASTField)1 ASTStandardCondition (net.sourceforge.pmd.lang.apex.ast.ASTStandardCondition)1