Search in sources :

Example 31 with RuleContext

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) {
    RuleContext ruleContext = (RuleContext) data;
    ruleContext.getLanguageVersion().getLanguageVersionHandler().getRuleViolationFactory().addViolation(ruleContext, this, node, this.getMessage(), null);
}
Also used : RuleContext(net.sourceforge.pmd.RuleContext)

Example 32 with RuleContext

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, String arg) {
    RuleContext ruleContext = (RuleContext) data;
    ruleContext.getLanguageVersion().getLanguageVersionHandler().getRuleViolationFactory().addViolation(ruleContext, this, node, this.getMessage(), new Object[] { arg });
}
Also used : RuleContext(net.sourceforge.pmd.RuleContext)

Example 33 with RuleContext

use of net.sourceforge.pmd.RuleContext in project pmd by pmd.

the class AbstractRule method addViolationWithMessage.

/**
 * @see RuleViolationFactory#addViolation(RuleContext, Rule, Node, String,
 * Object[])
 */
public void addViolationWithMessage(Object data, Node node, String message) {
    RuleContext ruleContext = (RuleContext) data;
    ruleContext.getLanguageVersion().getLanguageVersionHandler().getRuleViolationFactory().addViolation(ruleContext, this, node, message, null);
}
Also used : RuleContext(net.sourceforge.pmd.RuleContext)

Example 34 with RuleContext

use of net.sourceforge.pmd.RuleContext in project pmd by pmd.

the class AbstractRendererTst method testRuleWithProperties.

@Test
public void testRuleWithProperties() throws Exception {
    DummyNode node = createNode(1);
    RuleContext ctx = new RuleContext();
    ctx.setSourceCodeFilename(getSourceCodeFilename());
    Report report = new Report();
    RuleWithProperties theRule = new RuleWithProperties();
    theRule.setProperty(RuleWithProperties.STRING_PROPERTY_DESCRIPTOR, "the string value\nsecond line with \"quotes\"");
    report.addRuleViolation(new ParametricRuleViolation<Node>(theRule, ctx, node, "blah"));
    String rendered = ReportTest.render(getRenderer(), report);
    assertEquals(filter(getExpectedWithProperties()), filter(rendered));
}
Also used : RuleContext(net.sourceforge.pmd.RuleContext) Report(net.sourceforge.pmd.Report) DummyNode(net.sourceforge.pmd.lang.ast.DummyNode) Node(net.sourceforge.pmd.lang.ast.Node) DummyNode(net.sourceforge.pmd.lang.ast.DummyNode) RuleWithProperties(net.sourceforge.pmd.RuleWithProperties) Test(org.junit.Test) ReportTest(net.sourceforge.pmd.ReportTest)

Example 35 with RuleContext

use of net.sourceforge.pmd.RuleContext in project pmd by pmd.

the class MultiThreadProcessorTest method setUpForTest.

public void setUpForTest(final String ruleset) {
    PMDConfiguration configuration = new PMDConfiguration();
    configuration.setRuleSets(ruleset);
    configuration.setThreads(2);
    files = new ArrayList<>();
    files.add(new StringDataSource("file1-violation.dummy", "ABC"));
    files.add(new StringDataSource("file2-foo.dummy", "DEF"));
    reportListener = new SimpleReportListener();
    ctx = new RuleContext();
    ctx.getReport().addListener(reportListener);
    processor = new MultiThreadProcessor(configuration);
    ruleSetFactory = new RuleSetFactory();
}
Also used : RuleSetFactory(net.sourceforge.pmd.RuleSetFactory) RuleContext(net.sourceforge.pmd.RuleContext) PMDConfiguration(net.sourceforge.pmd.PMDConfiguration)

Aggregations

RuleContext (net.sourceforge.pmd.RuleContext)51 Test (org.junit.Test)19 RuleSets (net.sourceforge.pmd.RuleSets)17 RuleSetFactory (net.sourceforge.pmd.RuleSetFactory)15 Report (net.sourceforge.pmd.Report)14 Node (net.sourceforge.pmd.lang.ast.Node)13 RuleSet (net.sourceforge.pmd.RuleSet)11 StringReader (java.io.StringReader)9 RuleViolation (net.sourceforge.pmd.RuleViolation)9 IOException (java.io.IOException)8 PMDConfiguration (net.sourceforge.pmd.PMDConfiguration)8 PMDException (net.sourceforge.pmd.PMDException)8 ASTCompilationUnit (net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit)8 ArrayList (java.util.ArrayList)7 SourceCodeProcessor (net.sourceforge.pmd.SourceCodeProcessor)7 RuleSetNotFoundException (net.sourceforge.pmd.RuleSetNotFoundException)6 LanguageVersion (net.sourceforge.pmd.lang.LanguageVersion)6 DummyNode (net.sourceforge.pmd.lang.ast.DummyNode)5 FooRule (net.sourceforge.pmd.FooRule)4 Parser (net.sourceforge.pmd.lang.Parser)4