use of net.sourceforge.pmd.lang.apex.ast.ASTBlockStatement in project pmd by pmd.
the class ApexCRUDViolationRule method recursivelyEvaluateCRUDMethodCalls.
private void recursivelyEvaluateCRUDMethodCalls(final AbstractApexNode<?> self, final Set<ASTMethodCallExpression> innerMethodCalls, final ASTBlockStatement blockStatement) {
if (blockStatement != null) {
int numberOfStatements = blockStatement.jjtGetNumChildren();
for (int i = 0; i < numberOfStatements; i++) {
Node n = blockStatement.jjtGetChild(i);
if (n instanceof ASTIfElseBlockStatement) {
List<ASTBlockStatement> innerBlocks = n.findDescendantsOfType(ASTBlockStatement.class);
for (ASTBlockStatement innerBlock : innerBlocks) {
recursivelyEvaluateCRUDMethodCalls(self, innerMethodCalls, innerBlock);
}
}
AbstractApexNode<?> match = n.getFirstDescendantOfType(self.getClass());
if (Objects.equal(match, self)) {
break;
}
ASTMethodCallExpression methodCall = n.getFirstDescendantOfType(ASTMethodCallExpression.class);
if (methodCall != null) {
mapCallToMethodDecl(self, innerMethodCalls, Arrays.asList(methodCall));
}
}
}
}
use of net.sourceforge.pmd.lang.apex.ast.ASTBlockStatement in project pmd by pmd.
the class ApexCRUDViolationRule method getPreviousMethodCalls.
private Set<ASTMethodCallExpression> getPreviousMethodCalls(final AbstractApexNode<?> self) {
final Set<ASTMethodCallExpression> innerMethodCalls = new HashSet<>();
final ASTMethod outerMethod = self.getFirstParentOfType(ASTMethod.class);
if (outerMethod != null) {
final ASTBlockStatement blockStatement = outerMethod.getFirstChildOfType(ASTBlockStatement.class);
recursivelyEvaluateCRUDMethodCalls(self, innerMethodCalls, blockStatement);
final List<ASTMethod> constructorMethods = findConstructorlMethods();
for (ASTMethod method : constructorMethods) {
innerMethodCalls.addAll(method.findDescendantsOfType(ASTMethodCallExpression.class));
}
// some methods might be within this class
mapCallToMethodDecl(self, innerMethodCalls, new ArrayList<ASTMethodCallExpression>(innerMethodCalls));
}
return innerMethodCalls;
}
use of net.sourceforge.pmd.lang.apex.ast.ASTBlockStatement 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;
}
Aggregations