diff --git a/antlr4-wrapper.xml b/antlr4-wrapper.xml index 61f9c5fddf..f6a221708b 100644 --- a/antlr4-wrapper.xml +++ b/antlr4-wrapper.xml @@ -51,7 +51,7 @@ value="((${visitor-name}<? super P, ? extends R>) visitor)" /> + value="return super.acceptVisitor(visitor, data);" /> 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 8e15b071eb..52e93c486d 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 @@ -296,11 +296,18 @@ public interface Node { * @param data Parameter to the visit * * @return What the visitor returned + * + * @throws IllegalArgumentException If the visitor is incompatible with this 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). */ // TODO remove the default implementation, convert all visitors to be generic default R acceptVisitor(AstVisitor visitor, P data) { // override me - return visitor.visitNode(this, data); + throw new IllegalArgumentException("Unsupported visitor" + visitor + " for node " + this); } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/AbstractJavaNode.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/AbstractJavaNode.java index a50522a092..79681561a4 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/AbstractJavaNode.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/AbstractJavaNode.java @@ -38,7 +38,7 @@ public abstract class AbstractJavaNode extends AbstractJjtreeNode) visitor, data); } - return visitor.visitNode(this, data); + return super.acceptVisitor(visitor, data); } protected abstract R acceptVisitor(JavaVisitor visitor, P data); diff --git a/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/ast/AbstractJspNode.java b/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/ast/AbstractJspNode.java index d325167911..a0c2c53c57 100644 --- a/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/ast/AbstractJspNode.java +++ b/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/ast/AbstractJspNode.java @@ -18,7 +18,7 @@ abstract class AbstractJspNode extends AbstractJjtreeNode) visitor, data); } - return visitor.visitNode(this, data); + return super.acceptVisitor(visitor, data); } protected abstract R acceptVisitor(JspVisitor visitor, P data); diff --git a/pmd-scala-modules/pmd-scala-common/src/main/java/net/sourceforge/pmd/lang/scala/ast/AbstractScalaNode.java b/pmd-scala-modules/pmd-scala-common/src/main/java/net/sourceforge/pmd/lang/scala/ast/AbstractScalaNode.java index caf0f8e2c0..3f4810296a 100644 --- a/pmd-scala-modules/pmd-scala-common/src/main/java/net/sourceforge/pmd/lang/scala/ast/AbstractScalaNode.java +++ b/pmd-scala-modules/pmd-scala-common/src/main/java/net/sourceforge/pmd/lang/scala/ast/AbstractScalaNode.java @@ -38,7 +38,7 @@ abstract class AbstractScalaNode extends AbstractNode) visitor, data); } - return visitor.visitNode(this, data); + return super.acceptVisitor(visitor, data); } protected abstract R acceptVisitor(ScalaParserVisitor visitor, P data);