From adfd3963a09c899ef08788cfb774d5bf32a9f1e8 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 5 Jan 2024 16:48:29 +0100 Subject: [PATCH] [xml] Avoid using @Image - added new attribute @Text --- .../lang/xml/ast/internal/XmlNodeWrapper.java | 12 ++-- .../lang/xml/ast/internal/XmlParserImpl.java | 8 --- .../pmd/lang/xml/rule/DomXPathRule.java | 4 +- .../resources/category/pom/errorprone.xml | 8 +-- .../resources/category/xml/errorprone.xml | 2 +- .../pmd/lang/xml/ast/testdata/bug1518.txt | 62 +++++++++---------- .../pmd/lang/xml/ast/testdata/sampleXml.txt | 16 ++--- 7 files changed, 50 insertions(+), 62 deletions(-) diff --git a/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/ast/internal/XmlNodeWrapper.java b/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/ast/internal/XmlNodeWrapper.java index 93817548fa..7b471fc70a 100644 --- a/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/ast/internal/XmlNodeWrapper.java +++ b/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/ast/internal/XmlNodeWrapper.java @@ -11,7 +11,6 @@ import java.util.AbstractList; import java.util.Collections; import java.util.Iterator; import java.util.List; -import java.util.Objects; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; @@ -96,16 +95,13 @@ class XmlNodeWrapper implements XmlNode { return node.hasChildNodes() ? node.getChildNodes().getLength() : 0; } - @Override - public String getImage() { + /** + * Returns the text, if the underlying node is a text node. + */ + public String getText() { return node instanceof Text ? ((Text) node).getData() : null; } - @Override - public boolean hasImageEqualTo(String image) { - return Objects.equals(image, getImage()); - } - @Override public boolean isFindBoundary() { return false; diff --git a/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/ast/internal/XmlParserImpl.java b/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/ast/internal/XmlParserImpl.java index f307ed97af..14c8886bba 100644 --- a/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/ast/internal/XmlParserImpl.java +++ b/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/ast/internal/XmlParserImpl.java @@ -25,7 +25,6 @@ import net.sourceforge.pmd.lang.ast.ParseException; import net.sourceforge.pmd.lang.ast.Parser.ParserTask; import net.sourceforge.pmd.lang.ast.RootNode; import net.sourceforge.pmd.lang.rule.xpath.Attribute; -import net.sourceforge.pmd.lang.rule.xpath.NoAttribute; import net.sourceforge.pmd.lang.rule.xpath.impl.AttributeAxisIterator; import net.sourceforge.pmd.lang.xml.ast.XmlNode; @@ -125,13 +124,6 @@ public final class XmlParserImpl { return getNode().getXmlVersion(); } - // Hide the image attribute - @NoAttribute - @Override - public String getImage() { - return super.getImage(); - } - @Override public Iterator getXPathAttributesIterator() { // Expose this node's attributes through reflection diff --git a/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/rule/DomXPathRule.java b/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/rule/DomXPathRule.java index ce2df9d9de..31754643d9 100644 --- a/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/rule/DomXPathRule.java +++ b/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/rule/DomXPathRule.java @@ -31,10 +31,10 @@ import net.sourceforge.pmd.properties.PropertyFactory; *