i'd like to know if i can use PMD to perform some basic data flow analysis actions. It's an assignment so it doesn't matter if it's trivial. I can't find any code examples online.
Is the DFA module working? Should i go the reverse engineering way to see what's going on?
Thanks lots
PMD's Data Flow Analysis module is operational. There are rules using it shipping with PMD, for instance DataflowAnomalyAnalysis.
However, it is true the PMD team plans to revamp that implementation at some point in the future.
DFA is only usable through Java rules (XPath rules can't be used). Writing a DFA rule consists of:
Writing a visitor in which you get the DFA node for the method / constructor you want to analyze:
public Object visit(ASTMethodDeclaration methodDeclaration, Object data) {
final DataFlowNode node = methodDeclaration.getDataFlowNode().getFlow().get(0);
final DAAPathFinder pathFinder = new DAAPathFinder(node, executable, getProperty(MAX_PATH_DESCRIPTOR));
pathFinder.run();
return data;
}
Writing a proper Executable
to enforce your rule.
public void execute(CurrentPath path) {
// your code here to analyze the current path
}
A working example can be found here