Search in sources :

Example 1 with DFAGraphMethod

use of net.sourceforge.pmd.lang.dfa.DFAGraphMethod in project pmd by pmd.

the class DFAPanel method resetTo.

public void resetTo(List<DFAGraphMethod> newNodes, LineGetter lines) {
    dfaCanvas.setCode(lines);
    nodes.clear();
    for (DFAGraphMethod md : newNodes) {
        nodes.addElement(new ElementWrapper(md));
    }
    nodeList.setSelectedIndex(0);
    dfaCanvas.setMethod(newNodes.get(0));
    repaint();
}
Also used : DFAGraphMethod(net.sourceforge.pmd.lang.dfa.DFAGraphMethod)

Example 2 with DFAGraphMethod

use of net.sourceforge.pmd.lang.dfa.DFAGraphMethod in project Gargoyle by callakrsos.

the class DFAPanelFx method resetTo.

public void resetTo(List<DFAGraphMethod> newNodes, LineGetter lines) {
    dfaCanvas.setCode(lines);
    nodes.clear();
    for (DFAGraphMethod md : newNodes) {
        nodes.addElement(new ElementWrapper(md));
    }
    nodeList.setSelectedIndex(0);
    dfaCanvas.setMethod(newNodes.get(0));
    dfaCanvas.repaint();
}
Also used : DFAGraphMethod(net.sourceforge.pmd.lang.dfa.DFAGraphMethod)

Example 3 with DFAGraphMethod

use of net.sourceforge.pmd.lang.dfa.DFAGraphMethod 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;
}
Also used : RuleSet(net.sourceforge.pmd.RuleSet) ASTMethodDeclaration(net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration) RuleContext(net.sourceforge.pmd.RuleContext) JavaDFAGraphRule(net.sourceforge.pmd.lang.java.dfa.JavaDFAGraphRule) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) SourceCodeProcessor(net.sourceforge.pmd.SourceCodeProcessor) DFAGraphMethod(net.sourceforge.pmd.lang.dfa.DFAGraphMethod) JavaDFAGraphRule(net.sourceforge.pmd.lang.java.dfa.JavaDFAGraphRule) DFAGraphRule(net.sourceforge.pmd.lang.dfa.DFAGraphRule) ByteArrayInputStream(java.io.ByteArrayInputStream) RuleSets(net.sourceforge.pmd.RuleSets) PMDException(net.sourceforge.pmd.PMDException) PMDConfiguration(net.sourceforge.pmd.PMDConfiguration)

Aggregations

DFAGraphMethod (net.sourceforge.pmd.lang.dfa.DFAGraphMethod)3 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 PMDConfiguration (net.sourceforge.pmd.PMDConfiguration)1 PMDException (net.sourceforge.pmd.PMDException)1 RuleContext (net.sourceforge.pmd.RuleContext)1 RuleSet (net.sourceforge.pmd.RuleSet)1 RuleSets (net.sourceforge.pmd.RuleSets)1 SourceCodeProcessor (net.sourceforge.pmd.SourceCodeProcessor)1 DFAGraphRule (net.sourceforge.pmd.lang.dfa.DFAGraphRule)1 ASTMethodDeclaration (net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration)1 JavaDFAGraphRule (net.sourceforge.pmd.lang.java.dfa.JavaDFAGraphRule)1