Search in sources :

Example 1 with ASTReferenceExpression

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

the class ApexCRUDViolationRule method extractObjectTypeFromESAPI.

private void extractObjectTypeFromESAPI(final ASTMethodCallExpression node, final String dmlOperation) {
    final ASTVariableExpression var = node.getFirstChildOfType(ASTVariableExpression.class);
    if (var != null) {
        final ASTReferenceExpression reference = var.getFirstChildOfType(ASTReferenceExpression.class);
        if (reference != null) {
            List<Identifier> identifiers = reference.getNode().getNames();
            if (identifiers.size() == 1) {
                StringBuilder sb = new StringBuilder().append(node.getNode().getDefiningType().getApexName()).append(":").append(identifiers.get(0).getValue());
                checkedTypeToDMLOperationViaESAPI.put(sb.toString(), dmlOperation);
            }
        }
    }
}
Also used : ASTReferenceExpression(net.sourceforge.pmd.lang.apex.ast.ASTReferenceExpression) ASTVariableExpression(net.sourceforge.pmd.lang.apex.ast.ASTVariableExpression) Identifier(apex.jorje.data.Identifier)

Example 2 with ASTReferenceExpression

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

the class ApexCRUDViolationRule method collectCRUDMethodLevelChecks.

private void collectCRUDMethodLevelChecks(final ASTMethodCallExpression node) {
    final String method = node.getNode().getMethodName();
    final ASTReferenceExpression ref = node.getFirstChildOfType(ASTReferenceExpression.class);
    if (ref == null) {
        return;
    }
    List<Identifier> a = ref.getNode().getNames();
    if (!a.isEmpty()) {
        extractObjectAndFields(a, method, node.getNode().getDefiningType().getApexName());
    } else {
        // see if ESAPI
        if (Helper.isMethodCallChain(node, ESAPI_ISAUTHORIZED_TO_VIEW)) {
            extractObjectTypeFromESAPI(node, IS_ACCESSIBLE);
        }
        if (Helper.isMethodCallChain(node, ESAPI_ISAUTHORIZED_TO_CREATE)) {
            extractObjectTypeFromESAPI(node, IS_CREATEABLE);
        }
        if (Helper.isMethodCallChain(node, ESAPI_ISAUTHORIZED_TO_UPDATE)) {
            extractObjectTypeFromESAPI(node, IS_UPDATEABLE);
        }
        if (Helper.isMethodCallChain(node, ESAPI_ISAUTHORIZED_TO_DELETE)) {
            extractObjectTypeFromESAPI(node, IS_DELETABLE);
        }
        // see if getDescribe()
        final ASTMethodCallExpression nestedMethodCall = ref.getFirstChildOfType(ASTMethodCallExpression.class);
        if (nestedMethodCall != null) {
            if (isLastMethodName(nestedMethodCall, S_OBJECT_TYPE, GET_DESCRIBE)) {
                String resolvedType = getType(nestedMethodCall);
                if (!typeToDMLOperationMapping.get(resolvedType).contains(method)) {
                    typeToDMLOperationMapping.put(resolvedType, method);
                }
            }
        }
    }
}
Also used : ASTReferenceExpression(net.sourceforge.pmd.lang.apex.ast.ASTReferenceExpression) Identifier(apex.jorje.data.Identifier) ASTMethodCallExpression(net.sourceforge.pmd.lang.apex.ast.ASTMethodCallExpression)

Example 3 with ASTReferenceExpression

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

the class Helper method getFQVariableName.

static String getFQVariableName(final ASTVariableExpression variable) {
    final ASTReferenceExpression ref = variable.getFirstChildOfType(ASTReferenceExpression.class);
    String objectName = "";
    if (ref != null) {
        if (ref.getNode().getNames().size() == 1) {
            objectName = ref.getNode().getNames().get(0).getValue() + ".";
        }
    }
    VariableExpression n = variable.getNode();
    StringBuilder sb = new StringBuilder().append(n.getDefiningType().getApexName()).append(":").append(objectName).append(n.getIdentifier().getValue());
    return sb.toString();
}
Also used : ASTReferenceExpression(net.sourceforge.pmd.lang.apex.ast.ASTReferenceExpression) VariableExpression(apex.jorje.semantic.ast.expression.VariableExpression) ASTVariableExpression(net.sourceforge.pmd.lang.apex.ast.ASTVariableExpression)

Aggregations

ASTReferenceExpression (net.sourceforge.pmd.lang.apex.ast.ASTReferenceExpression)3 Identifier (apex.jorje.data.Identifier)2 ASTVariableExpression (net.sourceforge.pmd.lang.apex.ast.ASTVariableExpression)2 VariableExpression (apex.jorje.semantic.ast.expression.VariableExpression)1 ASTMethodCallExpression (net.sourceforge.pmd.lang.apex.ast.ASTMethodCallExpression)1