forked from phoedos/pmd
Fix code duplications
This commit is contained in:
@ -8,7 +8,7 @@ import org.mozilla.javascript.ast.FunctionCall;
|
||||
|
||||
import net.sourceforge.pmd.annotation.InternalApi;
|
||||
|
||||
public class ASTFunctionCall extends AbstractEcmascriptNode<FunctionCall> {
|
||||
public class ASTFunctionCall extends AbstractFunctionCallNode<FunctionCall> {
|
||||
@Deprecated
|
||||
@InternalApi
|
||||
public ASTFunctionCall(FunctionCall functionCall) {
|
||||
@ -19,20 +19,4 @@ public class ASTFunctionCall extends AbstractEcmascriptNode<FunctionCall> {
|
||||
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
|
||||
public EcmascriptNode<?> getTarget() {
|
||||
return (EcmascriptNode<?>) getChild(0);
|
||||
}
|
||||
|
||||
public int getNumArguments() {
|
||||
return node.getArguments().size();
|
||||
}
|
||||
|
||||
public EcmascriptNode<?> getArgument(int index) {
|
||||
return (EcmascriptNode<?>) getChild(index + 1);
|
||||
}
|
||||
|
||||
public boolean hasArguments() {
|
||||
return getNumArguments() != 0;
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import org.mozilla.javascript.ast.NewExpression;
|
||||
|
||||
import net.sourceforge.pmd.annotation.InternalApi;
|
||||
|
||||
public class ASTNewExpression extends AbstractEcmascriptNode<NewExpression> {
|
||||
public class ASTNewExpression extends AbstractFunctionCallNode<NewExpression> {
|
||||
@Deprecated
|
||||
@InternalApi
|
||||
public ASTNewExpression(NewExpression newExpression) {
|
||||
@ -20,22 +20,6 @@ public class ASTNewExpression extends AbstractEcmascriptNode<NewExpression> {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
|
||||
public EcmascriptNode<?> getTarget() {
|
||||
return (EcmascriptNode<?>) getChild(0);
|
||||
}
|
||||
|
||||
public int getNumArguments() {
|
||||
return node.getArguments().size();
|
||||
}
|
||||
|
||||
public EcmascriptNode<?> getArgument(int index) {
|
||||
return (EcmascriptNode<?>) getChild(index + 1);
|
||||
}
|
||||
|
||||
public boolean hasArguments() {
|
||||
return getNumArguments() != 0;
|
||||
}
|
||||
|
||||
public boolean hasInitializer() {
|
||||
return node.getInitializer() != null;
|
||||
}
|
||||
|
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.lang.ecmascript.ast;
|
||||
|
||||
import org.mozilla.javascript.ast.FunctionCall;
|
||||
|
||||
class AbstractFunctionCallNode<T extends FunctionCall> extends AbstractEcmascriptNode<T> {
|
||||
|
||||
AbstractFunctionCallNode(T node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
public EcmascriptNode<?> getTarget() {
|
||||
return (EcmascriptNode<?>) getChild(0);
|
||||
}
|
||||
|
||||
public int getNumArguments() {
|
||||
return node.getArguments().size();
|
||||
}
|
||||
|
||||
public EcmascriptNode<?> getArgument(int index) {
|
||||
return (EcmascriptNode<?>) getChild(index + 1);
|
||||
}
|
||||
|
||||
public boolean hasArguments() {
|
||||
return getNumArguments() != 0;
|
||||
}
|
||||
|
||||
}
|
@ -103,11 +103,11 @@ public abstract class AbstractEcmascriptRule extends AbstractRule
|
||||
}
|
||||
|
||||
//
|
||||
// The following APIs are identical to those in
|
||||
// EcmascriptParserVisitorAdapter.
|
||||
// Due to Java single inheritance, it preferred to extend from the more
|
||||
// The following APIs are identical to those in EcmascriptParserVisitorAdapter.
|
||||
// Due to Java single inheritance, it is preferred to extend from the more
|
||||
// complex Rule base class instead of from relatively simple Visitor.
|
||||
//
|
||||
// CPD-OFF
|
||||
|
||||
@Override
|
||||
public Object visit(EcmascriptNode<?> node, Object data) {
|
||||
@ -359,4 +359,6 @@ public abstract class AbstractEcmascriptRule extends AbstractRule
|
||||
public Object visit(ASTXmlString node, Object data) {
|
||||
return visit((EcmascriptNode<?>) node, data);
|
||||
}
|
||||
|
||||
// CPD-ON
|
||||
}
|
||||
|
Reference in New Issue
Block a user