Make JS visitor generic

This commit is contained in:
Clément Fournier
2020-08-07 02:38:45 +02:00
parent ab0aaadd64
commit daa51685ec
59 changed files with 328 additions and 294 deletions

View File

@ -10,29 +10,10 @@ package net.sourceforge.pmd.lang.ast;
*/
public abstract class AstVisitorBase<P, R> implements AstVisitor<P, R> {
/** Initial value when combining values returned by children. */
protected R zero() {
return null;
}
/**
* Merge two values of type R, used to combine values returned by children.
*
* @param acc Current accumulated value for the previous siblings
* (or {@link #zero()} if the child is the first child)
* @param childValue Value for the new child
*
* @return New accumulated value to use for the next sibling
*/
protected R combine(R acc, R childValue) {
return acc;
}
/**
* Visit the children. By default the data parameter is passed unchanged
* to all descendants. The {@link #zero() zero} and {@link #combine(Object, Object) combine}
* functions should be implemented if this is to return something else
* than null.
* to all descendants, and null is returned. Override this method to customize
* this behavior.
*
* @param node Node whose children should be visited
* @param data Parameter of the visit
@ -41,12 +22,10 @@ public abstract class AstVisitorBase<P, R> implements AstVisitor<P, R> {
*/
// kept separate from super.visit for clarity
protected R visitChildren(Node node, P data) {
R result = zero();
for (Node child : node.children()) {
R r1 = child.acceptVisitor(this, data);
result = combine(result, r1);
child.acceptVisitor(this, data);
}
return result;
return null;
}
@Override

View File

@ -12,7 +12,7 @@ public final class ASTArrayComprehension extends AbstractEcmascriptNode<ArrayCom
}
@Override
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}

View File

@ -12,7 +12,7 @@ public final class ASTArrayComprehensionLoop extends AbstractEcmascriptNode<Arra
}
@Override
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}

View File

@ -15,7 +15,7 @@ public final class ASTArrayLiteral extends AbstractEcmascriptNode<ArrayLiteral>
}
@Override
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}

View File

@ -12,7 +12,7 @@ public final class ASTAssignment extends AbstractInfixEcmascriptNode<Assignment>
}
@Override
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
}

View File

@ -20,7 +20,7 @@ public final class ASTAstRoot extends AbstractEcmascriptNode<AstRoot> implements
}
@Override
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}

View File

@ -12,7 +12,7 @@ public final class ASTBlock extends AbstractEcmascriptNode<Block> {
}
@Override
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
}

View File

@ -13,7 +13,7 @@ public final class ASTBreakStatement extends AbstractEcmascriptNode<BreakStateme
}
@Override
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}

View File

@ -12,7 +12,7 @@ public final class ASTCatchClause extends AbstractEcmascriptNode<CatchClause> {
}
@Override
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}

View File

@ -12,7 +12,7 @@ public final class ASTComment extends AbstractEcmascriptNode<Comment> {
}
@Override
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}

View File

@ -12,7 +12,7 @@ public final class ASTConditionalExpression extends AbstractEcmascriptNode<Condi
}
@Override
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}

View File

@ -13,7 +13,7 @@ public final class ASTContinueStatement extends AbstractEcmascriptNode<ContinueS
}
@Override
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}

View File

@ -12,7 +12,7 @@ public final class ASTDoLoop extends AbstractEcmascriptNode<DoLoop> {
}
@Override
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}

View File

@ -12,7 +12,7 @@ public final class ASTElementGet extends AbstractEcmascriptNode<ElementGet> {
}
@Override
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}

View File

@ -12,7 +12,7 @@ public final class ASTEmptyExpression extends AbstractEcmascriptNode<EmptyExpres
}
@Override
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
}

View File

@ -12,7 +12,7 @@ public final class ASTEmptyStatement extends AbstractEcmascriptNode<EmptyStateme
}
@Override
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
}

View File

@ -13,7 +13,7 @@ public final class ASTExpressionStatement extends AbstractEcmascriptNode<Express
}
@Override
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}

View File

@ -12,7 +12,7 @@ public final class ASTForInLoop extends AbstractEcmascriptNode<ForInLoop> {
}
@Override
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}

View File

@ -12,7 +12,7 @@ public final class ASTForLoop extends AbstractEcmascriptNode<ForLoop> {
}
@Override
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}

View File

@ -12,7 +12,7 @@ public final class ASTFunctionCall extends AbstractEcmascriptNode<FunctionCall>
}
@Override
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}

View File

@ -13,7 +13,7 @@ public final class ASTFunctionNode extends AbstractEcmascriptNode<FunctionNode>
}
@Override
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}

View File

@ -12,7 +12,7 @@ public final class ASTIfStatement extends AbstractEcmascriptNode<IfStatement> {
}
@Override
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}

View File

@ -12,7 +12,7 @@ public final class ASTInfixExpression extends AbstractInfixEcmascriptNode<InfixE
}
@Override
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
}

View File

@ -16,7 +16,7 @@ public final class ASTKeywordLiteral extends AbstractEcmascriptNode<KeywordLiter
}
@Override
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}

View File

@ -13,7 +13,7 @@ public final class ASTLabel extends AbstractEcmascriptNode<Label> {
}
@Override
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
}

View File

@ -12,7 +12,7 @@ public final class ASTLabeledStatement extends AbstractEcmascriptNode<LabeledSta
}
@Override
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}

View File

@ -12,7 +12,7 @@ public final class ASTLetNode extends AbstractEcmascriptNode<LetNode> {
}
@Override
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}

View File

@ -13,7 +13,7 @@ public final class ASTName extends AbstractEcmascriptNode<Name> {
}
@Override
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}

View File

@ -12,7 +12,7 @@ public final class ASTNewExpression extends AbstractEcmascriptNode<NewExpression
}
@Override
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}

View File

@ -13,7 +13,7 @@ public final class ASTNumberLiteral extends AbstractEcmascriptNode<NumberLiteral
}
@Override
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}

Some files were not shown because too many files have changed in this diff Show More