Search in sources :

Example 21 with DummyNode

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

the class AbstractRuleTest method testRuleSuppress.

@Test
public void testRuleSuppress() {
    MyRule r = new MyRule();
    RuleContext ctx = new RuleContext();
    Map<Integer, String> m = new HashMap<>();
    m.put(Integer.valueOf(5), "");
    ctx.setReport(new Report());
    ctx.getReport().suppress(m);
    ctx.setSourceCodeFilename("filename");
    DummyNode n = new DummyNode(1);
    n.testingOnlySetBeginColumn(5);
    n.testingOnlySetBeginLine(5);
    RuleViolation rv = new ParametricRuleViolation(r, ctx, n, "specificdescription");
    ctx.getReport().addRuleViolation(rv);
    assertTrue(ctx.getReport().isEmpty());
}
Also used : ParametricRuleViolation(net.sourceforge.pmd.lang.rule.ParametricRuleViolation) HashMap(java.util.HashMap) DummyNode(net.sourceforge.pmd.lang.ast.DummyNode) ParametricRuleViolation(net.sourceforge.pmd.lang.rule.ParametricRuleViolation) Test(org.junit.Test)

Example 22 with DummyNode

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

the class AbstractRendererTst method createNode.

protected static DummyNode createNode(int endColumn) {
    DummyNode node = new DummyNode(1);
    node.testingOnlySetBeginLine(1);
    node.testingOnlySetBeginColumn(1);
    node.testingOnlySetEndLine(1);
    node.testingOnlySetEndColumn(endColumn);
    return node;
}
Also used : DummyNode(net.sourceforge.pmd.lang.ast.DummyNode)

Example 23 with DummyNode

use of net.sourceforge.pmd.lang.ast.DummyNode 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 24 with DummyNode

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

the class AttributeAxisIteratorTest method testAttributeAxisIterator.

/**
 * Test hasNext and next.
 */
@Test
public void testAttributeAxisIterator() {
    DummyNode dummyNode = new DummyNode(1);
    dummyNode.testingOnlySetBeginLine(1);
    dummyNode.testingOnlySetBeginColumn(1);
    AttributeAxisIterator it = new AttributeAxisIterator(dummyNode);
    Map<String, Attribute> atts = new HashMap<>();
    while (it.hasNext()) {
        Attribute attribute = it.next();
        atts.put(attribute.getName(), attribute);
    }
    Assert.assertEquals(7, atts.size());
    Assert.assertTrue(atts.containsKey("BeginColumn"));
    Assert.assertTrue(atts.containsKey("BeginLine"));
    Assert.assertTrue(atts.containsKey("FindBoundary"));
    Assert.assertTrue(atts.containsKey("Image"));
    Assert.assertTrue(atts.containsKey("SingleLine"));
    Assert.assertTrue(atts.containsKey("EndColumn"));
    Assert.assertTrue(atts.containsKey("EndLine"));
}
Also used : HashMap(java.util.HashMap) DummyNode(net.sourceforge.pmd.lang.ast.DummyNode) Test(org.junit.Test)

Example 25 with DummyNode

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

the class DocumentNavigatorTest method getDocumentNode.

@Test
public void getDocumentNode() {
    DocumentNavigator nav = new DocumentNavigator();
    try {
        nav.getDocumentNode(null);
        fail();
    } catch (RuntimeException e) {
        assertNotNull(e);
    }
    Node root = new DummyRootNode(1);
    Node n = new DummyNode(1);
    root.jjtAddChild(n, 0);
    n.jjtSetParent(root);
    assertSame(root, nav.getDocumentNode(n));
}
Also used : DummyNode(net.sourceforge.pmd.lang.ast.DummyNode) DummyNode(net.sourceforge.pmd.lang.ast.DummyNode) RootNode(net.sourceforge.pmd.lang.ast.RootNode) Node(net.sourceforge.pmd.lang.ast.Node) 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