Remove childrenAccept

This commit is contained in:
Clément Fournier
2020-04-22 00:16:38 +02:00
parent 11d7aeb10f
commit 35c2637405
10 changed files with 163 additions and 684 deletions

View File

@ -23,7 +23,7 @@ public abstract class AbstractJjtreeNode<N extends JjtreeNode<N>> extends Abstra
private JavaccToken lastToken;
public AbstractJjtreeNode(int id) {
protected AbstractJjtreeNode(int id) {
super();
this.id = id;
}

View File

@ -7,7 +7,6 @@ package net.sourceforge.pmd.lang.java.ast;
import org.checkerframework.checker.nullness.qual.NonNull;
import net.sourceforge.pmd.annotation.InternalApi;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.ast.impl.javacc.AbstractJjtreeNode;
import net.sourceforge.pmd.lang.symboltable.Scope;
@ -25,24 +24,6 @@ public abstract class AbstractJavaNode extends AbstractJjtreeNode<JavaNode> impl
super(id);
}
@Override
public Object childrenAccept(JavaParserVisitor visitor, Object data) {
for (Node child : children()) {
((JavaNode) child).jjtAccept(visitor, data);
}
return data;
}
@Override
public <T> void childrenAccept(SideEffectingVisitor<T> visitor, T data) {
for (Node child : children()) {
((JavaNode) child).jjtAccept(visitor, data);
}
}
@Override
public Scope getScope() {

View File

@ -27,24 +27,6 @@ public interface JavaNode extends ScopedNode, JjtreeNode<JavaNode> {
Object jjtAccept(JavaParserVisitor visitor, Object data);
/**
* Dispatches the given visitor to the children of this node. This is the default implementation
* of {@link JavaParserVisitor#visit(JavaNode, Object)}, to which all other default
* implementations for visit methods delegate. Unless visit methods are overridden without calling
* {@code super.visit}, the visitor performs a depth-first tree walk.
*
* <p>The return value of the visit methods called on children are ignored.
*
* @param visitor Visitor to dispatch
* @param data Visit data
*
* @deprecated This method is not useful, the logic for combining
* children values should be present on the visitor, not the node
*/
@Deprecated
Object childrenAccept(JavaParserVisitor visitor, Object data);
/**
* Calls back the visitor's visit method corresponding to the runtime type of this Node.
*
@ -55,18 +37,6 @@ public interface JavaNode extends ScopedNode, JjtreeNode<JavaNode> {
<T> void jjtAccept(SideEffectingVisitor<T> visitor, T data);
/**
* Dispatches the given visitor to the children of this node. This is the default implementation
* of {@link SideEffectingVisitor#visit(JavaNode, Object)}, to which all other default
* implementations for visit methods delegate. Unless visit methods are overridden without calling
* {@code super.visit}, the visitor performs a depth-first tree walk.
*
* @param visitor Visitor to dispatch
* @param data Visit data
* @param <T> Type of data
*/
<T> void childrenAccept(SideEffectingVisitor<T> visitor, T data);
@InternalApi
@Deprecated
void setScope(Scope scope);

View File

@ -54,14 +54,16 @@ public class CouplingBetweenObjectsRule extends AbstractJavaRule {
typesFoundSoFar = new HashSet<>();
couplingCount = 0;
Object returnObj = cu.childrenAccept(this, data);
for (JavaNode child : cu.children()) {
child.jjtAccept(this, data);
}
if (couplingCount > getProperty(THRESHOLD_DESCRIPTOR)) {
addViolation(data, cu,
"A value of " + couplingCount + " may denote a high amount of coupling within the class");
}
return returnObj;
return data;
}
@Override

View File

@ -49,7 +49,9 @@ public class MoreThanOneLoggerRule extends AbstractJavaRule {
stack.push(count);
count = NumericConstants.ZERO;
node.childrenAccept(this, data);
for (JavaNode child : node.children()) {
child.jjtAccept(this, data);
}
if (count > 1) {
addViolation(data, node);

View File

@ -6,7 +6,6 @@ package net.sourceforge.pmd.lang.ecmascript.ast;
import org.mozilla.javascript.ast.AstNode;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.ast.SourceCodePositioner;
import net.sourceforge.pmd.lang.ast.impl.AbstractNodeWithTextCoordinates;
@ -42,21 +41,6 @@ abstract class AbstractEcmascriptNode<T extends AstNode> extends AbstractNodeWit
return visitor.visit(this, data);
}
/**
* Accept the visitor. *
*/
@Override
public Object childrenAccept(EcmascriptParserVisitor visitor, Object data) {
for (Node child : children) {
// we know that the children here
// are all EcmascriptNodes
@SuppressWarnings("unchecked")
EcmascriptNode<T> ecmascriptNode = (EcmascriptNode<T>) child;
ecmascriptNode.jjtAccept(visitor, data);
}
return data;
}
@Override
@Deprecated
public T getNode() {

View File

@ -15,14 +15,6 @@ public interface EcmascriptNode<T extends AstNode> extends GenericNode<Ecmascrip
*/
Object jjtAccept(EcmascriptParserVisitor visitor, Object data);
/**
* Accept the visitor. *
*
* @deprecated This method is not useful, the logic for combining
* children values should be present on the visitor, not the node
*/
@Deprecated
Object childrenAccept(EcmascriptParserVisitor visitor, Object data);
/**
* Get the underlying Rhino AST node.

View File

@ -1,107 +1,211 @@
/*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.ecmascript.ast;
public interface EcmascriptParserVisitor {
Object visit(EcmascriptNode<?> node, Object data);
Object visit(ASTArrayComprehension node, Object data);
default Object visit(EcmascriptNode<?> node, Object data) {
for (EcmascriptNode<?> child : node.children()) {
child.jjtAccept(this, data);
}
return data;
}
Object visit(ASTArrayComprehensionLoop node, Object data);
default Object visit(ASTArrayComprehension node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
Object visit(ASTArrayLiteral node, Object data);
default Object visit(ASTArrayComprehensionLoop node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
Object visit(ASTAssignment node, Object data);
default Object visit(ASTArrayLiteral node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
Object visit(ASTAstRoot node, Object data);
default Object visit(ASTAssignment node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
Object visit(ASTBlock node, Object data);
default Object visit(ASTAstRoot node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
Object visit(ASTBreakStatement node, Object data);
default Object visit(ASTBlock node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
Object visit(ASTCatchClause node, Object data);
default Object visit(ASTBreakStatement node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
Object visit(ASTComment node, Object data);
default Object visit(ASTCatchClause node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
Object visit(ASTConditionalExpression node, Object data);
default Object visit(ASTComment node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
Object visit(ASTContinueStatement node, Object data);
default Object visit(ASTConditionalExpression node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
Object visit(ASTDoLoop node, Object data);
default Object visit(ASTContinueStatement node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
Object visit(ASTElementGet node, Object data);
default Object visit(ASTDoLoop node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
Object visit(ASTEmptyExpression node, Object data);
default Object visit(ASTElementGet node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
Object visit(ASTExpressionStatement node, Object data);
default Object visit(ASTEmptyExpression node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
Object visit(ASTForInLoop node, Object data);
default Object visit(ASTExpressionStatement node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
Object visit(ASTForLoop node, Object data);
default Object visit(ASTForInLoop node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
Object visit(ASTFunctionCall node, Object data);
default Object visit(ASTForLoop node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
Object visit(ASTFunctionNode node, Object data);
default Object visit(ASTFunctionCall node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
Object visit(ASTIfStatement node, Object data);
default Object visit(ASTFunctionNode node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
Object visit(ASTInfixExpression node, Object data);
default Object visit(ASTIfStatement node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
Object visit(ASTKeywordLiteral node, Object data);
default Object visit(ASTInfixExpression node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
Object visit(ASTLabel node, Object data);
default Object visit(ASTKeywordLiteral node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
Object visit(ASTLabeledStatement node, Object data);
default Object visit(ASTLabel node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
Object visit(ASTLetNode node, Object data);
default Object visit(ASTLabeledStatement node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
Object visit(ASTName node, Object data);
default Object visit(ASTLetNode node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
Object visit(ASTNewExpression node, Object data);
default Object visit(ASTName node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
Object visit(ASTNumberLiteral node, Object data);
default Object visit(ASTNewExpression node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
Object visit(ASTObjectLiteral node, Object data);
default Object visit(ASTNumberLiteral node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
Object visit(ASTObjectProperty node, Object data);
default Object visit(ASTObjectLiteral node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
Object visit(ASTParenthesizedExpression node, Object data);
default Object visit(ASTObjectProperty node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
Object visit(ASTPropertyGet node, Object data);
default Object visit(ASTParenthesizedExpression node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
Object visit(ASTRegExpLiteral node, Object data);
default Object visit(ASTPropertyGet node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
Object visit(ASTReturnStatement node, Object data);
default Object visit(ASTRegExpLiteral node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
Object visit(ASTScope node, Object data);
default Object visit(ASTReturnStatement node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
Object visit(ASTStringLiteral node, Object data);
default Object visit(ASTScope node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
Object visit(ASTSwitchCase node, Object data);
default Object visit(ASTStringLiteral node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
Object visit(ASTSwitchStatement node, Object data);
default Object visit(ASTSwitchCase node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
Object visit(ASTThrowStatement node, Object data);
default Object visit(ASTSwitchStatement node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
Object visit(ASTTryStatement node, Object data);
default Object visit(ASTThrowStatement node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
Object visit(ASTUnaryExpression node, Object data);
default Object visit(ASTTryStatement node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
Object visit(ASTVariableDeclaration node, Object data);
default Object visit(ASTUnaryExpression node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
Object visit(ASTVariableInitializer node, Object data);
default Object visit(ASTVariableDeclaration node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
Object visit(ASTWhileLoop node, Object data);
default Object visit(ASTVariableInitializer node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
Object visit(ASTWithStatement node, Object data);
default Object visit(ASTWhileLoop node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
Object visit(ASTXmlDotQuery node, Object data);
default Object visit(ASTWithStatement node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
Object visit(ASTXmlExpression node, Object data);
default Object visit(ASTXmlDotQuery node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
Object visit(ASTXmlMemberGet node, Object data);
default Object visit(ASTXmlExpression node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
Object visit(ASTXmlString node, Object data);
default Object visit(ASTXmlMemberGet node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
default Object visit(ASTXmlString node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
}

View File

@ -6,254 +6,4 @@ package net.sourceforge.pmd.lang.ecmascript.ast;
public class EcmascriptParserVisitorAdapter implements EcmascriptParserVisitor {
@Override
public Object visit(EcmascriptNode<?> node, Object data) {
node.childrenAccept(this, data);
return null;
}
@Override
public Object visit(ASTArrayComprehension node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
@Override
public Object visit(ASTArrayComprehensionLoop node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
@Override
public Object visit(ASTArrayLiteral node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
@Override
public Object visit(ASTAssignment node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
@Override
public Object visit(ASTAstRoot node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
@Override
public Object visit(ASTBlock node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
@Override
public Object visit(ASTBreakStatement node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
@Override
public Object visit(ASTCatchClause node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
@Override
public Object visit(ASTComment node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
@Override
public Object visit(ASTConditionalExpression node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
@Override
public Object visit(ASTContinueStatement node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
@Override
public Object visit(ASTDoLoop node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
@Override
public Object visit(ASTElementGet node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
@Override
public Object visit(ASTEmptyExpression node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
@Override
public Object visit(ASTExpressionStatement node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
@Override
public Object visit(ASTForInLoop node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
@Override
public Object visit(ASTForLoop node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
@Override
public Object visit(ASTFunctionCall node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
@Override
public Object visit(ASTFunctionNode node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
@Override
public Object visit(ASTIfStatement node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
@Override
public Object visit(ASTInfixExpression node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
@Override
public Object visit(ASTKeywordLiteral node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
@Override
public Object visit(ASTLabel node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
@Override
public Object visit(ASTLabeledStatement node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
@Override
public Object visit(ASTLetNode node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
@Override
public Object visit(ASTName node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
@Override
public Object visit(ASTNewExpression node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
@Override
public Object visit(ASTNumberLiteral node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
@Override
public Object visit(ASTObjectLiteral node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
@Override
public Object visit(ASTObjectProperty node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
@Override
public Object visit(ASTParenthesizedExpression node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
@Override
public Object visit(ASTPropertyGet node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
@Override
public Object visit(ASTRegExpLiteral node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
@Override
public Object visit(ASTReturnStatement node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
@Override
public Object visit(ASTScope node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
@Override
public Object visit(ASTStringLiteral node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
@Override
public Object visit(ASTSwitchCase node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
@Override
public Object visit(ASTSwitchStatement node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
@Override
public Object visit(ASTThrowStatement node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
@Override
public Object visit(ASTTryStatement node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
@Override
public Object visit(ASTUnaryExpression node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
@Override
public Object visit(ASTVariableDeclaration node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
@Override
public Object visit(ASTVariableInitializer node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
@Override
public Object visit(ASTWhileLoop node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
@Override
public Object visit(ASTWithStatement node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
@Override
public Object visit(ASTXmlDotQuery node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
@Override
public Object visit(ASTXmlExpression node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
@Override
public Object visit(ASTXmlMemberGet node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
@Override
public Object visit(ASTXmlString node, Object data) {
return visit((EcmascriptNode<?>) node, data);
}
}