Same for VM module

This commit is contained in:
Clément Fournier
2020-08-25 01:38:11 +02:00
parent 6ccd620309
commit eed8a1609a
19 changed files with 62 additions and 18 deletions

View File

@ -494,8 +494,8 @@ public interface" />
<replacefilter token="${base-visitor-interface-name}"
value="${generic-visitor-interface-name}&lt;P, R> extends ${ast-api-package}.AstVisitor&lt;P, R>" />
<replacefilter token="Object" value="P" />
<replacefilter token="P visit" value="R visit" />
<replacefilter token="Object data" value="P data" />
<replacefilter token="Object visit" value="R visit" />
<replacefilter token="default R visit${node-name}(${node-name} node, P data) { for (int i = 0, len = node.getNumChildren(); i &lt; len; i++) node.getChild(i).jjtAccept(this, data); return data; }"
value="default R visit${node-name}(${node-name} node, P data) { return visitNode(node, data); }" />

View File

@ -42,7 +42,7 @@
</goals>
<configuration>
<target>
<ant antfile="${javacc.ant.wrapper}" target="alljavacc">
<ant antfile="${javacc.ant.wrapper}" target="alljavacc-visitor+">
<property name="javacc.jar" value="${javacc.jar}" />
<property name="lang-name" value="Vm" />
<property name="lang-terse-name" value="vm" />

View File

@ -39,7 +39,7 @@ public final class ASTAddNode extends ASTMathNode {
@Override
public Object jjtAccept(VmParserVisitor visitor, Object data) {
protected <P, R> R acceptVmVisitor(VmVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
}

View File

@ -14,7 +14,7 @@ public final class ASTBlock extends AbstractVmNode {
@Override
public Object jjtAccept(VmParserVisitor visitor, Object data) {
protected <P, R> R acceptVmVisitor(VmVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}

View File

@ -73,7 +73,7 @@ public final class ASTDirective extends AbstractVmNode {
}
@Override
public Object jjtAccept(final VmParserVisitor visitor, final Object data) {
protected <P, R> R acceptVmVisitor(VmVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}

View File

@ -40,7 +40,7 @@ public final class ASTDivNode extends ASTMathNode {
@Override
public Object jjtAccept(VmParserVisitor visitor, Object data) {
protected <P, R> R acceptVmVisitor(VmVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
}

View File

@ -48,7 +48,7 @@ public final class ASTEscape extends AbstractVmNode {
}
@Override
public Object jjtAccept(final VmParserVisitor visitor, final Object data) {
protected <P, R> R acceptVmVisitor(VmVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}

View File

@ -42,7 +42,7 @@ public final class ASTMethod extends AbstractVmNode {
}
@Override
public Object jjtAccept(final VmParserVisitor visitor, final Object data) {
protected <P, R> R acceptVmVisitor(VmVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}

View File

@ -39,7 +39,7 @@ public final class ASTModNode extends ASTMathNode {
@Override
public Object jjtAccept(VmParserVisitor visitor, Object data) {
protected <P, R> R acceptVmVisitor(VmVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
}

View File

@ -40,7 +40,7 @@ public final class ASTMulNode extends ASTMathNode {
@Override
public Object jjtAccept(VmParserVisitor visitor, Object data) {
protected <P, R> R acceptVmVisitor(VmVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
}

View File

@ -42,7 +42,7 @@ public final class ASTReference extends AbstractVmNode {
}
@Override
public Object jjtAccept(final VmParserVisitor visitor, final Object data) {
protected <P, R> R acceptVmVisitor(VmVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}

View File

@ -32,7 +32,7 @@ public final class ASTStringLiteral extends AbstractVmNode {
}
@Override
public Object jjtAccept(final VmParserVisitor visitor, final Object data) {
protected <P, R> R acceptVmVisitor(VmVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}

View File

@ -41,7 +41,7 @@ public final class ASTSubtractNode extends ASTMathNode {
@Override
public Object jjtAccept(VmParserVisitor visitor, Object data) {
protected <P, R> R acceptVmVisitor(VmVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
}

View File

@ -14,7 +14,7 @@ public final class ASTTemplate extends AbstractVmNode implements RootNode {
@Override
public Object jjtAccept(VmParserVisitor visitor, Object data) {
protected <P, R> R acceptVmVisitor(VmVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
}

View File

@ -20,6 +20,7 @@ package net.sourceforge.pmd.lang.vm.ast;
* under the License.
*/
import net.sourceforge.pmd.lang.ast.AstVisitor;
import net.sourceforge.pmd.lang.ast.impl.javacc.AbstractJjtreeNode;
import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccToken;
@ -40,6 +41,18 @@ abstract class AbstractVmNode extends AbstractJjtreeNode<AbstractVmNode, VmNode>
return VmParserImplTreeConstants.jjtNodeName[id];
}
protected abstract <P, R> R acceptVmVisitor(VmVisitor<? super P, ? extends R> visitor, P data);
@Override
@SuppressWarnings("unchecked")
public final <P, R> R acceptVisitor(AstVisitor<? super P, ? extends R> visitor, P data) {
if (visitor instanceof VmVisitor) {
return acceptVmVisitor((VmVisitor<? super P, ? extends R>) visitor, data);
}
return visitor.cannotVisit(this, data);
}
/*
* see org.apache.velocity.runtime.parser.node.Node#literal()
*/

View File

@ -4,12 +4,21 @@
package net.sourceforge.pmd.lang.vm.ast;
import net.sourceforge.pmd.annotation.DeprecatedUntil700;
import net.sourceforge.pmd.lang.ast.AstVisitor;
import net.sourceforge.pmd.lang.ast.impl.javacc.JjtreeNode;
public interface VmNode extends JjtreeNode<VmNode> {
/**
* Accept the visitor.
*
* @deprecated Use {@link #acceptVisitor(AstVisitor, Object)}
*/
Object jjtAccept(VmParserVisitor visitor, Object data);
@Deprecated
@DeprecatedUntil700
default Object jjtAccept(VmParserVisitor visitor, Object data) {
return acceptVisitor(visitor, data);
}
}

View File

@ -0,0 +1,19 @@
/*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.vm.ast;
import net.sourceforge.pmd.annotation.DeprecatedUntil700;
import net.sourceforge.pmd.lang.ast.Node;
@Deprecated
@DeprecatedUntil700
public interface VmParserVisitor extends VmVisitor<Object, Object> {
@Override
default Object visitNode(Node node, Object param) {
node.children().forEach(it -> it.acceptVisitor(this, param));
return param;
}
}

View File

@ -4,6 +4,10 @@
package net.sourceforge.pmd.lang.vm.ast;
import net.sourceforge.pmd.annotation.DeprecatedUntil700;
@Deprecated
@DeprecatedUntil700
public class VmParserVisitorAdapter implements VmParserVisitor {
}

View File

@ -10,7 +10,6 @@ import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.rule.AbstractRule;
import net.sourceforge.pmd.lang.rule.ImmutableLanguage;
import net.sourceforge.pmd.lang.vm.VmLanguageModule;
import net.sourceforge.pmd.lang.vm.ast.VmNode;
import net.sourceforge.pmd.lang.vm.ast.VmParserVisitor;
public abstract class AbstractVmRule extends AbstractRule implements VmParserVisitor, ImmutableLanguage {
@ -21,7 +20,7 @@ public abstract class AbstractVmRule extends AbstractRule implements VmParserVis
@Override
public void apply(Node target, RuleContext ctx) {
((VmNode) target).jjtAccept(this, ctx);
target.acceptVisitor(this, ctx);
}
}