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());
}
}
}
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();
}
Aggregations