Move javascript into own sub-module

This commit is contained in:
Andreas Dangel
2014-10-04 18:23:23 +02:00
parent c859a05718
commit 2e7310a2cd
108 changed files with 141 additions and 16 deletions

View File

@ -0,0 +1,58 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.ecmascript;
import java.io.Writer;
import net.sf.saxon.sxpath.IndependentContext;
import net.sourceforge.pmd.lang.AbstractLanguageVersionHandler;
import net.sourceforge.pmd.lang.Parser;
import net.sourceforge.pmd.lang.ParserOptions;
import net.sourceforge.pmd.lang.VisitorStarter;
import net.sourceforge.pmd.lang.XPathHandler;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.ast.xpath.AbstractASTXPathHandler;
import net.sourceforge.pmd.lang.ecmascript.ast.DumpFacade;
import net.sourceforge.pmd.lang.ecmascript.ast.EcmascriptNode;
import net.sourceforge.pmd.lang.ecmascript.rule.EcmascriptRuleViolationFactory;
import net.sourceforge.pmd.lang.rule.RuleViolationFactory;
/**
* Implementation of LanguageVersionHandler for the ECMAScript Version 3.
*/
public class Ecmascript3Handler extends AbstractLanguageVersionHandler {
@Override
public XPathHandler getXPathHandler() {
return new AbstractASTXPathHandler() {
public void initialize() {
}
public void initialize(IndependentContext context) {
}
};
}
public RuleViolationFactory getRuleViolationFactory() {
return EcmascriptRuleViolationFactory.INSTANCE;
}
@Override
public ParserOptions getDefaultParserOptions() {
return new EcmascriptParserOptions();
}
public Parser getParser(ParserOptions parserOptions) {
return new Ecmascript3Parser(parserOptions);
}
@Override
public VisitorStarter getDumpFacade(final Writer writer, final String prefix, final boolean recurse) {
return new VisitorStarter() {
public void start(Node rootNode) {
new DumpFacade().initializeWith(writer, prefix, recurse, (EcmascriptNode) rootNode);
}
};
}
}

View File

@ -0,0 +1,42 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.ecmascript;
import java.io.Reader;
import java.util.Map;
import net.sourceforge.pmd.lang.AbstractParser;
import net.sourceforge.pmd.lang.ParserOptions;
import net.sourceforge.pmd.lang.TokenManager;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.ast.ParseException;
/**
* Adapter for the EcmascriptParser.
*/
public class Ecmascript3Parser extends AbstractParser {
private net.sourceforge.pmd.lang.ecmascript.ast.EcmascriptParser ecmascriptParser;
public Ecmascript3Parser(ParserOptions parserOptions) {
super(parserOptions);
ecmascriptParser = new net.sourceforge.pmd.lang.ecmascript.ast.EcmascriptParser((EcmascriptParserOptions)parserOptions);
}
@Override
public TokenManager createTokenManager(Reader source) {
return null;
}
public boolean canParse() {
return true;
}
public Node parse(String fileName, Reader source) throws ParseException {
return ecmascriptParser.parse(source);
}
public Map<Integer, String> getSuppressMap() {
return ecmascriptParser.getSuppressMap();
}
}

View File

@ -0,0 +1,19 @@
package net.sourceforge.pmd.lang.ecmascript;
import net.sourceforge.pmd.lang.BaseLanguageModule;
import net.sourceforge.pmd.lang.ecmascript.rule.EcmascriptRuleChainVisitor;
/**
* Created by christoferdutz on 20.09.14.
*/
public class EcmascriptLanguageModule extends BaseLanguageModule {
public static final String NAME = "Ecmascript";
public static final String TERSE_NAME = "ecmascript";
public EcmascriptLanguageModule() {
super(NAME, null, TERSE_NAME, EcmascriptRuleChainVisitor.class, "js");
addVersion("3", new Ecmascript3Handler(), true);
}
}

View File

@ -0,0 +1,126 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.ecmascript;
import net.sourceforge.pmd.Rule;
import net.sourceforge.pmd.lang.ParserOptions;
import net.sourceforge.pmd.lang.rule.properties.BooleanProperty;
import net.sourceforge.pmd.lang.rule.properties.EnumeratedProperty;
import net.sourceforge.pmd.util.StringUtil;
import org.mozilla.javascript.Context;
public class EcmascriptParserOptions extends ParserOptions {
public enum Version {
VERSION_DEFAULT("default", Context.VERSION_DEFAULT),
VERSION_1_0("1.0", Context.VERSION_1_0),
VERSION_1_1("1.1", Context.VERSION_1_1),
VERSION_1_2("1.2", Context.VERSION_1_2),
VERSION_1_3("1.3", Context.VERSION_1_3),
VERSION_1_4("1.4", Context.VERSION_1_4),
VERSION_1_5("1.5", Context.VERSION_1_5),
VERSION_1_6("1.6", Context.VERSION_1_6),
VERSION_1_7("1.7", Context.VERSION_1_7),
VERSION_1_8("1.8", Context.VERSION_1_8);
private final String name;
private final int version;
private Version(String name, int version) {
this.name = name;
this.version = version;
}
public String getLabel() {
return name;
}
public int getVersion() {
return version;
}
};
private static final String[] VERSION_LABELS = new String[] { Version.VERSION_DEFAULT.getLabel(),
Version.VERSION_1_0.getLabel(), Version.VERSION_1_1.getLabel(), Version.VERSION_1_2.getLabel(),
Version.VERSION_1_3.getLabel(), Version.VERSION_1_4.getLabel(), Version.VERSION_1_5.getLabel(),
Version.VERSION_1_6.getLabel(), Version.VERSION_1_7.getLabel(), Version.VERSION_1_8.getLabel(), };
// Note: The UI order values are chosen to be larger than those built into XPathRule.
public static final BooleanProperty RECORDING_COMMENTS_DESCRIPTOR = new BooleanProperty("recordingComments",
"Specifies that comments are produced in the AST.", Boolean.TRUE, 3.0f);
public static final BooleanProperty RECORDING_LOCAL_JSDOC_COMMENTS_DESCRIPTOR = new BooleanProperty(
"recordingLocalJsDocComments", "Specifies that JsDoc comments are produced in the AST.", Boolean.TRUE, 4.0f);
public static final EnumeratedProperty<Version> RHINO_LANGUAGE_VERSION = new EnumeratedProperty<Version>(
"rhinoLanguageVersion",
"Specifies the Rhino Language Version to use for parsing. Defaults to Rhino default.", VERSION_LABELS,
Version.values(), 0, 5.0f);
private boolean recordingComments;
private boolean recordingLocalJsDocComments;
private Version rhinoLanguageVersion;
public EcmascriptParserOptions() {
this.recordingComments = RECORDING_COMMENTS_DESCRIPTOR.defaultValue().booleanValue();
this.recordingLocalJsDocComments = RECORDING_LOCAL_JSDOC_COMMENTS_DESCRIPTOR.defaultValue().booleanValue();
this.rhinoLanguageVersion = (Version) RHINO_LANGUAGE_VERSION.valueFrom((String) RHINO_LANGUAGE_VERSION
.defaultValue());
}
public EcmascriptParserOptions(Rule rule) {
this.recordingComments = rule.getProperty(RECORDING_COMMENTS_DESCRIPTOR);
this.recordingLocalJsDocComments = rule.getProperty(RECORDING_LOCAL_JSDOC_COMMENTS_DESCRIPTOR);
this.rhinoLanguageVersion = (Version) RHINO_LANGUAGE_VERSION.valueFrom((String) rule
.getProperty(RHINO_LANGUAGE_VERSION));
}
public boolean isRecordingComments() {
return this.recordingComments;
}
public void setRecordingComments(boolean recordingComments) {
this.recordingComments = recordingComments;
}
public boolean isRecordingLocalJsDocComments() {
return this.recordingLocalJsDocComments;
}
public void setRecordingLocalJsDocComments(boolean recordingLocalJsDocComments) {
this.recordingLocalJsDocComments = recordingLocalJsDocComments;
}
public Version getRhinoLanguageVersion() {
return this.rhinoLanguageVersion;
}
public void setRhinoLanguageVersion(Version rhinoLanguageVersion) {
this.rhinoLanguageVersion = rhinoLanguageVersion;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + (recordingComments ? 1231 : 1237);
result = prime * result + (recordingLocalJsDocComments ? 1231 : 1237);
result = prime * result + ((rhinoLanguageVersion == null) ? 0 : rhinoLanguageVersion.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
final EcmascriptParserOptions that = (EcmascriptParserOptions) obj;
return StringUtil.isSame(this.suppressMarker, that.suppressMarker, false, false, false)
&& this.recordingComments == that.recordingComments
&& this.recordingLocalJsDocComments == that.recordingLocalJsDocComments
&& this.rhinoLanguageVersion == that.rhinoLanguageVersion;
}
}

View File

@ -0,0 +1,39 @@
/**
* 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.ArrayComprehension;
public class ASTArrayComprehension extends AbstractEcmascriptNode<ArrayComprehension> {
public ASTArrayComprehension(ArrayComprehension arrayComprehension) {
super(arrayComprehension);
}
/**
* Accept the visitor.
*/
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
public EcmascriptNode getResult() {
return (EcmascriptNode) jjtGetChild(0);
}
public int getNumArrayComprehensionLoops() {
return node.getLoops().size();
}
public ASTArrayComprehensionLoop getArrayComprehensionLoop(int index) {
return (ASTArrayComprehensionLoop) jjtGetChild(index + 1);
}
public boolean hasFilter() {
return node.getFilter() != null;
}
public EcmascriptNode getFilter() {
return (EcmascriptNode) jjtGetChild(jjtGetNumChildren() - 1);
}
}

View File

@ -0,0 +1,28 @@
/**
* 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.ArrayComprehensionLoop;
public class ASTArrayComprehensionLoop extends AbstractEcmascriptNode<ArrayComprehensionLoop> {
public ASTArrayComprehensionLoop(ArrayComprehensionLoop arrayComprehensionLoop) {
super(arrayComprehensionLoop);
}
/**
* Accept the visitor.
*/
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
public EcmascriptNode getIterator() {
return (EcmascriptNode) jjtGetChild(0);
}
public EcmascriptNode getIteratedObject() {
return (EcmascriptNode) jjtGetChild(1);
}
}

View File

@ -0,0 +1,33 @@
/**
* 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.ArrayLiteral;
public class ASTArrayLiteral extends AbstractEcmascriptNode<ArrayLiteral> implements DestructuringNode, TrailingCommaNode {
private boolean trailingComma;
public ASTArrayLiteral(ArrayLiteral arrayLiteral) {
super(arrayLiteral);
}
/**
* Accept the visitor.
*/
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
public boolean isDestructuring() {
return node.isDestructuring();
}
public boolean isTrailingComma() {
return trailingComma;
}
public void setTrailingComma(boolean trailingComma) {
this.trailingComma = trailingComma;
}
}

View File

@ -0,0 +1,20 @@
/**
* 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.Assignment;
public class ASTAssignment extends AbstractInfixEcmascriptNode<Assignment> {
public ASTAssignment(Assignment asssignment) {
super(asssignment);
}
/**
* Accept the visitor.
*/
@Override
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
}

View File

@ -0,0 +1,28 @@
/**
* 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.AstRoot;
public class ASTAstRoot extends AbstractEcmascriptNode<AstRoot> {
public ASTAstRoot(AstRoot astRoot) {
super(astRoot);
}
/**
* Accept the visitor.
*/
@Override
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
public int getNumComments() {
return node.getComments() != null ? node.getComments().size() : 0;
}
public ASTComment getComment(int index) {
return (ASTComment) jjtGetChild(jjtGetNumChildren() - 1 - getNumComments() + index);
}
}

View File

@ -0,0 +1,20 @@
/**
* 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.Block;
public class ASTBlock extends AbstractEcmascriptNode<Block> {
public ASTBlock(Block block) {
super(block);
}
/**
* Accept the visitor.
*/
@Override
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
}

View File

@ -0,0 +1,29 @@
/**
* 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.BreakStatement;
public class ASTBreakStatement extends AbstractEcmascriptNode<BreakStatement> {
public ASTBreakStatement(BreakStatement breakStatement) {
super(breakStatement);
super.setImage(breakStatement.getBreakLabel() != null ? breakStatement.getBreakLabel().getIdentifier() : null);
}
/**
* Accept the visitor.
*/
@Override
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
public boolean hasLabel() {
return node.getBreakLabel() != null;
}
public ASTName getLabel() {
return (ASTName) jjtGetChild(0);
}
}

View File

@ -0,0 +1,36 @@
/**
* 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.CatchClause;
public class ASTCatchClause extends AbstractEcmascriptNode<CatchClause> {
public ASTCatchClause(CatchClause catchClause) {
super(catchClause);
}
/**
* Accept the visitor.
*/
@Override
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
public ASTName getVariableName() {
return (ASTName) jjtGetChild(0);
}
public boolean isIf() {
return node.getCatchCondition() != null;
}
public EcmascriptNode getCatchCondition() {
return (EcmascriptNode) jjtGetChild(1);
}
public ASTBlock getBlock() {
return (ASTBlock) jjtGetChild(jjtGetNumChildren() - 1);
}
}

View File

@ -0,0 +1,24 @@
/**
* 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.Comment;
public class ASTComment extends AbstractEcmascriptNode<Comment> {
public ASTComment(Comment comment) {
super(comment);
}
/**
* Accept the visitor.
*/
@Override
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
public String getValue() {
return node.getValue();
}
}

View File

@ -0,0 +1,32 @@
/**
* 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.ConditionalExpression;
public class ASTConditionalExpression extends AbstractEcmascriptNode<ConditionalExpression> {
public ASTConditionalExpression(ConditionalExpression conditionalExpression) {
super(conditionalExpression);
}
/**
* Accept the visitor.
*/
@Override
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
public EcmascriptNode getTestExpression() {
return (EcmascriptNode) jjtGetChild(0);
}
public EcmascriptNode getTrueExpression() {
return (EcmascriptNode) jjtGetChild(1);
}
public EcmascriptNode getFalseExpression() {
return (EcmascriptNode) jjtGetChild(2);
}
}

View File

@ -0,0 +1,29 @@
/**
* 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.ContinueStatement;
public class ASTContinueStatement extends AbstractEcmascriptNode<ContinueStatement> {
public ASTContinueStatement(ContinueStatement continueStatement) {
super(continueStatement);
super.setImage(continueStatement.getLabel() != null ? continueStatement.getLabel().getIdentifier() : null);
}
/**
* Accept the visitor.
*/
@Override
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
public boolean hasLabel() {
return node.getLabel() != null;
}
public ASTName getLabel() {
return (ASTName) jjtGetChild(0);
}
}

View File

@ -0,0 +1,28 @@
/**
* 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.DoLoop;
public class ASTDoLoop extends AbstractEcmascriptNode<DoLoop> {
public ASTDoLoop(DoLoop doLoop) {
super(doLoop);
}
/**
* Accept the visitor.
*/
@Override
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
public EcmascriptNode getBody() {
return (EcmascriptNode) jjtGetChild(0);
}
public EcmascriptNode getCondition() {
return (EcmascriptNode) jjtGetChild(1);
}
}

View File

@ -0,0 +1,34 @@
/**
* 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.ElementGet;
public class ASTElementGet extends AbstractEcmascriptNode<ElementGet> {
public ASTElementGet(ElementGet elementGet) {
super(elementGet);
}
/**
* Accept the visitor.
*/
@Override
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
public EcmascriptNode getTarget() {
if (jjtGetNumChildren() > 0) {
return (EcmascriptNode)jjtGetChild(0);
}
return null;
}
public EcmascriptNode getElement() {
if (jjtGetNumChildren() > 1) {
return (EcmascriptNode)jjtGetChild(1);
}
return null;
}
}

View File

@ -0,0 +1,20 @@
/**
* 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.EmptyExpression;
public class ASTEmptyExpression extends AbstractEcmascriptNode<EmptyExpression> {
public ASTEmptyExpression(EmptyExpression emptyExpression) {
super(emptyExpression);
}
/**
* Accept the visitor.
*/
@Override
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
}

View File

@ -0,0 +1,25 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.ecmascript.ast;
import org.mozilla.javascript.Token;
import org.mozilla.javascript.ast.ExpressionStatement;
public class ASTExpressionStatement extends AbstractEcmascriptNode<ExpressionStatement> {
public ASTExpressionStatement(ExpressionStatement expressionStatement) {
super(expressionStatement);
}
/**
* Accept the visitor.
*/
@Override
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
public boolean hasResult() {
return node.getType() == Token.EXPR_RESULT;
}
}

View File

@ -0,0 +1,35 @@
/**
* 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.ForInLoop;
public class ASTForInLoop extends AbstractEcmascriptNode<ForInLoop> {
public ASTForInLoop(ForInLoop forInLoop) {
super(forInLoop);
}
/**
* Accept the visitor.
*/
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
public EcmascriptNode getIterator() {
return (EcmascriptNode) jjtGetChild(0);
}
public EcmascriptNode getIteratedObject() {
return (EcmascriptNode) jjtGetChild(1);
}
public EcmascriptNode getBody() {
return (EcmascriptNode) jjtGetChild(2);
}
public boolean isForEach() {
return node.isForEach();
}
}

View File

@ -0,0 +1,35 @@
/**
* 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.ForLoop;
public class ASTForLoop extends AbstractEcmascriptNode<ForLoop> {
public ASTForLoop(ForLoop forLoop) {
super(forLoop);
}
/**
* Accept the visitor.
*/
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
public EcmascriptNode getInitializer() {
return (EcmascriptNode) jjtGetChild(0);
}
public EcmascriptNode getCondition() {
return (EcmascriptNode) jjtGetChild(1);
}
public EcmascriptNode getIncrement() {
return (EcmascriptNode) jjtGetChild(2);
}
public EcmascriptNode getBody() {
return (EcmascriptNode) jjtGetChild(3);
}
}

View File

@ -0,0 +1,35 @@
/**
* 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;
public class ASTFunctionCall extends AbstractEcmascriptNode<FunctionCall> {
public ASTFunctionCall(FunctionCall functionCall) {
super(functionCall);
}
/**
* Accept the visitor.
*/
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
public EcmascriptNode getTarget() {
return (EcmascriptNode) jjtGetChild(0);
}
public int getNumArguments() {
return node.getArguments().size();
}
public EcmascriptNode getArgument(int index) {
return (EcmascriptNode) jjtGetChild(index + 1);
}
public boolean hasArguments() {
return getNumArguments() != 0;
}
}

View File

@ -0,0 +1,63 @@
/**
* 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.FunctionNode;
public class ASTFunctionNode extends AbstractEcmascriptNode<FunctionNode> {
public ASTFunctionNode(FunctionNode functionNode) {
super(functionNode);
super.setImage(functionNode.getName());
}
/**
* Accept the visitor.
*/
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
public int getNumParams() {
return node.getParams().size();
}
public ASTName getFunctionName() {
if (node.getFunctionName() != null) {
return (ASTName) jjtGetChild(0);
}
return null;
}
public EcmascriptNode getParam(int index) {
if (node.getFunctionName() != null) {
index++;
}
return (EcmascriptNode) jjtGetChild(index);
}
public EcmascriptNode getBody() {
return (EcmascriptNode) jjtGetChild(jjtGetNumChildren() - 1);
}
@Deprecated // use getBody() instead
public EcmascriptNode getBody(int index) {
return getBody();
}
public boolean isClosure() {
return node.isExpressionClosure();
}
public boolean isGetter() {
return node.isGetter();
}
public boolean isSetter() {
return node.isSetter();
}
public boolean isGetterOrSetter() {
return node.isGetterOrSetter();
}
}

View File

@ -0,0 +1,35 @@
/**
* 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.IfStatement;
public class ASTIfStatement extends AbstractEcmascriptNode<IfStatement> {
public ASTIfStatement(IfStatement ifStatement) {
super(ifStatement);
}
/**
* Accept the visitor.
*/
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
public boolean hasElse() {
return node.getElsePart() != null;
}
public EcmascriptNode getCondition() {
return (EcmascriptNode) jjtGetChild(0);
}
public EcmascriptNode getThen() {
return (EcmascriptNode) jjtGetChild(1);
}
public EcmascriptNode getElse() {
return (EcmascriptNode) jjtGetChild(2);
}
}

View File

@ -0,0 +1,19 @@
/**
* 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.InfixExpression;
public class ASTInfixExpression extends AbstractInfixEcmascriptNode<InfixExpression> {
public ASTInfixExpression(InfixExpression infixExpression) {
super(infixExpression);
}
/**
* Accept the visitor.
*/
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
}

View File

@ -0,0 +1,38 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.ecmascript.ast;
import org.mozilla.javascript.Token;
import org.mozilla.javascript.ast.KeywordLiteral;
public class ASTKeywordLiteral extends AbstractEcmascriptNode<KeywordLiteral> {
public ASTKeywordLiteral(KeywordLiteral keywordLiteral) {
super(keywordLiteral);
super.setImage(Token.typeToName(keywordLiteral.getType()).toLowerCase());
}
/**
* Accept the visitor.
*/
@Override
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
public boolean isBoolean() {
return node.isBooleanLiteral();
}
public boolean isThis() {
return node.getType() == Token.THIS;
}
public boolean isNull() {
return node.getType() == Token.NULL;
}
public boolean isDebugger() {
return node.getType() == Token.DEBUGGER;
}
}

View File

@ -0,0 +1,20 @@
/**
* 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.Label;
public class ASTLabel extends AbstractEcmascriptNode<Label> {
public ASTLabel(Label label) {
super(label);
super.setImage(label.getName());
}
/**
* Accept the visitor.
*/
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
}

View File

@ -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.LabeledStatement;
public class ASTLabeledStatement extends AbstractEcmascriptNode<LabeledStatement> {
public ASTLabeledStatement(LabeledStatement labeledStatement) {
super(labeledStatement);
}
/**
* Accept the visitor.
*/
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
public int getNumLabels() {
return node.getLabels().size();
}
public ASTLabel getLabel(int index) {
return (ASTLabel) jjtGetChild(index);
}
public EcmascriptNode getStatement() {
return (EcmascriptNode) jjtGetChild(jjtGetNumChildren() - 1);
}
}

View File

@ -0,0 +1,35 @@
/**
* 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.LetNode;
public class ASTLetNode extends AbstractEcmascriptNode<LetNode> {
public ASTLetNode(LetNode letNode) {
super(letNode);
}
/**
* Accept the visitor.
*/
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
public ASTVariableDeclaration getVariables() {
return (ASTVariableDeclaration) jjtGetChild(0);
}
public boolean hasBody() {
return node.getBody() != null;
}
public EcmascriptNode getBody() {
if (hasBody()) {
return (EcmascriptNode) jjtGetChild(jjtGetNumChildren() - 1);
} else {
return null;
}
}
}

View File

@ -0,0 +1,79 @@
/**
* 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.Name;
public class ASTName extends AbstractEcmascriptNode<Name> {
public ASTName(Name name) {
super(name);
super.setImage(name.getIdentifier());
}
/**
* Accept the visitor.
*/
@Override
public Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
public String getIdentifier() {
return node.getIdentifier();
}
public boolean isLocalName() {
return node.isLocalName();
}
public boolean isGlobalName() {
return !node.isLocalName();
}
/**
* Returns whether this name node is the name of a function declaration.
* @return <code>true</code> if name of a function declaration,
* <code>false</code> otherwise.
*/
public boolean isFunctionNodeName() {
return jjtGetParent() instanceof ASTFunctionNode
&& ((ASTFunctionNode) jjtGetParent()).getFunctionName() == this;
}
/**
* Returns whether this name node is the name of a function declaration parameter.
* @return <code>true</code> if name of a function declaration parameter,
* <code>false</code> otherwise.
*/
public boolean isFunctionNodeParameter() {
if (jjtGetParent() instanceof ASTFunctionNode) {
ASTFunctionNode functionNode = (ASTFunctionNode) jjtGetParent();
for (int i = 0; i < functionNode.getNumParams(); i++) {
if (functionNode.getParam(i) == this) {
return true;
}
}
}
return false;
}
/**
* Returns whether this name node is the name of a function call.
* @return <code>true</code> if name of a function call,
* <code>false</code> otherwise.
*/
public boolean isFunctionCallName() {
return jjtGetParent() instanceof ASTFunctionCall && ((ASTFunctionCall) jjtGetParent()).getTarget() == this;
}
/**
* Returns whether this name node is the name of a variable declaration.
* @return <code>true</code> if name of a variable declaration,
* <code>false</code> otherwise.
*/
public boolean isVariableDeclaration() {
return jjtGetParent() instanceof ASTVariableInitializer
&& ((ASTVariableInitializer) jjtGetParent()).getTarget() == this;
}
}

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