diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/Node.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/Node.java index 8d919f1114..2d5b47d858 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/Node.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/Node.java @@ -282,17 +282,19 @@ public interface Node { * @param visitor Visitor to dispatch * @param data Parameter to the visit * - * @return What the visitor returned - * - * @throws IllegalArgumentException If the visitor is incompatible with this node + * @return What the visitor returned. If this node doesn't recognize + * the type of the visitor, returns {@link AstVisitor#cannotVisit(Node, Object) visitor.cannotVisit(this, data)}. * * @implSpec A typical implementation will check the type of the visitor to * be that of the language specific visitor, then call the most specific * visit method of this Node. This is typically implemented by having - * a different override per concrete node class (no shortcuts). If the - * visitor is not handled, call {@link AstVisitor#cannotVisit(Node, Object)}. + * a different override per concrete node class (no shortcuts). + * + * The default implementation calls back {@link AstVisitor#cannotVisit(Node, Object)}. */ - R acceptVisitor(AstVisitor visitor, P data); + default R acceptVisitor(AstVisitor visitor, P data) { + return visitor.cannotVisit(this, data); + } /** 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 3895703a29..730945af6c 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 @@ -15,7 +15,6 @@ import org.w3c.dom.NamedNodeMap; import org.w3c.dom.NodeList; import org.w3c.dom.Text; -import net.sourceforge.pmd.lang.ast.AstVisitor; import net.sourceforge.pmd.lang.rule.xpath.Attribute; import net.sourceforge.pmd.lang.xml.ast.XmlNode; import net.sourceforge.pmd.util.CompoundIterator; @@ -162,11 +161,6 @@ class XmlNodeWrapper implements XmlNode { return new CompoundIterator<>(iterators.toArray(it)); } - @Override - public R acceptVisitor(AstVisitor visitor, P data) { - return visitor.cannotVisit(this, data); - } - @Override public org.w3c.dom.Node getNode() { return node;