[xml] Fix impl and tests
This commit is contained in:
parent
adfd3963a0
commit
120d24dae4
@ -20,6 +20,7 @@ import org.w3c.dom.Text;
|
||||
import net.sourceforge.pmd.lang.document.TextDocument;
|
||||
import net.sourceforge.pmd.lang.document.TextRegion;
|
||||
import net.sourceforge.pmd.lang.rule.xpath.Attribute;
|
||||
import net.sourceforge.pmd.lang.rule.xpath.NoAttribute;
|
||||
import net.sourceforge.pmd.lang.rule.xpath.internal.CoordinateXPathFunction;
|
||||
import net.sourceforge.pmd.lang.xml.ast.XmlNode;
|
||||
import net.sourceforge.pmd.util.DataMap;
|
||||
@ -98,6 +99,7 @@ class XmlNodeWrapper implements XmlNode {
|
||||
/**
|
||||
* Returns the text, if the underlying node is a text node.
|
||||
*/
|
||||
@NoAttribute // see getXPathAttributesIterator() for how this is exposed as XPath attribute
|
||||
public String getText() {
|
||||
return node instanceof Text ? ((Text) node).getData() : null;
|
||||
}
|
||||
@ -131,9 +133,9 @@ class XmlNodeWrapper implements XmlNode {
|
||||
@Override
|
||||
public Iterator<Attribute> getXPathAttributesIterator() {
|
||||
|
||||
// Expose Text/CDATA nodes to have an 'Image' attribute like AST Nodes
|
||||
// Expose Text/CDATA nodes to have an 'Text' attribute like AST Nodes
|
||||
if (node instanceof Text) {
|
||||
return Collections.singletonList(new Attribute(this, "Image", ((Text) node).getData())).iterator();
|
||||
return Collections.singletonList(new Attribute(this, "Text", getText())).iterator();
|
||||
}
|
||||
|
||||
// Expose DOM Attributes
|
||||
|
@ -2,14 +2,14 @@
|
||||
+- comment[]
|
||||
+- rootElement[]
|
||||
+- rootElement[]
|
||||
+- text[@Image = "\n "]
|
||||
+- text[@Text = "\n "]
|
||||
+- comment[]
|
||||
+- text[@Image = "\n "]
|
||||
+- text[@Text = "\n "]
|
||||
+- child1[@test = "1"]
|
||||
| +- text[@Image = "entity: Copyright: PMD\n "]
|
||||
+- text[@Image = "\n "]
|
||||
| +- text[@Text = "entity: Copyright: PMD\n "]
|
||||
+- text[@Text = "\n "]
|
||||
+- child2[]
|
||||
| +- text[@Image = "\n "]
|
||||
| +- cdata-section[@Image = " cdata section "]
|
||||
| +- text[@Image = "\n "]
|
||||
+- text[@Image = "\n"]
|
||||
| +- text[@Text = "\n "]
|
||||
| +- cdata-section[@Text = " cdata section "]
|
||||
| +- text[@Text = "\n "]
|
||||
+- text[@Text = "\n"]
|
||||
|
Loading…
x
Reference in New Issue
Block a user