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