Search in sources :

Example 1 with DummyNode

use of net.sourceforge.pmd.lang.ast.DummyNode in project pmd by pmd.

the class ReportTest method getNode.

private static Node getNode(int line, int column, boolean nextLine) {
    DummyNode s = (DummyNode) getNode(line, column);
    if (nextLine) {
        s.testingOnlySetBeginLine(line + 1);
        s.testingOnlySetBeginColumn(column + 4);
    }
    return s;
}
Also used : DummyNode(net.sourceforge.pmd.lang.ast.DummyNode)

Example 2 with DummyNode

use of net.sourceforge.pmd.lang.ast.DummyNode in project pmd by pmd.

the class RuleSetTest method makeCompilationUnits.

private List<Node> makeCompilationUnits() {
    List<Node> nodes = new ArrayList<>();
    DummyNode node = new DummyNode(1);
    node.testingOnlySetBeginLine(1);
    node.testingOnlySetBeginColumn(1);
    node.setImage("Foo");
    nodes.add(node);
    return nodes;
}
Also used : DummyNode(net.sourceforge.pmd.lang.ast.DummyNode) Node(net.sourceforge.pmd.lang.ast.Node) DummyNode(net.sourceforge.pmd.lang.ast.DummyNode) ArrayList(java.util.ArrayList)

Example 3 with DummyNode

use of net.sourceforge.pmd.lang.ast.DummyNode in project pmd by pmd.

the class AbstractRuleTest method testRuleWithVariableInMessage.

@Test
public void testRuleWithVariableInMessage() {
    MyRule r = new MyRule();
    r.definePropertyDescriptor(IntegerProperty.named("testInt").desc("description").range(0, 100).defaultValue(10).uiOrder(0).build());
    r.setMessage("Message ${packageName} ${className} ${methodName} ${variableName} ${testInt} ${noSuchProperty}");
    RuleContext ctx = new RuleContext();
    ctx.setLanguageVersion(LanguageRegistry.getLanguage(DummyLanguageModule.NAME).getDefaultVersion());
    ctx.setReport(new Report());
    ctx.setSourceCodeFilename("filename");
    DummyNode s = new DummyNode(1);
    s.testingOnlySetBeginColumn(5);
    s.testingOnlySetBeginLine(5);
    s.setImage("TestImage");
    r.addViolation(ctx, s);
    RuleViolation rv = ctx.getReport().getViolationTree().iterator().next();
    assertEquals("Message foo    10 ${noSuchProperty}", rv.getDescription());
}
Also used : DummyNode(net.sourceforge.pmd.lang.ast.DummyNode) ParametricRuleViolation(net.sourceforge.pmd.lang.rule.ParametricRuleViolation) Test(org.junit.Test)

Example 4 with DummyNode

use of net.sourceforge.pmd.lang.ast.DummyNode in project pmd by pmd.

the class AbstractRuleTest method testCreateRV.

@Test
public void testCreateRV() {
    MyRule r = new MyRule();
    r.setRuleSetName("foo");
    RuleContext ctx = new RuleContext();
    ctx.setSourceCodeFilename("filename");
    DummyNode s = new DummyNode(1);
    s.testingOnlySetBeginColumn(5);
    s.testingOnlySetBeginLine(5);
    RuleViolation rv = new ParametricRuleViolation(r, ctx, s, r.getMessage());
    assertEquals("Line number mismatch!", 5, rv.getBeginLine());
    assertEquals("Filename mismatch!", "filename", rv.getFilename());
    assertEquals("Rule object mismatch!", r, rv.getRule());
    assertEquals("Rule msg mismatch!", "my rule msg", rv.getDescription());
    assertEquals("RuleSet name mismatch!", "foo", rv.getRule().getRuleSetName());
}
Also used : ParametricRuleViolation(net.sourceforge.pmd.lang.rule.ParametricRuleViolation) DummyNode(net.sourceforge.pmd.lang.ast.DummyNode) ParametricRuleViolation(net.sourceforge.pmd.lang.rule.ParametricRuleViolation) Test(org.junit.Test)

Example 5 with DummyNode

use of net.sourceforge.pmd.lang.ast.DummyNode in project pmd by pmd.

the class AbstractRuleTest method testCreateRV2.

@Test
public void testCreateRV2() {
    MyRule r = new MyRule();
    RuleContext ctx = new RuleContext();
    ctx.setSourceCodeFilename("filename");
    DummyNode s = new DummyNode(1);
    s.testingOnlySetBeginColumn(5);
    s.testingOnlySetBeginLine(5);
    RuleViolation rv = new ParametricRuleViolation(r, ctx, s, "specificdescription");
    assertEquals("Line number mismatch!", 5, rv.getBeginLine());
    assertEquals("Filename mismatch!", "filename", rv.getFilename());
    assertEquals("Rule object mismatch!", r, rv.getRule());
    assertEquals("Rule description mismatch!", "specificdescription", rv.getDescription());
}
Also used : ParametricRuleViolation(net.sourceforge.pmd.lang.rule.ParametricRuleViolation) DummyNode(net.sourceforge.pmd.lang.ast.DummyNode) ParametricRuleViolation(net.sourceforge.pmd.lang.rule.ParametricRuleViolation) Test(org.junit.Test)

Aggregations

DummyNode (net.sourceforge.pmd.lang.ast.DummyNode)25 Test (org.junit.Test)17 ParametricRuleViolation (net.sourceforge.pmd.lang.rule.ParametricRuleViolation)13 RuleContext (net.sourceforge.pmd.RuleContext)5 MockRule (net.sourceforge.pmd.lang.rule.MockRule)5 Report (net.sourceforge.pmd.Report)4 Node (net.sourceforge.pmd.lang.ast.Node)4 FooRule (net.sourceforge.pmd.FooRule)3 ReportTest (net.sourceforge.pmd.ReportTest)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Method (java.lang.reflect.Method)1 List (java.util.List)1 RuleViolation (net.sourceforge.pmd.RuleViolation)1 RuleWithProperties (net.sourceforge.pmd.RuleWithProperties)1 RootNode (net.sourceforge.pmd.lang.ast.RootNode)1 Attribute (net.sourceforge.pmd.lang.ast.xpath.Attribute)1 AttributeAxisIterator (net.sourceforge.pmd.lang.ast.xpath.AttributeAxisIterator)1 XPathRule (net.sourceforge.pmd.lang.rule.XPathRule)1 StatisticalRule (net.sourceforge.pmd.lang.rule.stat.StatisticalRule)1