use of net.sourceforge.pmd.lang.dfa.DFAGraphRule in project pmd-eclipse-plugin by pmd.
the class AbstractStructureInspectorPage method getPMDMethods.
/**
* Gets a List of all PMD-Methods.
*
* @return an List of ASTMethodDeclarations
*/
private List<ASTMethodDeclaration> getPMDMethods() {
List<ASTMethodDeclaration> methodList = new ArrayList<ASTMethodDeclaration>();
// PMD needs this Resource as a String
try {
DFAGraphRule dfaGraphRule = new JavaDFAGraphRule();
RuleSet rs = RuleSetUtil.newSingle(dfaGraphRule);
RuleContext ctx = new RuleContext();
ctx.setSourceCodeFilename("[scratchpad]");
// StringReader reader = new StringReader(getDocument().get());
// run PMD using the DFAGraphRule and the Text of the Resource
// new PMDEngine().processFile(reader, rs, ctx);
byte[] bytes = getDocument().get().getBytes();
InputStream input = new ByteArrayInputStream(bytes);
RuleSets rSets = new RuleSets(rs);
new SourceCodeProcessor(new PMDConfiguration()).processSourceCode(input, rSets, ctx);
// the Rule then can give us the Methods
for (DFAGraphMethod m : dfaGraphRule.getMethods()) {
if (m instanceof ASTMethodDeclaration) {
methodList.add((ASTMethodDeclaration) m);
}
}
Collections.sort(methodList, ASTUtil.METHOD_COMPARATOR);
} catch (PMDException pmde) {
logError(StringKeys.ERROR_PMD_EXCEPTION + toString(), pmde);
}
return methodList;
}
Aggregations