From dd303a0903379709da76329a0e33300b617c442f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Tue, 25 Aug 2020 02:12:03 +0200 Subject: [PATCH] Remove default implementation --- .../src/main/java/net/sourceforge/pmd/lang/ast/Node.java | 9 +++------ .../pmd/lang/xml/ast/internal/XmlNodeWrapper.java | 5 +++++ 2 files changed, 8 insertions(+), 6 deletions(-) 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 b2972344d3..8d919f1114 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 @@ -289,13 +289,10 @@ public interface Node { * @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). + * a different override per concrete node class (no shortcuts). If the + * visitor is not handled, call {@link AstVisitor#cannotVisit(Node, Object)}. */ - // TODO remove the default implementation, convert all visitors to be generic - default R acceptVisitor(AstVisitor visitor, P data) { - // override me - throw new IllegalArgumentException("Unsupported visitor" + visitor + " for node " + this); - } + R acceptVisitor(AstVisitor visitor, P 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 282c0b1e4d..3895703a29 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,6 +15,7 @@ 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; @@ -161,6 +162,10 @@ 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() {