Search in sources :

Example 6 with ParametricRuleViolation

use of net.sourceforge.pmd.lang.rule.ParametricRuleViolation in project pmd by pmd.

the class XSLTRendererTest method testDefaultStylesheet.

@Test
public void testDefaultStylesheet() throws Exception {
    XSLTRenderer renderer = new XSLTRenderer();
    Report report = new Report();
    DummyNode node = new DummyNode(1);
    node.testingOnlySetBeginLine(1);
    node.testingOnlySetBeginColumn(1);
    RuleViolation rv = new ParametricRuleViolation<Node>(new FooRule(), new RuleContext(), node, "violation message");
    report.addRuleViolation(rv);
    String result = ReportTest.render(renderer, report);
    Assert.assertTrue(result.contains("violation message"));
}
Also used : ParametricRuleViolation(net.sourceforge.pmd.lang.rule.ParametricRuleViolation) FooRule(net.sourceforge.pmd.FooRule) RuleContext(net.sourceforge.pmd.RuleContext) Report(net.sourceforge.pmd.Report) DummyNode(net.sourceforge.pmd.lang.ast.DummyNode) RuleViolation(net.sourceforge.pmd.RuleViolation) ParametricRuleViolation(net.sourceforge.pmd.lang.rule.ParametricRuleViolation) ReportTest(net.sourceforge.pmd.ReportTest) Test(org.junit.Test)

Example 7 with ParametricRuleViolation

use of net.sourceforge.pmd.lang.rule.ParametricRuleViolation in project pmd by pmd.

the class SummaryHTMLRendererTest method createEmptyReportWithSuppression.

private Report createEmptyReportWithSuppression() {
    Report rep = new Report();
    Map<Integer, String> suppressions = new HashMap<>();
    suppressions.put(1, "test");
    rep.suppress(suppressions);
    RuleContext ctx = new RuleContext();
    ParametricRuleViolation<Node> violation = new ParametricRuleViolation<>(new FooRule(), ctx, null, "suppress test");
    violation.setLines(1, 1);
    rep.addRuleViolation(violation);
    return rep;
}
Also used : ParametricRuleViolation(net.sourceforge.pmd.lang.rule.ParametricRuleViolation) FooRule(net.sourceforge.pmd.FooRule) RuleContext(net.sourceforge.pmd.RuleContext) Report(net.sourceforge.pmd.Report) HashMap(java.util.HashMap) Node(net.sourceforge.pmd.lang.ast.Node)

Example 8 with ParametricRuleViolation

use of net.sourceforge.pmd.lang.rule.ParametricRuleViolation in project pmd by pmd.

the class AbstractRendererTst method newRuleViolation.

private RuleViolation newRuleViolation(int endColumn) {
    DummyNode node = createNode(endColumn);
    RuleContext ctx = new RuleContext();
    ctx.setSourceCodeFilename(getSourceCodeFilename());
    return new ParametricRuleViolation<Node>(new FooRule(), ctx, node, "blah");
}
Also used : ParametricRuleViolation(net.sourceforge.pmd.lang.rule.ParametricRuleViolation) FooRule(net.sourceforge.pmd.FooRule) RuleContext(net.sourceforge.pmd.RuleContext) DummyNode(net.sourceforge.pmd.lang.ast.DummyNode)

Example 9 with ParametricRuleViolation

use of net.sourceforge.pmd.lang.rule.ParametricRuleViolation in project pmd by pmd.

the class ReportTest method testTreeIterator.

@Test
public void testTreeIterator() {
    Report r = new Report();
    RuleContext ctx = new RuleContext();
    Rule rule = new MockRule("name", "desc", "msg", "rulesetname");
    Node node1 = getNode(5, 5, true);
    r.addRuleViolation(new ParametricRuleViolation<>(rule, ctx, node1, rule.getMessage()));
    Node node2 = getNode(5, 6, true);
    r.addRuleViolation(new ParametricRuleViolation<>(rule, ctx, node2, rule.getMessage()));
    Iterator<RuleViolation> violations = r.iterator();
    int violationCount = 0;
    while (violations.hasNext()) {
        violations.next();
        violationCount++;
    }
    assertEquals(2, violationCount);
    Iterator<RuleViolation> treeIterator = r.treeIterator();
    int treeCount = 0;
    while (treeIterator.hasNext()) {
        treeIterator.next();
        treeCount++;
    }
    assertEquals(2, treeCount);
}
Also used : Node(net.sourceforge.pmd.lang.ast.Node) DummyNode(net.sourceforge.pmd.lang.ast.DummyNode) MockRule(net.sourceforge.pmd.lang.rule.MockRule) ParametricRuleViolation(net.sourceforge.pmd.lang.rule.ParametricRuleViolation) MockRule(net.sourceforge.pmd.lang.rule.MockRule) Test(org.junit.Test)

Example 10 with ParametricRuleViolation

use of net.sourceforge.pmd.lang.rule.ParametricRuleViolation in project pmd by pmd.

the class RuleViolationComparatorTest method createJavaRuleViolation.

private RuleViolation createJavaRuleViolation(Rule rule, String fileName, int beginLine, String description, int beginColumn, int endLine, int endColumn) {
    RuleContext ruleContext = new RuleContext();
    ruleContext.setSourceCodeFilename(fileName);
    DummyNode simpleNode = new DummyNode(1);
    simpleNode.testingOnlySetBeginLine(beginLine);
    simpleNode.testingOnlySetBeginColumn(beginColumn);
    simpleNode.testingOnlySetEndLine(endLine);
    simpleNode.testingOnlySetEndColumn(endColumn);
    RuleViolation ruleViolation = new ParametricRuleViolation<Node>(rule, ruleContext, simpleNode, description);
    return ruleViolation;
}
Also used : ParametricRuleViolation(net.sourceforge.pmd.lang.rule.ParametricRuleViolation) DummyNode(net.sourceforge.pmd.lang.ast.DummyNode) ParametricRuleViolation(net.sourceforge.pmd.lang.rule.ParametricRuleViolation)

Aggregations

ParametricRuleViolation (net.sourceforge.pmd.lang.rule.ParametricRuleViolation)14 DummyNode (net.sourceforge.pmd.lang.ast.DummyNode)13 Test (org.junit.Test)10 MockRule (net.sourceforge.pmd.lang.rule.MockRule)6 FooRule (net.sourceforge.pmd.FooRule)4 RuleContext (net.sourceforge.pmd.RuleContext)4 HashMap (java.util.HashMap)2 Report (net.sourceforge.pmd.Report)2 Node (net.sourceforge.pmd.lang.ast.Node)2 ReportTest (net.sourceforge.pmd.ReportTest)1 RuleViolation (net.sourceforge.pmd.RuleViolation)1 Ignore (org.junit.Ignore)1