Search in sources :

Example 1 with ASTNewKeyValueObjectExpression

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

the class ApexCRUDViolationRule method checkForCRUD.

private void checkForCRUD(final AbstractApexNode<?> node, final Object data, final String crudMethod) {
    final Set<ASTMethodCallExpression> prevCalls = getPreviousMethodCalls(node);
    for (ASTMethodCallExpression prevCall : prevCalls) {
        collectCRUDMethodLevelChecks(prevCall);
    }
    final ASTMethod wrappingMethod = node.getFirstParentOfType(ASTMethod.class);
    final ASTUserClass wrappingClass = node.getFirstParentOfType(ASTUserClass.class);
    if (wrappingClass != null && Helper.isTestMethodOrClass(wrappingClass) || wrappingMethod != null && Helper.isTestMethodOrClass(wrappingMethod)) {
        return;
    }
    final ASTNewKeyValueObjectExpression newObj = node.getFirstChildOfType(ASTNewKeyValueObjectExpression.class);
    if (newObj != null) {
        final String type = Helper.getFQVariableName(newObj);
        validateCRUDCheckPresent(node, data, crudMethod, type);
    }
    final ASTVariableExpression variable = node.getFirstChildOfType(ASTVariableExpression.class);
    if (variable != null) {
        final String type = varToTypeMapping.get(Helper.getFQVariableName(variable));
        if (type != null) {
            StringBuilder typeCheck = new StringBuilder().append(node.getNode().getDefiningType().getApexName()).append(":").append(type);
            validateCRUDCheckPresent(node, data, crudMethod, typeCheck.toString());
        }
    }
}
Also used : ASTUserClass(net.sourceforge.pmd.lang.apex.ast.ASTUserClass) ASTNewKeyValueObjectExpression(net.sourceforge.pmd.lang.apex.ast.ASTNewKeyValueObjectExpression) ASTVariableExpression(net.sourceforge.pmd.lang.apex.ast.ASTVariableExpression) ASTMethod(net.sourceforge.pmd.lang.apex.ast.ASTMethod) ASTMethodCallExpression(net.sourceforge.pmd.lang.apex.ast.ASTMethodCallExpression)

Example 2 with ASTNewKeyValueObjectExpression

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

the class Helper method getFQVariableName.

static String getFQVariableName(final ASTNewKeyValueObjectExpression variable) {
    NewKeyValueObjectExpression n = variable.getNode();
    TypeRef typeRef = n.getTypeRef();
    String objType = typeRef.getNames().get(0).getValue();
    StringBuilder sb = new StringBuilder().append(n.getDefiningType().getApexName()).append(":").append(objType);
    return sb.toString();
}
Also used : TypeRef(apex.jorje.data.ast.TypeRef) NewKeyValueObjectExpression(apex.jorje.semantic.ast.expression.NewKeyValueObjectExpression) ASTNewKeyValueObjectExpression(net.sourceforge.pmd.lang.apex.ast.ASTNewKeyValueObjectExpression)

Aggregations

ASTNewKeyValueObjectExpression (net.sourceforge.pmd.lang.apex.ast.ASTNewKeyValueObjectExpression)2 TypeRef (apex.jorje.data.ast.TypeRef)1 NewKeyValueObjectExpression (apex.jorje.semantic.ast.expression.NewKeyValueObjectExpression)1 ASTMethod (net.sourceforge.pmd.lang.apex.ast.ASTMethod)1 ASTMethodCallExpression (net.sourceforge.pmd.lang.apex.ast.ASTMethodCallExpression)1 ASTUserClass (net.sourceforge.pmd.lang.apex.ast.ASTUserClass)1 ASTVariableExpression (net.sourceforge.pmd.lang.apex.ast.ASTVariableExpression)1