use of net.sourceforge.pmd.RuleContext in project pmd by pmd.
the class AbstractRule method addViolation.
/**
* @see RuleViolationFactory#addViolation(RuleContext, Rule, Node, String,
* Object[])
*/
public void addViolation(Object data, Node node, Object[] args) {
RuleContext ruleContext = (RuleContext) data;
ruleContext.getLanguageVersion().getLanguageVersionHandler().getRuleViolationFactory().addViolation(ruleContext, this, node, this.getMessage(), args);
}
use of net.sourceforge.pmd.RuleContext in project pmd by pmd.
the class XMLRendererTest method createRuleViolation.
private static RuleViolation createRuleViolation(String description) {
DummyNode node = new DummyNode(1);
node.testingOnlySetBeginLine(1);
node.testingOnlySetBeginColumn(1);
node.testingOnlySetEndLine(1);
node.testingOnlySetEndColumn(1);
RuleContext ctx = new RuleContext();
ctx.setSourceCodeFilename("n/a");
return new ParametricRuleViolation<Node>(new FooRule(), ctx, node, description);
}
use of net.sourceforge.pmd.RuleContext 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"));
}
use of net.sourceforge.pmd.RuleContext in project pmd by pmd.
the class StatisticalRuleTest method makeReport.
public Report makeReport(Rule rule) {
List<Node> list = new ArrayList<>();
Report report = new Report();
RuleContext ctx = new RuleContext();
ctx.setReport(report);
ctx.setSourceCodeFilename(testName);
ctx.setLanguageVersion(LanguageRegistry.getLanguage(DummyLanguageModule.NAME).getDefaultVersion());
rule.apply(list, ctx);
return report;
}
use of net.sourceforge.pmd.RuleContext in project pmd by pmd.
the class CodeClimateRendererTest method testXPathRule.
@Test
public void testXPathRule() throws Exception {
DummyNode node = createNode(1);
RuleContext ctx = new RuleContext();
ctx.setSourceCodeFilename(getSourceCodeFilename());
Report report = new Report();
XPathRule theRule = new XPathRule();
theRule.setProperty(XPathRule.XPATH_DESCRIPTOR, "//dummyNode");
// Setup as FooRule
theRule.setDescription("desc");
theRule.setName("Foo");
report.addRuleViolation(new ParametricRuleViolation<Node>(theRule, ctx, node, "blah"));
String rendered = ReportTest.render(getRenderer(), report);
// Output should be the exact same as for non xpath rules
assertEquals(filter(getExpected()), filter(rendered));
}
Aggregations