Search in sources :

Example 1 with Attribute

use of net.sourceforge.pmd.lang.ast.xpath.Attribute in project pmd by pmd.

the class AttributeTest method testConstructor.

@Test
public void testConstructor() {
    DummyNode p = new DummyNode(1);
    p.testingOnlySetBeginLine(5);
    Method[] methods = p.getClass().getMethods();
    Method m = null;
    for (int i = 0; i < methods.length; i++) {
        if (methods[i].getName().equals("getBeginLine")) {
            m = methods[i];
            break;
        }
    }
    Attribute a = new Attribute(p, "BeginLine", m);
    assertEquals("BeginLine", a.getName());
    assertEquals(5, a.getValue());
    assertEquals("5", a.getStringValue());
    assertEquals(p, a.getParent());
}
Also used : Attribute(net.sourceforge.pmd.lang.ast.xpath.Attribute) DummyNode(net.sourceforge.pmd.lang.ast.DummyNode) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 2 with Attribute

use of net.sourceforge.pmd.lang.ast.xpath.Attribute in project pmd by pmd.

the class NodeInfoPanelController method getAttributes.

/**
 * Gets the XPath attributes of the node for display within a listview.
 */
private static ObservableList<String> getAttributes(Node node) {
    ObservableList<String> result = FXCollections.observableArrayList();
    AttributeAxisIterator attributeAxisIterator = new AttributeAxisIterator(node);
    while (attributeAxisIterator.hasNext()) {
        Attribute attribute = attributeAxisIterator.next();
        result.add(attribute.getName() + " = " + ((attribute.getValue() != null) ? attribute.getStringValue() : "null"));
    }
    if (node instanceof TypeNode) {
        result.add("typeof() = " + ((TypeNode) node).getType());
    }
    Collections.sort(result);
    return result;
}
Also used : Attribute(net.sourceforge.pmd.lang.ast.xpath.Attribute) TypeNode(net.sourceforge.pmd.lang.java.ast.TypeNode) AttributeAxisIterator(net.sourceforge.pmd.lang.ast.xpath.AttributeAxisIterator)

Example 3 with Attribute

use of net.sourceforge.pmd.lang.ast.xpath.Attribute in project pmd by pmd.

the class XmlParserTest method assertTextNode.

/**
 * Assert a single text node.
 *
 * @param node
 *            the node to check
 * @param text
 *            the text to expect
 * @param toString
 *            the to string representation
 */
private void assertTextNode(Node node, String text, String toString) {
    Assert.assertEquals(toString, String.valueOf(node));
    Assert.assertEquals(0, node.jjtGetNumChildren());
    Assert.assertEquals(text, StringUtil.escapeWhitespace(node.getImage()));
    Iterator<Attribute> attributeIterator = ((XmlNode) node).getAttributeIterator();
    Assert.assertTrue(attributeIterator.hasNext());
    Attribute attribute = attributeIterator.next();
    Assert.assertEquals("Image", attribute.getName());
    Assert.assertEquals(text, StringUtil.escapeWhitespace(attribute.getValue()));
    Assert.assertFalse(attributeIterator.hasNext());
}
Also used : XmlNode(net.sourceforge.pmd.lang.xml.ast.XmlNode) Attribute(net.sourceforge.pmd.lang.ast.xpath.Attribute)

Example 4 with Attribute

use of net.sourceforge.pmd.lang.ast.xpath.Attribute in project pmd by pmd.

the class AbstractNode method appendElement.

protected void appendElement(org.w3c.dom.Node parentNode) {
    DocumentNavigator docNav = new DocumentNavigator();
    Document ownerDocument = parentNode.getOwnerDocument();
    if (ownerDocument == null) {
        // If the parentNode is a Document itself, it's ownerDocument is
        // null
        ownerDocument = (Document) parentNode;
    }
    String elementName = docNav.getElementName(this);
    Element element = ownerDocument.createElement(elementName);
    parentNode.appendChild(element);
    for (Iterator<Attribute> iter = docNav.getAttributeAxisIterator(this); iter.hasNext(); ) {
        Attribute attr = iter.next();
        element.setAttribute(attr.getName(), attr.getStringValue());
    }
    for (Iterator<Node> iter = docNav.getChildAxisIterator(this); iter.hasNext(); ) {
        AbstractNode child = (AbstractNode) iter.next();
        child.appendElement(element);
    }
}
Also used : Attribute(net.sourceforge.pmd.lang.ast.xpath.Attribute) Element(org.w3c.dom.Element) DataFlowNode(net.sourceforge.pmd.lang.dfa.DataFlowNode) Document(org.w3c.dom.Document) DocumentNavigator(net.sourceforge.pmd.lang.ast.xpath.DocumentNavigator)

Example 5 with Attribute

use of net.sourceforge.pmd.lang.ast.xpath.Attribute in project pmd by pmd.

the class AttributeAxisIterator method advance.

@Override
public void advance() {
    if (this.iterator.hasNext()) {
        Attribute attribute = this.iterator.next();
        super.current = new AttributeNode(attribute, super.position());
    } else {
        super.current = null;
    }
}
Also used : Attribute(net.sourceforge.pmd.lang.ast.xpath.Attribute)

Aggregations

Attribute (net.sourceforge.pmd.lang.ast.xpath.Attribute)12 ArrayList (java.util.ArrayList)3 List (java.util.List)2 Node (net.sourceforge.pmd.lang.ast.Node)2 AttributeAxisIterator (net.sourceforge.pmd.lang.ast.xpath.AttributeAxisIterator)2 DataFlowNode (net.sourceforge.pmd.lang.dfa.DataFlowNode)2 TypeNode (net.sourceforge.pmd.lang.java.ast.TypeNode)2 XmlNode (net.sourceforge.pmd.lang.xml.ast.XmlNode)2 Method (java.lang.reflect.Method)1 Iterator (java.util.Iterator)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 DummyNode (net.sourceforge.pmd.lang.ast.DummyNode)1 DocumentNavigator (net.sourceforge.pmd.lang.ast.xpath.DocumentNavigator)1 MatchesFunction (net.sourceforge.pmd.lang.xpath.MatchesFunction)1 CompoundIterator (net.sourceforge.pmd.util.CompoundIterator)1 Context (org.jaxen.Context)1 Test (org.junit.Test)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1