use of apex.jorje.data.Identifier in project pmd by pmd.
the class ApexCRUDViolationRule method innerAddParametrizedClassToMapping.
private void innerAddParametrizedClassToMapping(final ASTFieldDeclaration node, final ClassTypeRef innerClassRef) {
List<Identifier> ids = innerClassRef.getNames();
StringBuffer argType = new StringBuffer();
for (Identifier id : ids) {
argType.append(id.getValue()).append(".");
}
argType.deleteCharAt(argType.length() - 1);
addVariableToMapping(Helper.getFQVariableName(node), argType.toString());
}
use of apex.jorje.data.Identifier 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 apex.jorje.data.Identifier 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 apex.jorje.data.Identifier in project pmd by pmd.
the class ApexOpenRedirectRule method checkNewObjects.
/**
* Traverses all new declarations to find PageReferences
*
* @param node
* @param data
*/
private void checkNewObjects(ASTNewObjectExpression node, Object data) {
ASTMethod method = node.getFirstParentOfType(ASTMethod.class);
if (method != null && Helper.isTestMethodOrClass(method)) {
return;
}
ClassTypeRef classRef = (ClassTypeRef) node.getNode().getTypeRef();
Identifier identifier = classRef.getNames().get(0);
if (identifier.getValue().equalsIgnoreCase(PAGEREFERENCE)) {
getObjectValue(node, data);
}
}
use of apex.jorje.data.Identifier in project pmd by pmd.
the class Helper method getFQVariableName.
static String getFQVariableName(final ASTFieldDeclaration variable) {
FieldDeclaration n = variable.getNode();
String name = "";
try {
java.lang.reflect.Field f = n.getClass().getDeclaredField("name");
f.setAccessible(true);
Identifier nameField = (Identifier) f.get(n);
name = nameField.getValue();
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
throw new RuntimeException(e);
}
StringBuilder sb = new StringBuilder().append(n.getDefiningType().getApexName()).append(":").append(name);
return sb.toString();
}
Aggregations