use of net.sourceforge.pmd.lang.apex.ast.ASTMethod in project pmd by pmd.
the class MethodWithSameNameAsEnclosingClassRule method visit.
@Override
public Object visit(ASTUserClass node, Object data) {
String className = node.getImage();
List<ASTMethod> methods = node.findDescendantsOfType(ASTMethod.class);
for (ASTMethod m : methods) {
String methodName = m.getImage();
if (!m.getNode().getMethodInfo().isConstructor() && methodName.equalsIgnoreCase(className)) {
addViolation(data, m);
}
}
return super.visit(node, data);
}
use of net.sourceforge.pmd.lang.apex.ast.ASTMethod in project pmd by pmd.
the class ApexMetricsComputer method findOperations.
@Override
protected List<ASTMethod> findOperations(ASTUserClassOrInterface<?> node) {
List<ASTMethod> candidates = node.findChildrenOfType(ASTMethod.class);
List<ASTMethod> result = new ArrayList<>(candidates);
for (ASTMethod method : candidates) {
if (method.getImage().matches("(<clinit>|<init>|clone)")) {
result.remove(method);
}
}
return result;
}
use of net.sourceforge.pmd.lang.apex.ast.ASTMethod in project pmd by pmd.
the class ApexCRUDViolationRule method visit.
@Override
public Object visit(ASTUserClass node, Object data) {
if (Helper.isTestMethodOrClass(node) || Helper.isSystemLevelClass(node)) {
// stops all the rules
return data;
}
className = node.getImage();
for (ASTMethod n : node.findDescendantsOfType(ASTMethod.class)) {
StringBuilder sb = new StringBuilder().append(n.getNode().getDefiningType().getApexName()).append(":").append(n.getNode().getMethodInfo().getCanonicalName()).append(":").append(n.getNode().getMethodInfo().getParameterTypes().size());
classMethods.put(sb.toString(), n);
}
return super.visit(node, data);
}
use of net.sourceforge.pmd.lang.apex.ast.ASTMethod 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.ASTMethod in project pmd by pmd.
the class ApexMultifileVisitorTest method testOperationsAreThere.
@Test
public void testOperationsAreThere() throws IOException {
ApexNode<Compilation> acu = parseAndVisitForString(IOUtils.toString(ApexMultifileVisitorTest.class.getResourceAsStream("MetadataDeployController.cls")));
final ApexSignatureMatcher toplevel = ApexProjectMirror.INSTANCE;
final ApexOperationSigMask opMask = new ApexOperationSigMask();
// We could parse qnames from string but probably simpler to do that
acu.jjtAccept(new ApexParserVisitorAdapter() {
@Override
public Object visit(ASTMethod node, Object data) {
if (!node.getImage().matches("(<clinit>|<init>|clone)")) {
assertTrue(toplevel.hasMatchingSig(node.getQualifiedName(), opMask));
}
return data;
}
}, null);
}
Aggregations