use of net.sourceforge.pmd.lang.apex.ast.ASTMethodCallExpression in project pmd by pmd.
the class ApexXSSFromURLParamRule method processVariableAssignments.
private void processVariableAssignments(AbstractApexNode<?> node, Object data, final boolean reverseOrder) {
ASTMethodCallExpression methodCallAssignment = node.getFirstChildOfType(ASTMethodCallExpression.class);
if (methodCallAssignment != null) {
String varType = null;
if (node instanceof ASTVariableDeclaration) {
varType = ((ASTVariableDeclaration) node).getNode().getLocalInfo().getType().getApexName();
}
if (varType == null || !"id".equalsIgnoreCase(varType)) {
processInlineMethodCalls(methodCallAssignment, data, false);
}
}
List<ASTVariableExpression> nodes = node.findChildrenOfType(ASTVariableExpression.class);
switch(nodes.size()) {
case 1:
{
// Look for: foo + bar
final List<ASTBinaryExpression> ops = node.findChildrenOfType(ASTBinaryExpression.class);
if (!ops.isEmpty()) {
for (ASTBinaryExpression o : ops) {
processBinaryExpression(o, data);
}
}
}
break;
case 2:
{
// Look for: foo = bar;
final ASTVariableExpression right = reverseOrder ? nodes.get(0) : nodes.get(1);
if (urlParameterStrings.contains(Helper.getFQVariableName(right))) {
addViolation(data, right);
}
}
break;
default:
break;
}
}
use of net.sourceforge.pmd.lang.apex.ast.ASTMethodCallExpression in project pmd by pmd.
the class ApexUnitTestClassShouldHaveAssertsRule method checkForAssertStatements.
private Object checkForAssertStatements(ApexNode<?> node, Object data) {
final List<ASTBlockStatement> blockStatements = node.findDescendantsOfType(ASTBlockStatement.class);
final List<ASTStatement> statements = new ArrayList<>();
final List<ASTMethodCallExpression> methodCalls = new ArrayList<>();
for (ASTBlockStatement blockStatement : blockStatements) {
statements.addAll(blockStatement.findDescendantsOfType(ASTStatement.class));
methodCalls.addAll(blockStatement.findDescendantsOfType(ASTMethodCallExpression.class));
}
boolean isAssertFound = false;
for (final ASTMethodCallExpression methodCallExpression : methodCalls) {
if (ASSERT_METHODS.contains(methodCallExpression.getFullMethodName().toLowerCase(Locale.ROOT))) {
isAssertFound = true;
break;
}
}
if (!isAssertFound) {
addViolation(data, node);
}
return data;
}
use of net.sourceforge.pmd.lang.apex.ast.ASTMethodCallExpression in project pmd by pmd.
the class ApexBadCryptoRule method visit.
@Override
public Object visit(ASTUserClass node, Object data) {
if (Helper.isTestMethodOrClass(node)) {
return data;
}
List<ASTFieldDeclaration> fieldDecl = node.findDescendantsOfType(ASTFieldDeclaration.class);
for (ASTFieldDeclaration var : fieldDecl) {
findSafeVariables(var);
}
List<ASTVariableDeclaration> variableDecl = node.findDescendantsOfType(ASTVariableDeclaration.class);
for (ASTVariableDeclaration var : variableDecl) {
findSafeVariables(var);
}
List<ASTMethodCallExpression> methodCalls = node.findDescendantsOfType(ASTMethodCallExpression.class);
for (ASTMethodCallExpression methodCall : methodCalls) {
if (Helper.isMethodName(methodCall, CRYPTO, ENCRYPT) || Helper.isMethodName(methodCall, CRYPTO, DECRYPT) || Helper.isMethodName(methodCall, CRYPTO, ENCRYPT_WITH_MANAGED_IV) || Helper.isMethodName(methodCall, CRYPTO, DECRYPT_WITH_MANAGED_IV)) {
validateStaticIVorKey(methodCall, data);
}
}
potentiallyStaticBlob.clear();
return data;
}
Aggregations