repo stringlengths 1 191 ⌀ | file stringlengths 23 351 | code stringlengths 0 5.32M | file_length int64 0 5.32M | avg_line_length float64 0 2.9k | max_line_length int64 0 288k | extension_type stringclasses 1 value |
|---|---|---|---|---|---|---|
pmd | pmd-master/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/rule/bestpractices/AvoidWithStatementTest.java | /**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.ecmascript.rule.bestpractices;
import net.sourceforge.pmd.testframework.PmdRuleTst;
class AvoidWithStatementTest extends PmdRuleTst {
// no additional unit tests
}
| 292 | 23.416667 | 79 | java |
pmd | pmd-master/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/rule/bestpractices/UseBaseWithParseIntTest.java | /**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.ecmascript.rule.bestpractices;
import net.sourceforge.pmd.testframework.PmdRuleTst;
class UseBaseWithParseIntTest extends PmdRuleTst {
// no additional unit tests
}
| 293 | 23.5 | 79 | java |
pmd | pmd-master/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/rule/bestpractices/ScopeForInVariableTest.java | /**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.ecmascript.rule.bestpractices;
import net.sourceforge.pmd.testframework.PmdRuleTst;
class ScopeForInVariableTest extends PmdRuleTst {
// no additional unit tests
}
| 292 | 23.416667 | 79 | java |
pmd | pmd-master/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/rule/bestpractices/GlobalVariableTest.java | /**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.ecmascript.rule.bestpractices;
import net.sourceforge.pmd.testframework.PmdRuleTst;
class GlobalVariableTest extends PmdRuleTst {
// no additional unit tests
}
| 288 | 23.083333 | 79 | java |
pmd | pmd-master/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/rule/codestyle/IfElseStmtsMustUseBracesTest.java | /**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.ecmascript.rule.codestyle;
import net.sourceforge.pmd.testframework.PmdRuleTst;
class IfElseStmtsMustUseBracesTest extends PmdRuleTst {
// no additional unit tests
}
| 294 | 23.583333 | 79 | java |
pmd | pmd-master/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/rule/codestyle/UnnecessaryParenthesesTest.java | /**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.ecmascript.rule.codestyle;
import net.sourceforge.pmd.testframework.PmdRuleTst;
class UnnecessaryParenthesesTest extends PmdRuleTst {
// no additional unit tests
}
| 292 | 23.416667 | 79 | java |
pmd | pmd-master/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/rule/codestyle/IfStmtsMustUseBracesTest.java | /**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.ecmascript.rule.codestyle;
import net.sourceforge.pmd.testframework.PmdRuleTst;
class IfStmtsMustUseBracesTest extends PmdRuleTst {
// no additional unit tests
}
| 290 | 23.25 | 79 | java |
pmd | pmd-master/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/rule/codestyle/AssignmentInOperandTest.java | /**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.ecmascript.rule.codestyle;
import net.sourceforge.pmd.testframework.PmdRuleTst;
class AssignmentInOperandTest extends PmdRuleTst {
// no additional unit tests
}
| 289 | 23.166667 | 79 | java |
pmd | pmd-master/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/rule/codestyle/NoElseReturnTest.java | /**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.ecmascript.rule.codestyle;
import net.sourceforge.pmd.testframework.PmdRuleTst;
class NoElseReturnTest extends PmdRuleTst {
// no additional unit tests
}
| 282 | 22.583333 | 79 | java |
pmd | pmd-master/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/rule/codestyle/UnnecessaryBlockTest.java | /**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.ecmascript.rule.codestyle;
import net.sourceforge.pmd.testframework.PmdRuleTst;
class UnnecessaryBlockTest extends PmdRuleTst {
// no additional unit tests
}
| 286 | 22.916667 | 79 | java |
pmd | pmd-master/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/rule/codestyle/UnreachableCodeTest.java | /**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.ecmascript.rule.codestyle;
import net.sourceforge.pmd.testframework.PmdRuleTst;
class UnreachableCodeTest extends PmdRuleTst {
// no additional unit tests
}
| 285 | 22.833333 | 79 | java |
pmd | pmd-master/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/rule/codestyle/WhileLoopsMustUseBracesTest.java | /**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.ecmascript.rule.codestyle;
import net.sourceforge.pmd.testframework.PmdRuleTst;
class WhileLoopsMustUseBracesTest extends PmdRuleTst {
// no additional unit tests
}
| 293 | 23.5 | 79 | java |
pmd | pmd-master/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/rule/codestyle/ForLoopsMustUseBracesTest.java | /**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.ecmascript.rule.codestyle;
import net.sourceforge.pmd.testframework.PmdRuleTst;
class ForLoopsMustUseBracesTest extends PmdRuleTst {
// no additional unit tests
}
| 291 | 23.333333 | 79 | java |
pmd | pmd-master/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/typescript/cpd/TypeScriptTokenizerTest.java | /**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.typescript.cpd;
import java.util.Properties;
import org.junit.jupiter.api.Test;
import net.sourceforge.pmd.cpd.Tokenizer;
import net.sourceforge.pmd.cpd.test.CpdTextComparisonTest;
class TypeScriptTokenizerTest extends CpdTextComparisonTest {
TypeScriptTokenizerTest() {
super(".ts");
}
@Override
public Tokenizer newTokenizer(Properties properties) {
return new TypeScriptTokenizer();
}
@Override
protected String getResourcePrefix() {
return "../cpd/testdata";
}
@Test
void greeterTest() {
doTest("greeter");
}
@Test
void apiSampleWatchTest() {
doTest("APISample_Watch");
}
}
| 805 | 19.15 | 79 | java |
pmd | pmd-master/pmd-javascript/src/test/java/net/sourceforge/pmd/cpd/AnyTokenizerForTypescriptTest.java | /*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.cpd;
import java.util.Properties;
import org.junit.jupiter.api.Test;
import net.sourceforge.pmd.cpd.test.CpdTextComparisonTest;
/**
*
*/
class AnyTokenizerForTypescriptTest extends CpdTextComparisonTest {
AnyTokenizerForTypescriptTest() {
super(".ts");
}
@Override
protected String getResourcePrefix() {
return "testdata/ts";
}
@Override
public Tokenizer newTokenizer(Properties properties) {
return new AnyTokenizer();
}
@Test
void testFile1() {
doTest("SampleTypeScript");
}
}
| 682 | 16.973684 | 79 | java |
pmd | pmd-master/pmd-javascript/src/test/java/net/sourceforge/pmd/cpd/EcmascriptTokenizerTest.java | /**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.cpd;
import java.util.Properties;
import org.junit.jupiter.api.Test;
import net.sourceforge.pmd.cpd.test.CpdTextComparisonTest;
class EcmascriptTokenizerTest extends CpdTextComparisonTest {
EcmascriptTokenizerTest() {
super(".js");
}
@Override
public Tokenizer newTokenizer(Properties properties) {
return new EcmascriptTokenizer();
}
@Override
protected String getResourcePrefix() {
return "../lang/ecmascript/cpd/testdata";
}
@Test
void testSimple() {
doTest("simple");
}
@Test
void testSimplewithSemis() {
doTest("simpleWithSemis");
}
@Test
void testIgnoreBetweenSpecialComments() {
doTest("specialComments");
}
/**
* See: https://sourceforge.net/p/pmd/bugs/1239/
*/
@Test
void parseStringNotAsMultiline() {
doTest("lineContinuations");
}
@Test
void testIgnoreSingleLineComments() {
doTest("singleLineCommentIgnore");
}
@Test
void testIgnoreMultiLineComments() {
doTest("multilineCommentIgnore");
}
@Test
void testTemplateStrings() {
doTest("templateStrings");
}
@Test
void testTabWidth() {
doTest("tabWidth");
}
}
| 1,380 | 18.180556 | 79 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/EcmascriptLanguageModule.java | /**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.ecmascript;
import static net.sourceforge.pmd.util.CollectionUtil.listOf;
import java.util.List;
import net.sourceforge.pmd.annotation.InternalApi;
import net.sourceforge.pmd.lang.Language;
import net.sourceforge.pmd.lang.LanguageRegistry;
import net.sourceforge.pmd.lang.ecmascript.ast.EcmascriptParser;
import net.sourceforge.pmd.lang.impl.SimpleLanguageModuleBase;
/**
* Created by christoferdutz on 20.09.14.
*/
public class EcmascriptLanguageModule extends SimpleLanguageModuleBase {
public static final String NAME = "JavaScript";
public static final String TERSE_NAME = "ecmascript";
@InternalApi
public static final List<String> EXTENSIONS = listOf("js");
public EcmascriptLanguageModule() {
super(LanguageMetadata.withId(TERSE_NAME).name(NAME).extensions(EXTENSIONS)
.addVersion("3")
.addVersion("5")
.addVersion("6", "ES6", "ES2015")
.addVersion("7", "ES2016")
.addVersion("8", "ES2017")
.addDefaultVersion("9", "ES2018"),
properties -> () -> new EcmascriptParser(properties));
}
public static Language getInstance() {
return LanguageRegistry.PMD.getLanguageByFullName(NAME);
}
}
| 1,463 | 33.857143 | 83 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTUpdateExpression.java | /*
* 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.AstNode;
import org.mozilla.javascript.ast.AstRoot;
import org.mozilla.javascript.ast.UpdateExpression;
public final class ASTUpdateExpression extends AbstractEcmascriptNode<UpdateExpression> {
ASTUpdateExpression(UpdateExpression updateExpression) {
super(updateExpression);
super.setImage(AstRoot.operatorToString(updateExpression.getOperator()));
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
public String getOperator() {
return AstNode.operatorToString(node.getOperator());
}
public boolean isPostfix() {
return node.isPostfix();
}
public boolean isPrefix() {
return node.isPrefix();
}
}
| 961 | 26.485714 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTThrowStatement.java | /*
* 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.ThrowStatement;
public final class ASTThrowStatement extends AbstractEcmascriptNode<ThrowStatement> {
ASTThrowStatement(ThrowStatement throwStatement) {
super(throwStatement);
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
}
| 532 | 27.052632 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTParenthesizedExpression.java | /*
* 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.ParenthesizedExpression;
public final class ASTParenthesizedExpression extends AbstractEcmascriptNode<ParenthesizedExpression> {
ASTParenthesizedExpression(ParenthesizedExpression parenthesizedExpression) {
super(parenthesizedExpression);
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
}
| 595 | 30.368421 | 103 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTContinueStatement.java | /*
* 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 final class ASTContinueStatement extends AbstractEcmascriptNode<ContinueStatement> {
ASTContinueStatement(ContinueStatement continueStatement) {
super(continueStatement);
super.setImage(continueStatement.getLabel() != null ? continueStatement.getLabel().getIdentifier() : null);
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
public boolean hasLabel() {
return node.getLabel() != null;
}
public ASTName getLabel() {
return (ASTName) getChild(0);
}
}
| 825 | 28.5 | 115 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTForLoop.java | /*
* 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 final class ASTForLoop extends AbstractEcmascriptNode<ForLoop> {
ASTForLoop(ForLoop forLoop) {
super(forLoop);
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
public EcmascriptNode<?> getInitializer() {
return (EcmascriptNode<?>) getChild(0);
}
public EcmascriptNode<?> getCondition() {
return (EcmascriptNode<?>) getChild(1);
}
public EcmascriptNode<?> getIncrement() {
return (EcmascriptNode<?>) getChild(2);
}
public EcmascriptNode<?> getBody() {
return (EcmascriptNode<?>) getChild(3);
}
}
| 884 | 24.285714 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTArrayLiteral.java | /*
* 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 final class ASTArrayLiteral extends AbstractEcmascriptNode<ArrayLiteral>
implements DestructuringNode, TrailingCommaNode {
private boolean trailingComma;
ASTArrayLiteral(ArrayLiteral arrayLiteral) {
super(arrayLiteral);
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
@Override
public boolean isDestructuring() {
return node.isDestructuring();
}
@Override
public boolean isTrailingComma() {
return trailingComma;
}
@Override
protected void setTrailingCommaExists(boolean b) {
this.trailingComma = b;
}
}
| 907 | 23.540541 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTXmlDotQuery.java | /*
* 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.XmlDotQuery;
public final class ASTXmlDotQuery extends AbstractInfixEcmascriptNode<XmlDotQuery> {
ASTXmlDotQuery(XmlDotQuery xmlDotQuery) {
super(xmlDotQuery);
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
}
| 516 | 26.210526 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/TrailingCommaNode.java | /*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.ecmascript.ast;
public interface TrailingCommaNode {
boolean isTrailingComma();
}
| 209 | 18.090909 | 79 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTName.java | /*
* 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 final class ASTName extends AbstractEcmascriptNode<Name> {
ASTName(Name name) {
super(name);
super.setImage(name.getIdentifier());
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P 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 getParent() instanceof ASTFunctionNode
&& ((ASTFunctionNode) getParent()).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 (getParent() instanceof ASTFunctionNode) {
ASTFunctionNode functionNode = (ASTFunctionNode) getParent();
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 getParent() instanceof ASTFunctionCall && ((ASTFunctionCall) getParent()).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 getParent() instanceof ASTVariableInitializer
&& ((ASTVariableInitializer) getParent()).getTarget() == this;
}
}
| 2,544 | 29.662651 | 109 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTGeneratorExpressionLoop.java | /*
* 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.GeneratorExpressionLoop;
public final class ASTGeneratorExpressionLoop extends AbstractEcmascriptNode<GeneratorExpressionLoop> {
ASTGeneratorExpressionLoop(GeneratorExpressionLoop generatorExpressionLoop) {
super(generatorExpressionLoop);
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
}
| 596 | 28.85 | 103 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTYield.java | /*
* 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.Yield;
public final class ASTYield extends AbstractEcmascriptNode<Yield> {
ASTYield(Yield yield) {
super(yield);
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
}
| 470 | 22.55 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTBreakStatement.java | /*
* 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 final class ASTBreakStatement extends AbstractEcmascriptNode<BreakStatement> {
ASTBreakStatement(BreakStatement breakStatement) {
super(breakStatement);
super.setImage(breakStatement.getBreakLabel() != null ? breakStatement.getBreakLabel().getIdentifier() : null);
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
public boolean hasLabel() {
return node.getBreakLabel() != null;
}
public ASTName getLabel() {
return (ASTName) getChild(0);
}
}
| 813 | 28.071429 | 119 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTObjectLiteral.java | /*
* 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.ObjectLiteral;
public final class ASTObjectLiteral extends AbstractEcmascriptNode<ObjectLiteral>
implements DestructuringNode, TrailingCommaNode {
private boolean trailingComma;
ASTObjectLiteral(ObjectLiteral objectLiteral) {
super(objectLiteral);
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
public ASTObjectProperty getObjectProperty(int index) {
return (ASTObjectProperty) getChild(index);
}
@Override
public boolean isDestructuring() {
return node.isDestructuring();
}
@Override
public boolean isTrailingComma() {
return trailingComma;
}
@Override
protected void setTrailingCommaExists(boolean b) {
this.trailingComma = b;
}
}
| 1,033 | 24.219512 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTTemplateCharacters.java | /*
* 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.TemplateCharacters;
public final class ASTTemplateCharacters extends AbstractEcmascriptNode<TemplateCharacters> {
ASTTemplateCharacters(TemplateCharacters templateCharacters) {
super(templateCharacters);
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
public String getValue() {
return node.getValue();
}
}
| 631 | 25.333333 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTReturnStatement.java | /*
* 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.ReturnStatement;
public final class ASTReturnStatement extends AbstractEcmascriptNode<ReturnStatement> {
ASTReturnStatement(ReturnStatement returnStatement) {
super(returnStatement);
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
public boolean hasResult() {
return node.getReturnValue() != null;
}
}
| 625 | 26.217391 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTDoLoop.java | /*
* 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 final class ASTDoLoop extends AbstractEcmascriptNode<DoLoop> {
ASTDoLoop(DoLoop doLoop) {
super(doLoop);
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
public EcmascriptNode<?> getBody() {
return (EcmascriptNode<?>) getChild(0);
}
public EcmascriptNode<?> getCondition() {
return (EcmascriptNode<?>) getChild(1);
}
}
| 673 | 23.962963 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/EcmascriptTreeBuilder.java | /*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.ecmascript.ast;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.mozilla.javascript.ScriptRuntime;
import org.mozilla.javascript.ast.ArrayComprehension;
import org.mozilla.javascript.ast.ArrayComprehensionLoop;
import org.mozilla.javascript.ast.ArrayLiteral;
import org.mozilla.javascript.ast.Assignment;
import org.mozilla.javascript.ast.AstNode;
import org.mozilla.javascript.ast.AstRoot;
import org.mozilla.javascript.ast.BigIntLiteral;
import org.mozilla.javascript.ast.Block;
import org.mozilla.javascript.ast.BreakStatement;
import org.mozilla.javascript.ast.CatchClause;
import org.mozilla.javascript.ast.Comment;
import org.mozilla.javascript.ast.ConditionalExpression;
import org.mozilla.javascript.ast.ContinueStatement;
import org.mozilla.javascript.ast.DoLoop;
import org.mozilla.javascript.ast.ElementGet;
import org.mozilla.javascript.ast.EmptyExpression;
import org.mozilla.javascript.ast.EmptyStatement;
import org.mozilla.javascript.ast.ErrorNode;
import org.mozilla.javascript.ast.ExpressionStatement;
import org.mozilla.javascript.ast.ForInLoop;
import org.mozilla.javascript.ast.ForLoop;
import org.mozilla.javascript.ast.FunctionCall;
import org.mozilla.javascript.ast.FunctionNode;
import org.mozilla.javascript.ast.GeneratorExpression;
import org.mozilla.javascript.ast.GeneratorExpressionLoop;
import org.mozilla.javascript.ast.IfStatement;
import org.mozilla.javascript.ast.InfixExpression;
import org.mozilla.javascript.ast.KeywordLiteral;
import org.mozilla.javascript.ast.Label;
import org.mozilla.javascript.ast.LabeledStatement;
import org.mozilla.javascript.ast.LetNode;
import org.mozilla.javascript.ast.Name;
import org.mozilla.javascript.ast.NewExpression;
import org.mozilla.javascript.ast.NodeVisitor;
import org.mozilla.javascript.ast.NumberLiteral;
import org.mozilla.javascript.ast.ObjectLiteral;
import org.mozilla.javascript.ast.ObjectProperty;
import org.mozilla.javascript.ast.ParenthesizedExpression;
import org.mozilla.javascript.ast.ParseProblem;
import org.mozilla.javascript.ast.PropertyGet;
import org.mozilla.javascript.ast.RegExpLiteral;
import org.mozilla.javascript.ast.ReturnStatement;
import org.mozilla.javascript.ast.Scope;
import org.mozilla.javascript.ast.ScriptNode;
import org.mozilla.javascript.ast.StringLiteral;
import org.mozilla.javascript.ast.SwitchCase;
import org.mozilla.javascript.ast.SwitchStatement;
import org.mozilla.javascript.ast.TaggedTemplateLiteral;
import org.mozilla.javascript.ast.TemplateCharacters;
import org.mozilla.javascript.ast.TemplateLiteral;
import org.mozilla.javascript.ast.ThrowStatement;
import org.mozilla.javascript.ast.TryStatement;
import org.mozilla.javascript.ast.UnaryExpression;
import org.mozilla.javascript.ast.UpdateExpression;
import org.mozilla.javascript.ast.VariableDeclaration;
import org.mozilla.javascript.ast.VariableInitializer;
import org.mozilla.javascript.ast.WhileLoop;
import org.mozilla.javascript.ast.WithStatement;
import org.mozilla.javascript.ast.XmlDotQuery;
import org.mozilla.javascript.ast.XmlElemRef;
import org.mozilla.javascript.ast.XmlExpression;
import org.mozilla.javascript.ast.XmlLiteral;
import org.mozilla.javascript.ast.XmlMemberGet;
import org.mozilla.javascript.ast.XmlPropRef;
import org.mozilla.javascript.ast.XmlString;
import org.mozilla.javascript.ast.Yield;
final class EcmascriptTreeBuilder implements NodeVisitor {
private static final Map<Class<? extends AstNode>, Constructor<? extends AbstractEcmascriptNode<?>>> NODE_TYPE_TO_NODE_ADAPTER_TYPE = new HashMap<>();
static {
register(ArrayComprehension.class, ASTArrayComprehension.class);
register(ArrayComprehensionLoop.class, ASTArrayComprehensionLoop.class);
register(ArrayLiteral.class, ASTArrayLiteral.class);
register(Assignment.class, ASTAssignment.class);
register(AstRoot.class, ASTAstRoot.class);
register(BigIntLiteral.class, ASTBigIntLiteral.class);
register(Block.class, ASTBlock.class);
register(BreakStatement.class, ASTBreakStatement.class);
register(CatchClause.class, ASTCatchClause.class);
register(Comment.class, ASTComment.class);
register(ConditionalExpression.class, ASTConditionalExpression.class);
register(ContinueStatement.class, ASTContinueStatement.class);
register(DoLoop.class, ASTDoLoop.class);
register(ElementGet.class, ASTElementGet.class);
register(EmptyExpression.class, ASTEmptyExpression.class);
register(EmptyStatement.class, ASTEmptyStatement.class);
register(ErrorNode.class, ASTErrorNode.class);
register(ExpressionStatement.class, ASTExpressionStatement.class);
register(ForInLoop.class, ASTForInLoop.class);
register(ForLoop.class, ASTForLoop.class);
register(FunctionCall.class, ASTFunctionCall.class);
register(FunctionNode.class, ASTFunctionNode.class);
register(GeneratorExpression.class, ASTGeneratorExpression.class);
register(GeneratorExpressionLoop.class, ASTGeneratorExpressionLoop.class);
register(IfStatement.class, ASTIfStatement.class);
register(InfixExpression.class, ASTInfixExpression.class);
// - not a real node - register(Jump.class, ASTJump.class);
register(KeywordLiteral.class, ASTKeywordLiteral.class);
register(Label.class, ASTLabel.class);
register(LabeledStatement.class, ASTLabeledStatement.class);
register(LetNode.class, ASTLetNode.class);
register(Name.class, ASTName.class);
register(NewExpression.class, ASTNewExpression.class);
register(NumberLiteral.class, ASTNumberLiteral.class);
register(ObjectLiteral.class, ASTObjectLiteral.class);
register(ObjectProperty.class, ASTObjectProperty.class);
register(ParenthesizedExpression.class, ASTParenthesizedExpression.class);
register(PropertyGet.class, ASTPropertyGet.class);
register(RegExpLiteral.class, ASTRegExpLiteral.class);
register(ReturnStatement.class, ASTReturnStatement.class);
register(Scope.class, ASTScope.class);
register(ScriptNode.class, ASTScriptNode.class);
register(StringLiteral.class, ASTStringLiteral.class);
register(SwitchCase.class, ASTSwitchCase.class);
register(SwitchStatement.class, ASTSwitchStatement.class);
register(TaggedTemplateLiteral.class, ASTTaggedTemplateLiteral.class);
register(TemplateCharacters.class, ASTTemplateCharacters.class);
register(TemplateLiteral.class, ASTTemplateLiteral.class);
register(ThrowStatement.class, ASTThrowStatement.class);
register(TryStatement.class, ASTTryStatement.class);
register(UnaryExpression.class, ASTUnaryExpression.class);
register(UpdateExpression.class, ASTUpdateExpression.class);
register(VariableDeclaration.class, ASTVariableDeclaration.class);
register(VariableInitializer.class, ASTVariableInitializer.class);
register(WhileLoop.class, ASTWhileLoop.class);
register(WithStatement.class, ASTWithStatement.class);
register(XmlDotQuery.class, ASTXmlDotQuery.class);
register(XmlElemRef.class, ASTXmlElemRef.class);
register(XmlExpression.class, ASTXmlExpression.class);
register(XmlMemberGet.class, ASTXmlMemberGet.class);
register(XmlPropRef.class, ASTXmlPropRef.class);
register(XmlString.class, ASTXmlString.class);
register(XmlLiteral.class, ASTXmlLiteral.class);
register(Yield.class, ASTYield.class);
}
private final List<ParseProblem> parseProblems;
private final Map<ParseProblem, AbstractEcmascriptNode<?>> parseProblemToNode = new HashMap<>();
// The nodes having children built.
private final Deque<AbstractEcmascriptNode<?>> nodes = new ArrayDeque<>();
// The Rhino nodes with children to build.
private final Deque<AstNode> parents = new ArrayDeque<>();
EcmascriptTreeBuilder(List<ParseProblem> parseProblems) {
this.parseProblems = parseProblems;
}
private static <T extends AstNode> void register(Class<T> nodeType,
Class<? extends AbstractEcmascriptNode<T>> nodeAdapterType) {
try {
NODE_TYPE_TO_NODE_ADAPTER_TYPE.put(nodeType, nodeAdapterType.getDeclaredConstructor(nodeType));
} catch (SecurityException | NoSuchMethodException e) {
throw new RuntimeException(e);
}
}
static <T extends AstNode> AbstractEcmascriptNode<T> createNodeAdapter(T node) {
try {
// the register function makes sure only AbstractEcmascriptNode<T> can be
// added, where T is "T extends AstNode".
@SuppressWarnings("unchecked")
Constructor<? extends AbstractEcmascriptNode<T>> constructor = (Constructor<? extends AbstractEcmascriptNode<T>>) NODE_TYPE_TO_NODE_ADAPTER_TYPE.get(node.getClass());
if (constructor == null) {
throw new IllegalArgumentException(
"There is no Node adapter class registered for the Node class: " + node.getClass());
}
return constructor.newInstance(node);
} catch (InstantiationException | IllegalAccessException e) {
throw new RuntimeException(e);
} catch (InvocationTargetException e) {
throw new RuntimeException(e.getTargetException());
}
}
public <T extends AstNode> EcmascriptNode<T> build(T astNode) {
EcmascriptNode<T> node = buildInternal(astNode);
// Set all the trailing comma nodes
for (AbstractEcmascriptNode<?> trailingCommaNode : parseProblemToNode.values()) {
trailingCommaNode.setTrailingCommaExists(true);
}
return node;
}
private <T extends AstNode> EcmascriptNode<T> buildInternal(T astNode) {
// Create a Node
AbstractEcmascriptNode<T> node = createNodeAdapter(astNode);
// Append to parent
AbstractEcmascriptNode<?> parent = nodes.isEmpty() ? null : nodes.peek();
if (parent != null) {
parent.addChild(node, parent.getNumChildren());
}
handleParseProblems(node);
// Build the children...
nodes.push(node);
parents.push(astNode);
astNode.visit(this);
nodes.pop();
parents.pop();
return node;
}
@Override
public boolean visit(AstNode node) {
if (node.equals(parents.peek())) {
return true;
} else {
buildInternal(node);
return false;
}
}
private void handleParseProblems(AbstractEcmascriptNode<? extends AstNode> node) {
if (node instanceof TrailingCommaNode) {
int nodeStart = node.node.getAbsolutePosition();
int nodeEnd = nodeStart + node.node.getLength() - 1;
// This will fetch the localized message
// See https://github.com/pmd/pmd/issues/384
String trailingCommaLocalizedMessage = ScriptRuntime.getMessage0("msg.extra.trailing.comma");
for (ParseProblem parseProblem : parseProblems) {
// The node overlaps the comma (i.e. end of the problem)?
int problemStart = parseProblem.getFileOffset();
int commaPosition = problemStart + parseProblem.getLength() - 1;
if (nodeStart <= commaPosition && commaPosition <= nodeEnd) {
if (trailingCommaLocalizedMessage.equals(parseProblem.getMessage())) {
// Report on the shortest code block containing the
// problem (i.e. inner most code in nested structures).
AbstractEcmascriptNode<?> currentNode = parseProblemToNode.get(parseProblem);
if (currentNode == null || node.node.getLength() < currentNode.node.getLength()) {
parseProblemToNode.put(parseProblem, node);
}
}
}
}
}
}
}
| 12,359 | 45.641509 | 178 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/AbstractEcmascriptNode.java | /*
* 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.AstNode;
import net.sourceforge.pmd.lang.ast.AstVisitor;
import net.sourceforge.pmd.lang.ast.impl.AbstractNode;
import net.sourceforge.pmd.lang.document.TextRegion;
abstract class AbstractEcmascriptNode<T extends AstNode> extends AbstractNode<AbstractEcmascriptNode<?>, EcmascriptNode<?>> implements EcmascriptNode<T> {
protected final T node;
private String image;
AbstractEcmascriptNode(T node) {
this.node = node;
}
@Override
protected void addChild(AbstractEcmascriptNode<?> child, int index) {
super.addChild(child, index);
}
@Override
public String getImage() {
return image;
}
protected void setImage(String image) {
this.image = image;
}
@Override
public TextRegion getTextRegion() {
return TextRegion.fromOffsetLength(node.getAbsolutePosition(), node.getLength());
}
@Override
@SuppressWarnings("unchecked")
public final <P, R> R acceptVisitor(AstVisitor<? super P, ? extends R> visitor, P data) {
if (visitor instanceof EcmascriptVisitor) {
return acceptJsVisitor((EcmascriptVisitor<? super P, ? extends R>) visitor, data);
}
return visitor.cannotVisit(this, data);
}
protected abstract <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data);
@Override
@Deprecated
public T getNode() {
return node;
}
@Override
public String getJsDoc() {
return node.getJsDoc();
}
@Override
public boolean hasSideEffects() {
return node.hasSideEffects();
}
@Override
public String getXPathNodeName() {
return node.shortName();
}
protected void setTrailingCommaExists(boolean b) {
// empty. Only needed for ASTArrayLiteral and ASTObjectLiteral
// This method is protected to not clutter the public API via a interface
}
}
| 2,094 | 25.858974 | 154 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTScope.java | /*
* 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.Scope;
public final class ASTScope extends AbstractEcmascriptNode<Scope> {
ASTScope(Scope scope) {
super(scope);
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
}
| 469 | 23.736842 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTCatchClause.java | /*
* 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 final class ASTCatchClause extends AbstractEcmascriptNode<CatchClause> {
ASTCatchClause(CatchClause catchClause) {
super(catchClause);
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
public ASTName getVariableName() {
return (ASTName) getChild(0);
}
public boolean isIf() {
return node.getCatchCondition() != null;
}
public EcmascriptNode<?> getCatchCondition() {
return (EcmascriptNode<?>) getChild(1);
}
public ASTBlock getBlock() {
return (ASTBlock) getChild(getNumChildren() - 1);
}
}
| 883 | 24.257143 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTPropertyGet.java | /*
* 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.PropertyGet;
public final class ASTPropertyGet extends AbstractInfixEcmascriptNode<PropertyGet> {
ASTPropertyGet(PropertyGet propertyGet) {
super(propertyGet, false);
super.setImage(".");
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
}
| 552 | 26.65 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTWithStatement.java | /*
* 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.WithStatement;
public final class ASTWithStatement extends AbstractEcmascriptNode<WithStatement> {
ASTWithStatement(WithStatement withStatement) {
super(withStatement);
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
public EcmascriptNode<?> getExpression() {
return (EcmascriptNode<?>) getChild(0);
}
public EcmascriptNode<?> getStatement() {
return (EcmascriptNode<?>) getChild(1);
}
}
| 728 | 26 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/EcmascriptVisitorBase.java | /*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.ecmascript.ast;
import net.sourceforge.pmd.lang.ast.AstVisitorBase;
/**
* A base visitor that by default does a top-down visit of the tree.
*
* @param <P> Parameter of the visit
* @param <R> Return type of the visit
*/
public abstract class EcmascriptVisitorBase<P, R> extends AstVisitorBase<P, R> implements EcmascriptVisitor<P, R> {
}
| 466 | 24.944444 | 115 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTXmlElemRef.java | /*
* 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.XmlElemRef;
public final class ASTXmlElemRef extends AbstractEcmascriptNode<XmlElemRef> {
ASTXmlElemRef(XmlElemRef xmlElemRef) {
super(xmlElemRef);
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
}
| 505 | 24.3 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTFunctionNode.java | /*
* 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 final class ASTFunctionNode extends AbstractEcmascriptNode<FunctionNode> {
ASTFunctionNode(FunctionNode functionNode) {
super(functionNode);
super.setImage(functionNode.getName());
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
public int getNumParams() {
return node.getParams().size();
}
public ASTName getFunctionName() {
if (node.getFunctionName() != null) {
return (ASTName) getChild(0);
}
return null;
}
public EcmascriptNode<?> getParam(int index) {
int paramIndex = index;
if (node.getFunctionName() != null) {
paramIndex = index + 1;
}
return (EcmascriptNode<?>) getChild(paramIndex);
}
public EcmascriptNode<?> getBody() {
return (EcmascriptNode<?>) getChild(getNumChildren() - 1);
}
@Deprecated // use getBody() instead
public EcmascriptNode<?> getBody(int index) {
return getBody();
}
public boolean isClosure() {
return node.isExpressionClosure();
}
public boolean isGetter() {
return node.isGetterMethod();
}
public boolean isSetter() {
return node.isSetterMethod();
}
public boolean isGetterOrSetter() {
return isGetter() || isSetter();
}
}
| 1,613 | 24.21875 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTGeneratorExpression.java | /*
* 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.GeneratorExpression;
public final class ASTGeneratorExpression extends AbstractEcmascriptNode<GeneratorExpression> {
ASTGeneratorExpression(GeneratorExpression generatorExpression) {
super(generatorExpression);
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
}
| 568 | 27.45 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTArrayComprehensionLoop.java | /*
* 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 final class ASTArrayComprehensionLoop extends AbstractEcmascriptNode<ArrayComprehensionLoop> {
ASTArrayComprehensionLoop(ArrayComprehensionLoop arrayComprehensionLoop) {
super(arrayComprehensionLoop);
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
public EcmascriptNode<?> getIterator() {
return (EcmascriptNode<?>) getChild(0);
}
public EcmascriptNode<?> getIteratedObject() {
return (EcmascriptNode<?>) getChild(1);
}
}
| 794 | 28.444444 | 101 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/EcmascriptParser.java | /*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.ecmascript.ast;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.mozilla.javascript.CompilerEnvirons;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Parser;
import org.mozilla.javascript.ast.AstRoot;
import org.mozilla.javascript.ast.Comment;
import org.mozilla.javascript.ast.ErrorCollector;
import org.mozilla.javascript.ast.ParseProblem;
import net.sourceforge.pmd.lang.LanguagePropertyBundle;
import net.sourceforge.pmd.lang.LanguageVersion;
import net.sourceforge.pmd.lang.ast.AstInfo;
import net.sourceforge.pmd.lang.ast.FileAnalysisException;
import net.sourceforge.pmd.lang.ast.ParseException;
import net.sourceforge.pmd.lang.ast.RootNode;
public final class EcmascriptParser implements net.sourceforge.pmd.lang.ast.Parser {
private final LanguagePropertyBundle properties;
public EcmascriptParser(LanguagePropertyBundle properties) {
this.properties = properties;
}
private AstRoot parseEcmascript(final String sourceCode, final LanguageVersion version, final List<ParseProblem> parseProblems) throws ParseException {
final CompilerEnvirons compilerEnvirons = new CompilerEnvirons();
compilerEnvirons.setRecordingComments(true);
compilerEnvirons.setRecordingLocalJsDocComments(true);
compilerEnvirons.setLanguageVersion(determineRhinoLanguageVersion(version));
// Scope's don't appear to get set right without this
compilerEnvirons.setIdeMode(true);
compilerEnvirons.setWarnTrailingComma(true);
// see bug #1150 "EmptyExpression" for valid statements!
compilerEnvirons.setReservedKeywordAsIdentifier(true);
// TODO We should do something with Rhino errors...
final ErrorCollector errorCollector = new ErrorCollector();
final Parser parser = new Parser(compilerEnvirons, errorCollector);
// TODO Fix hardcode
final String sourceURI = "unknown";
final int beginLineno = 1;
AstRoot astRoot = parser.parse(sourceCode, sourceURI, beginLineno);
parseProblems.addAll(errorCollector.getErrors());
return astRoot;
}
private static int determineRhinoLanguageVersion(LanguageVersion version) {
switch (version.getVersion()) {
case "3": return Context.VERSION_1_5;
case "5": return Context.VERSION_1_8;
default: return Context.VERSION_ES6;
}
}
@Override
public RootNode parse(ParserTask task) throws FileAnalysisException {
final LanguageVersion version = task.getLanguageVersion();
final List<ParseProblem> parseProblems = new ArrayList<>();
final AstRoot astRoot = parseEcmascript(task.getSourceText(), version, parseProblems);
final EcmascriptTreeBuilder treeBuilder = new EcmascriptTreeBuilder(parseProblems);
ASTAstRoot tree = (ASTAstRoot) treeBuilder.build(astRoot);
String suppressMarker = properties.getSuppressMarker();
Map<Integer, String> suppressMap = new HashMap<>();
if (astRoot.getComments() != null) {
for (Comment comment : astRoot.getComments()) {
int nopmd = comment.getValue().indexOf(suppressMarker);
if (nopmd > -1) {
String suppression = comment.getValue().substring(nopmd + suppressMarker.length());
suppressMap.put(comment.getLineno(), suppression);
}
}
}
tree.setAstInfo(new AstInfo<>(task, tree).withSuppressMap(suppressMap));
return tree;
}
}
| 3,715 | 41.227273 | 155 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTLabel.java | /*
* 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 final class ASTLabel extends AbstractEcmascriptNode<Label> {
ASTLabel(Label label) {
super(label);
super.setImage(label.getName());
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
}
| 510 | 24.55 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTXmlMemberGet.java | /*
* 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.XmlMemberGet;
public final class ASTXmlMemberGet extends AbstractInfixEcmascriptNode<XmlMemberGet> {
ASTXmlMemberGet(XmlMemberGet xmlMemberGet) {
super(xmlMemberGet);
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
}
| 523 | 26.578947 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTAstRoot.java | /*
* 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;
import net.sourceforge.pmd.lang.ast.AstInfo;
import net.sourceforge.pmd.lang.ast.RootNode;
public final class ASTAstRoot extends AbstractEcmascriptNode<AstRoot> implements RootNode {
private AstInfo<ASTAstRoot> astInfo;
public ASTAstRoot(AstRoot astRoot) {
super(astRoot);
}
@Override
public AstInfo<ASTAstRoot> getAstInfo() {
return astInfo;
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
public int getNumComments() {
return node.getComments() != null ? node.getComments().size() : 0;
}
public ASTComment getComment(int index) {
return (ASTComment) getChild(getNumChildren() - 1 - getNumComments() + index);
}
void setAstInfo(AstInfo<ASTAstRoot> astInfo) {
this.astInfo = astInfo;
}
}
| 1,083 | 24.209302 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTXmlLiteral.java | /*
* 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.XmlLiteral;
public final class ASTXmlLiteral extends AbstractEcmascriptNode<XmlLiteral> {
ASTXmlLiteral(XmlLiteral xmlLiteral) {
super(xmlLiteral);
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
}
| 505 | 24.3 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/DestructuringNode.java | /*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.ecmascript.ast;
public interface DestructuringNode {
boolean isDestructuring();
}
| 208 | 19.9 | 79 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTArrayComprehension.java | /*
* 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 final class ASTArrayComprehension extends AbstractEcmascriptNode<ArrayComprehension> {
ASTArrayComprehension(ArrayComprehension arrayComprehension) {
super(arrayComprehension);
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
public EcmascriptNode<?> getResult() {
return (EcmascriptNode<?>) getChild(0);
}
public int getNumArrayComprehensionLoops() {
return node.getLoops().size();
}
public ASTArrayComprehensionLoop getArrayComprehensionLoop(int index) {
return (ASTArrayComprehensionLoop) getChild(index + 1);
}
public boolean hasFilter() {
return node.getFilter() != null;
}
public EcmascriptNode<?> getFilter() {
return (EcmascriptNode<?>) getChild(getNumChildren() - 1);
}
}
| 1,098 | 27.179487 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTBigIntLiteral.java | /*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.ecmascript.ast;
import java.math.BigInteger;
import org.mozilla.javascript.ast.BigIntLiteral;
public final class ASTBigIntLiteral extends AbstractEcmascriptNode<BigIntLiteral> {
ASTBigIntLiteral(BigIntLiteral bigIntLiteral) {
super(bigIntLiteral);
super.setImage(bigIntLiteral.getValue());
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
public BigInteger getNumber() {
return node.getBigInt();
}
}
| 682 | 24.296296 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTLetNode.java | /*
* 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 final class ASTLetNode extends AbstractEcmascriptNode<LetNode> {
ASTLetNode(LetNode letNode) {
super(letNode);
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
public ASTVariableDeclaration getVariables() {
return (ASTVariableDeclaration) getChild(0);
}
public boolean hasBody() {
return node.getBody() != null;
}
public EcmascriptNode<?> getBody() {
if (hasBody()) {
return (EcmascriptNode<?>) getChild(getNumChildren() - 1);
} else {
return null;
}
}
}
| 867 | 23.8 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTXmlString.java | /*
* 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.XmlString;
public final class ASTXmlString extends AbstractEcmascriptNode<XmlString> {
ASTXmlString(XmlString xmlString) {
super(xmlString);
super.setImage(xmlString.getXml());
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
}
| 541 | 26.1 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTNumberLiteral.java | /*
* 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.NumberLiteral;
public final class ASTNumberLiteral extends AbstractEcmascriptNode<NumberLiteral> {
ASTNumberLiteral(NumberLiteral numberLiteral) {
super(numberLiteral);
super.setImage(numberLiteral.getValue());
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
public String getNormalizedImage() {
String image = getImage();
image = image.replaceAll("_", "");
image = normalizeHexIntegerLiteral(image);
image = normalizeBinaryLiteral(image);
image = normalizeOctalLiteral(image);
image = image.replace('e', 'E');
if (image.indexOf('.') == -1 && image.indexOf('E') == -1) {
image = image + ".0";
}
return image;
}
private String normalizeHexIntegerLiteral(String image) {
if (image.startsWith("0x") || image.startsWith("0X")) {
return String.valueOf(Integer.parseInt(image.substring(2), 16));
}
return image;
}
private String normalizeBinaryLiteral(String image) {
if (image.startsWith("0b") || image.startsWith("0B")) {
return String.valueOf(Integer.parseInt(image.substring(2), 2));
}
return image;
}
private String normalizeOctalLiteral(String image) {
if (image.startsWith("0o") || image.startsWith("0O")) {
return String.valueOf(Integer.parseInt(image.substring(2), 8));
}
return image;
}
public double getNumber() {
return node.getNumber();
}
}
| 1,807 | 30.172414 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTXmlPropRef.java | /*
* 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;
import org.mozilla.javascript.ast.XmlPropRef;
public final class ASTXmlPropRef extends AbstractEcmascriptNode<XmlPropRef> {
ASTXmlPropRef(XmlPropRef xmlPropRef) {
super(xmlPropRef);
Name propName = xmlPropRef.getPropName();
if (propName != null) {
super.setImage(propName.getIdentifier());
}
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
}
| 692 | 25.653846 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTEmptyStatement.java | /*
* 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.EmptyStatement;
public final class ASTEmptyStatement extends AbstractEcmascriptNode<EmptyStatement> {
ASTEmptyStatement(EmptyStatement emptyStatement) {
super(emptyStatement);
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
}
| 532 | 27.052632 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTBlock.java | /*
* 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 final class ASTBlock extends AbstractEcmascriptNode<Block> {
ASTBlock(Block block) {
super(block);
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
}
| 469 | 23.736842 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/AbstractInfixEcmascriptNode.java | /*
* 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.AstRoot;
import org.mozilla.javascript.ast.InfixExpression;
abstract class AbstractInfixEcmascriptNode<T extends InfixExpression> extends AbstractEcmascriptNode<T> {
AbstractInfixEcmascriptNode(T infixExpression) {
this(infixExpression, true);
}
AbstractInfixEcmascriptNode(T infixExpression, boolean setImage) {
super(infixExpression);
if (setImage) {
if (infixExpression.getOperator() == Token.ASSIGN_BITXOR) {
super.setImage("^=");
} else if (infixExpression.getOperator() != Token.METHOD) {
super.setImage(AstRoot.operatorToString(infixExpression.getOperator()));
}
}
}
public EcmascriptNode<?> getLeft() {
return getChild(0);
}
public EcmascriptNode<?> getRight() {
return getChild(1);
}
}
| 1,057 | 28.388889 | 105 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTRegExpLiteral.java | /*
* 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.RegExpLiteral;
public final class ASTRegExpLiteral extends AbstractEcmascriptNode<RegExpLiteral> {
ASTRegExpLiteral(RegExpLiteral regExpLiteral) {
super(regExpLiteral);
super.setImage(regExpLiteral.getValue());
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
public String getFlags() {
return node.getFlags();
}
}
| 645 | 25.916667 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/AbstractFunctionCallNode.java | /*
* 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;
abstract 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;
}
}
| 739 | 22.125 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTSwitchStatement.java | /*
* 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.SwitchStatement;
public final class ASTSwitchStatement extends AbstractEcmascriptNode<SwitchStatement> {
ASTSwitchStatement(SwitchStatement switchStatement) {
super(switchStatement);
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
public EcmascriptNode<?> getExpression() {
return (EcmascriptNode<?>) getChild(0);
}
public int getNumCases() {
return node.getCases().size();
}
public ASTSwitchCase getSwitchCase(int index) {
return (ASTSwitchCase) getChild(index + 1);
}
}
| 829 | 25.774194 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTScriptNode.java | /*
* 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.ScriptNode;
public final class ASTScriptNode extends AbstractEcmascriptNode<ScriptNode> {
ASTScriptNode(ScriptNode scriptNode) {
super(scriptNode);
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
}
| 505 | 24.3 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTForInLoop.java | /*
* 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 final class ASTForInLoop extends AbstractEcmascriptNode<ForInLoop> {
ASTForInLoop(ForInLoop forInLoop) {
super(forInLoop);
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
public EcmascriptNode<?> getIterator() {
return (EcmascriptNode<?>) getChild(0);
}
public EcmascriptNode<?> getIteratedObject() {
return (EcmascriptNode<?>) getChild(1);
}
public EcmascriptNode<?> getBody() {
return (EcmascriptNode<?>) getChild(2);
}
public boolean isForEach() {
return node.isForEach();
}
public boolean isForOf() {
return node.isForOf();
}
}
| 941 | 23.153846 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTFunctionCall.java | /*
* 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 final class ASTFunctionCall extends AbstractFunctionCallNode<FunctionCall> {
ASTFunctionCall(FunctionCall functionCall) {
super(functionCall);
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
}
| 520 | 26.421053 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTInfixExpression.java | /*
* 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 final class ASTInfixExpression extends AbstractInfixEcmascriptNode<InfixExpression> {
ASTInfixExpression(InfixExpression infixExpression) {
super(infixExpression);
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
}
| 544 | 27.684211 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTVariableDeclaration.java | /*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.ecmascript.ast;
import java.util.Locale;
import org.mozilla.javascript.Token;
import org.mozilla.javascript.ast.VariableDeclaration;
public final class ASTVariableDeclaration extends AbstractEcmascriptNode<VariableDeclaration> {
ASTVariableDeclaration(VariableDeclaration variableDeclaration) {
super(variableDeclaration);
super.setImage(Token.typeToName(variableDeclaration.getType()).toLowerCase(Locale.ROOT));
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
public ASTVariableInitializer getVariableInitializer(int index) {
return (ASTVariableInitializer) getChild(index);
}
public boolean isVar() {
return node.isVar();
}
public boolean isLet() {
return node.isLet();
}
public boolean isConst() {
return node.isConst();
}
}
| 1,061 | 26.230769 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTStringLiteral.java | /*
* 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.StringLiteral;
public final class ASTStringLiteral extends AbstractEcmascriptNode<StringLiteral> {
ASTStringLiteral(StringLiteral stringLiteral) {
super(stringLiteral);
super.setImage(stringLiteral.getValue());
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
public char getQuoteCharacter() {
return node.getQuoteCharacter();
}
public boolean isSingleQuoted() {
return '\'' == getQuoteCharacter();
}
public boolean isDoubleQuoted() {
return '"' == getQuoteCharacter();
}
}
| 838 | 25.21875 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/EcmascriptParserVisitor.java | /*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.ecmascript.ast;
import net.sourceforge.pmd.annotation.DeprecatedUntil700;
import net.sourceforge.pmd.lang.ast.Node;
/**
* @deprecated Use {@link EcmascriptVisitor}
*/
@Deprecated
@DeprecatedUntil700
public interface EcmascriptParserVisitor extends EcmascriptVisitor<Object, Object> {
@Override
default Object visitNode(Node node, Object param) {
node.children().forEach(c -> c.acceptVisitor(this, param));
return param;
}
/**
* @deprecated Use {@link #visitJsNode(EcmascriptNode, Object)}
*/
@Deprecated
default Object visit(EcmascriptNode<?> node, Object data) {
for (EcmascriptNode<?> child : node.children()) {
child.acceptVisitor(this, data);
}
return data;
}
}
| 883 | 25 | 84 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTAssignment.java | /*
* 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 final class ASTAssignment extends AbstractInfixEcmascriptNode<Assignment> {
ASTAssignment(Assignment asssignment) {
super(asssignment);
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
}
| 511 | 25.947368 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTWhileLoop.java | /*
* 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.WhileLoop;
public final class ASTWhileLoop extends AbstractEcmascriptNode<WhileLoop> {
ASTWhileLoop(WhileLoop whileLoop) {
super(whileLoop);
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
public EcmascriptNode<?> getCondition() {
return (EcmascriptNode<?>) getChild(0);
}
public EcmascriptNode<?> getBody() {
return (EcmascriptNode<?>) getChild(1);
}
}
| 694 | 24.740741 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTSwitchCase.java | /*
* 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.SwitchCase;
public final class ASTSwitchCase extends AbstractEcmascriptNode<SwitchCase> {
ASTSwitchCase(SwitchCase switchCase) {
super(switchCase);
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
public boolean isDefault() {
return node.isDefault();
}
public EcmascriptNode<?> getExpression() {
if (!isDefault()) {
return (EcmascriptNode<?>) getChild(0);
} else {
return null;
}
}
public int getNumStatements() {
// TODO Tell Rhino folks about null Statements, should be empty List?
return node.getStatements() != null ? node.getStatements().size() : 0;
}
public EcmascriptNode<?> getStatement(int index) {
int statementIndex = index;
if (!isDefault()) {
statementIndex++;
}
return (EcmascriptNode<?>) getChild(statementIndex);
}
}
| 1,190 | 26.068182 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTIfStatement.java | /*
* 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 final class ASTIfStatement extends AbstractEcmascriptNode<IfStatement> {
ASTIfStatement(IfStatement ifStatement) {
super(ifStatement);
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
public boolean hasElse() {
return node.getElsePart() != null;
}
public EcmascriptNode<?> getCondition() {
return (EcmascriptNode<?>) getChild(0);
}
public EcmascriptNode<?> getThen() {
return (EcmascriptNode<?>) getChild(1);
}
public EcmascriptNode<?> getElse() {
return (EcmascriptNode<?>) getChild(2);
}
}
| 885 | 24.314286 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTTaggedTemplateLiteral.java | /*
* 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.TaggedTemplateLiteral;
public final class ASTTaggedTemplateLiteral extends AbstractEcmascriptNode<TaggedTemplateLiteral> {
ASTTaggedTemplateLiteral(TaggedTemplateLiteral taggedTemplateLiteral) {
super(taggedTemplateLiteral);
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
}
| 582 | 28.15 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTVariableInitializer.java | /*
* 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.VariableInitializer;
public final class ASTVariableInitializer extends AbstractEcmascriptNode<VariableInitializer> implements DestructuringNode {
ASTVariableInitializer(VariableInitializer variableInitializer) {
super(variableInitializer);
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
public EcmascriptNode<?> getTarget() {
return (EcmascriptNode<?>) getChild(0);
}
public EcmascriptNode<?> getInitializer() {
if (getNumChildren() > 0) {
return (EcmascriptNode<?>) getChild(1);
} else {
return null;
}
}
@Override
public boolean isDestructuring() {
return node.isDestructuring();
}
}
| 988 | 26.472222 | 124 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTErrorNode.java | /*
* 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.ErrorNode;
public final class ASTErrorNode extends AbstractEcmascriptNode<ErrorNode> {
ASTErrorNode(ErrorNode errorNode) {
super(errorNode);
super.setImage(errorNode.getMessage());
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
public String getMessage() {
return node.getMessage();
}
}
| 620 | 23.84 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/EcmascriptVisitor.java | /*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.ecmascript.ast;
import net.sourceforge.pmd.lang.ast.AstVisitor;
public interface EcmascriptVisitor<P, R> extends AstVisitor<P, R> {
/**
* Every visit method for other JS nodes forwards to this method
* by default.
*/
default R visitJsNode(EcmascriptNode<?> node, P data) {
return visitNode(node, data);
}
default R visit(ASTArrayComprehension node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTArrayComprehensionLoop node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTArrayLiteral node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTAssignment node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTAstRoot node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTBigIntLiteral node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTBlock node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTBreakStatement node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTCatchClause node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTComment node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTConditionalExpression node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTContinueStatement node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTDoLoop node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTElementGet node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTEmptyExpression node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTEmptyStatement node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTErrorNode node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTExpressionStatement node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTForInLoop node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTForLoop node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTFunctionCall node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTFunctionNode node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTGeneratorExpression node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTGeneratorExpressionLoop node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTIfStatement node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTInfixExpression node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTKeywordLiteral node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTLabel node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTLabeledStatement node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTLetNode node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTName node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTNewExpression node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTNumberLiteral node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTObjectLiteral node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTObjectProperty node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTParenthesizedExpression node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTPropertyGet node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTRegExpLiteral node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTReturnStatement node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTScope node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTScriptNode node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTStringLiteral node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTSwitchCase node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTSwitchStatement node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTTaggedTemplateLiteral node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTTemplateCharacters node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTTemplateLiteral node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTThrowStatement node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTTryStatement node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTUnaryExpression node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTUpdateExpression node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTVariableDeclaration node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTVariableInitializer node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTWhileLoop node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTWithStatement node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTXmlDotQuery node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTXmlElemRef node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTXmlExpression node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTXmlLiteral node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTXmlMemberGet node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTXmlPropRef node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTXmlString node, P data) {
return visitJsNode(node, data);
}
default R visit(ASTYield node, P data) {
return visitJsNode(node, data);
}
}
| 6,750 | 23.911439 | 79 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTEmptyExpression.java | /*
* 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 final class ASTEmptyExpression extends AbstractEcmascriptNode<EmptyExpression> {
ASTEmptyExpression(EmptyExpression emptyExpression) {
super(emptyExpression);
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
}
| 539 | 27.421053 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTTryStatement.java | /*
* 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.TryStatement;
public final class ASTTryStatement extends AbstractEcmascriptNode<TryStatement> {
ASTTryStatement(TryStatement tryStatement) {
super(tryStatement);
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
public EcmascriptNode<?> getTryBlock() {
return (EcmascriptNode<?>) getChild(0);
}
@Deprecated // use hasCatch() instead
public boolean isCatch() {
return hasCatch();
}
public boolean hasCatch() {
return getNumCatchClause() != 0;
}
public int getNumCatchClause() {
return node.getCatchClauses().size();
}
public ASTCatchClause getCatchClause(int index) {
if (index >= getNumCatchClause()) {
return null;
}
return (ASTCatchClause) getChild(index + 1);
}
@Deprecated // use hasFinally() instead
public boolean isFinally() {
return hasFinally();
}
public boolean hasFinally() {
return node.getFinallyBlock() != null;
}
public EcmascriptNode<?> getFinallyBlock() {
if (!hasFinally()) {
return null;
}
return (EcmascriptNode<?>) getChild(getNumChildren() - 1);
}
}
| 1,476 | 24.033898 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTUnaryExpression.java | /*
* 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.AstRoot;
import org.mozilla.javascript.ast.UnaryExpression;
public final class ASTUnaryExpression extends AbstractEcmascriptNode<UnaryExpression> {
ASTUnaryExpression(UnaryExpression unaryExpression) {
super(unaryExpression);
super.setImage(AstRoot.operatorToString(unaryExpression.getOperator()));
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
public EcmascriptNode<?> getOperand() {
return (EcmascriptNode<?>) getChild(0);
}
public boolean isPrefix() {
return !isPostfix();
}
public boolean isPostfix() {
return node.getOperator() == Token.INC || node.getOperator() == Token.DEC;
}
}
| 990 | 28.147059 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTLabeledStatement.java | /*
* 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 final class ASTLabeledStatement extends AbstractEcmascriptNode<LabeledStatement> {
ASTLabeledStatement(LabeledStatement labeledStatement) {
super(labeledStatement);
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
public int getNumLabels() {
return node.getLabels().size();
}
public ASTLabel getLabel(int index) {
return (ASTLabel) getChild(index);
}
public EcmascriptNode<?> getStatement() {
return (EcmascriptNode<?>) getChild(getNumChildren() - 1);
}
}
| 837 | 26.032258 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTTemplateLiteral.java | /*
* 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.TemplateLiteral;
public final class ASTTemplateLiteral extends AbstractEcmascriptNode<TemplateLiteral> {
ASTTemplateLiteral(TemplateLiteral templateLiteral) {
super(templateLiteral);
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
}
| 540 | 26.05 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTConditionalExpression.java | /*
* 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 final class ASTConditionalExpression extends AbstractEcmascriptNode<ConditionalExpression> {
ASTConditionalExpression(ConditionalExpression conditionalExpression) {
super(conditionalExpression);
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
public EcmascriptNode<?> getTestExpression() {
return (EcmascriptNode<?>) getChild(0);
}
public EcmascriptNode<?> getTrueExpression() {
return (EcmascriptNode<?>) getChild(1);
}
public EcmascriptNode<?> getFalseExpression() {
return (EcmascriptNode<?>) getChild(2);
}
}
| 900 | 28.064516 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/EcmascriptParserVisitorAdapter.java | /*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.ecmascript.ast;
import net.sourceforge.pmd.annotation.DeprecatedUntil700;
/**
* @deprecated Use {@link EcmascriptVisitorBase}
*/
@Deprecated
@DeprecatedUntil700
public class EcmascriptParserVisitorAdapter extends EcmascriptVisitorBase<Object, Object> implements EcmascriptParserVisitor {
}
| 416 | 23.529412 | 126 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTElementGet.java | /*
* 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 final class ASTElementGet extends AbstractEcmascriptNode<ElementGet> {
ASTElementGet(ElementGet elementGet) {
super(elementGet);
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
public EcmascriptNode<?> getTarget() {
if (getNumChildren() > 0) {
return (EcmascriptNode<?>) getChild(0);
}
return null;
}
public EcmascriptNode<?> getElement() {
if (getNumChildren() > 1) {
return (EcmascriptNode<?>) getChild(1);
}
return null;
}
}
| 843 | 24.575758 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTComment.java | /*
* 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 final class ASTComment extends AbstractEcmascriptNode<Comment> {
ASTComment(Comment comment) {
super(comment);
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
public String getValue() {
return node.getValue();
}
}
| 553 | 23.086957 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/EcmascriptNode.java | /*
* 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.AstNode;
import net.sourceforge.pmd.annotation.DeprecatedUntil700;
import net.sourceforge.pmd.lang.ast.impl.GenericNode;
public interface EcmascriptNode<T extends AstNode> extends GenericNode<EcmascriptNode<?>> {
/**
* @deprecated See {@link EcmascriptParserVisitor}
*/
@Deprecated
@DeprecatedUntil700
default Object jjtAccept(EcmascriptParserVisitor visitor, Object data) {
return acceptVisitor(visitor, data);
}
/**
* Get the underlying Rhino AST node.
* @deprecated The underlying Rhino node should not be used directly.
*/
@Deprecated
T getNode();
/**
* Get the JsDoc associated with the given node. If there is no JsDoc on
* this node, it may be associated with a parent node, on more
* representative of the entire expression containing this node.
*
* @return The JsDoc comment for the node, may be <code>null</code>.
*/
String getJsDoc();
boolean hasSideEffects();
}
| 1,160 | 26.642857 | 91 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTObjectProperty.java | /*
* 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.ObjectProperty;
public final class ASTObjectProperty extends AbstractInfixEcmascriptNode<ObjectProperty> {
ASTObjectProperty(ObjectProperty objectProperty) {
super(objectProperty);
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
public boolean isGetter() {
return node.isGetterMethod();
}
public boolean isSetter() {
return node.isSetterMethod();
}
}
| 691 | 24.62963 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTNewExpression.java | /*
* 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.NewExpression;
public final class ASTNewExpression extends AbstractFunctionCallNode<NewExpression> {
ASTNewExpression(NewExpression newExpression) {
super(newExpression);
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
public boolean hasInitializer() {
return node.getInitializer() != null;
}
public ASTObjectLiteral getInitializer() {
return (ASTObjectLiteral) getChild(getNumChildren() - 1);
}
}
| 738 | 26.37037 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTXmlExpression.java | /*
* 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.XmlExpression;
public final class ASTXmlExpression extends AbstractEcmascriptNode<XmlExpression> {
ASTXmlExpression(XmlExpression xmlExpression) {
super(xmlExpression);
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
public EcmascriptNode<?> getExpression() {
return (EcmascriptNode<?>) getChild(0);
}
public boolean isXmlAttribute() {
return node.isXmlAttribute();
}
}
| 710 | 25.333333 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTExpressionStatement.java | /*
* 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 final class ASTExpressionStatement extends AbstractEcmascriptNode<ExpressionStatement> {
ASTExpressionStatement(ExpressionStatement expressionStatement) {
super(expressionStatement);
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
public boolean hasResult() {
return node.getType() == Token.EXPR_RESULT;
}
}
| 696 | 28.041667 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTKeywordLiteral.java | /*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.ecmascript.ast;
import java.util.Locale;
import org.mozilla.javascript.Token;
import org.mozilla.javascript.ast.KeywordLiteral;
public final class ASTKeywordLiteral extends AbstractEcmascriptNode<KeywordLiteral> {
ASTKeywordLiteral(KeywordLiteral keywordLiteral) {
super(keywordLiteral);
super.setImage(Token.typeToName(keywordLiteral.getType()).toLowerCase(Locale.ROOT));
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P 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;
}
}
| 1,022 | 25.230769 | 99 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/rule/AbstractEcmascriptRule.java | /*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.ecmascript.rule;
import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.ecmascript.ast.EcmascriptParserVisitor;
import net.sourceforge.pmd.lang.rule.AbstractRule;
public abstract class AbstractEcmascriptRule extends AbstractRule
implements EcmascriptParserVisitor {
@Override
public void apply(Node target, RuleContext ctx) {
target.acceptVisitor(this, ctx);
}
}
| 575 | 26.428571 | 79 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/rule/bestpractices/ConsistentReturnRule.java | /**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.ecmascript.rule.bestpractices;
import java.util.List;
import net.sourceforge.pmd.lang.ecmascript.ast.ASTFunctionNode;
import net.sourceforge.pmd.lang.ecmascript.ast.ASTReturnStatement;
import net.sourceforge.pmd.lang.ecmascript.rule.AbstractEcmascriptRule;
public class ConsistentReturnRule extends AbstractEcmascriptRule {
public ConsistentReturnRule() {
addRuleChainVisit(ASTFunctionNode.class);
}
@Override
public Object visit(ASTFunctionNode functionNode, Object data) {
List<ASTReturnStatement> returnStatements = functionNode.findDescendantsOfType(ASTReturnStatement.class);
Boolean hasResult = null;
for (ASTReturnStatement returnStatement : returnStatements) {
// Return for this function?
if (functionNode == returnStatement.getFirstParentOfType(ASTFunctionNode.class)) {
if (hasResult == null) {
hasResult = Boolean.valueOf(returnStatement.hasResult());
} else {
// Return has different result from previous return?
if (hasResult.booleanValue() != returnStatement.hasResult()) {
addViolation(data, functionNode);
break;
}
}
}
}
return data;
}
}
| 1,462 | 35.575 | 113 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/typescript/ast/TypeScriptLexerBase.java | /**
* Source: https://github.com/antlr/grammars-v4/tree/master/javascript/typescript
* License: MIT
*
* Slightly modified to adapt to pmd's style.
*/
package net.sourceforge.pmd.lang.typescript.ast;
import org.antlr.v4.runtime.*;
import java.util.ArrayDeque;
import java.util.Deque;
/**
* All lexer methods that used in grammar (IsStrictMode)
* should start with Upper Case Char similar to Lexer rules.
*/
abstract class TypeScriptLexerBase extends Lexer
{
/**
* Stores values of nested modes. By default mode is strict or
* defined externally (useStrictDefault)
*/
private Deque<Boolean> scopeStrictModes = new ArrayDeque<>();
private Token lastToken = null;
/**
* Default value of strict mode
* Can be defined externally by setUseStrictDefault
*/
private boolean useStrictDefault = false;
/**
* Current value of strict mode
* Can be defined during parsing, see StringFunctions.js and StringGlobal.js samples
*/
private boolean useStrictCurrent = false;
/**
* Keeps track of the current depth of nested template string backticks.
* E.g. after the X in:
*
* `${a ? `${X
*
* templateDepth will be 2. This variable is needed to determine if a `}` is a
* plain CloseBrace, or one that closes an expression inside a template string.
*/
private int templateDepth = 0;
/**
* Keeps track of the depth of open- and close-braces. Used for expressions like:
*
* `${[1, 2, 3].map(x => { return x * 2;}).join("")}`
*
* where the '}' from `return x * 2;}` should not become a `TemplateCloseBrace`
* token but rather a `CloseBrace` token.
*/
private int bracesDepth = 0;
TypeScriptLexerBase(CharStream input) {
super(input);
}
public boolean getStrictDefault() {
return useStrictDefault;
}
public void setUseStrictDefault(boolean value) {
useStrictDefault = value;
useStrictCurrent = value;
}
public boolean IsStrictMode() {
return useStrictCurrent;
}
public void StartTemplateString() {
this.bracesDepth = 0;
}
public boolean IsInTemplateString() {
return this.templateDepth > 0 && this.bracesDepth == 0;
}
/**
* Return the next token from the character stream and records this last
* token in case it resides on the default channel. This recorded token
* is used to determine when the lexer could possibly match a regex
* literal. Also changes scopeStrictModes stack if tokenize special
* string 'use strict';
*
* @return the next token from the character stream.
*/
@Override
public Token nextToken() {
Token next = super.nextToken();
if (next.getChannel() == Token.DEFAULT_CHANNEL) {
// Keep track of the last token on the default channel.
this.lastToken = next;
}
return next;
}
protected void ProcessOpenBrace()
{
bracesDepth++;
useStrictCurrent = !scopeStrictModes.isEmpty() && scopeStrictModes.peek() || useStrictDefault;
scopeStrictModes.push(useStrictCurrent);
}
protected void ProcessCloseBrace()
{
bracesDepth--;
useStrictCurrent = !scopeStrictModes.isEmpty() ? scopeStrictModes.pop() : useStrictDefault;
}
protected void ProcessStringLiteral()
{
if (lastToken == null || lastToken.getType() == TypeScriptLexer.OpenBrace)
{
String text = getText();
if ("\"use strict\"".equals(text) || "'use strict'".equals(text))
{
if (!scopeStrictModes.isEmpty()) {
scopeStrictModes.pop();
}
useStrictCurrent = true;
scopeStrictModes.push(useStrictCurrent);
}
}
}
protected void IncreaseTemplateDepth() {
this.templateDepth++;
}
protected void DecreaseTemplateDepth() {
this.templateDepth--;
}
/**
* Returns {@code true} if the lexer can match a regex literal.
*/
protected boolean IsRegexPossible() {
if (this.lastToken == null) {
// No token has been produced yet: at the start of the input,
// no division is possible, so a regex literal _is_ possible.
return true;
}
switch (this.lastToken.getType()) {
case TypeScriptLexer.Identifier:
case TypeScriptLexer.NullLiteral:
case TypeScriptLexer.BooleanLiteral:
case TypeScriptLexer.This:
case TypeScriptLexer.CloseBracket:
case TypeScriptLexer.CloseParen:
case TypeScriptLexer.OctalIntegerLiteral:
case TypeScriptLexer.DecimalLiteral:
case TypeScriptLexer.HexIntegerLiteral:
case TypeScriptLexer.StringLiteral:
case TypeScriptLexer.PlusPlus:
case TypeScriptLexer.MinusMinus:
// After any of the tokens above, no regex literal can follow.
return false;
default:
// In all other cases, a regex literal _is_ possible.
return true;
}
}
}
| 5,253 | 29.195402 | 102 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/typescript/ast/package-info.java | /*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.typescript.ast;
| 137 | 22 | 79 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/typescript/cpd/TypeScriptTokenizer.java | /**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.typescript.cpd;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.Lexer;
import net.sourceforge.pmd.cpd.impl.AntlrTokenizer;
import net.sourceforge.pmd.lang.typescript.ast.TypeScriptLexer;
public class TypeScriptTokenizer extends AntlrTokenizer {
@Override
protected Lexer getLexerForSource(CharStream charStream) {
return new TypeScriptLexer(charStream);
}
}
| 523 | 26.578947 | 79 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/typescript/cpd/TypeScriptLanguage.java | /**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.typescript.cpd;
import net.sourceforge.pmd.cpd.AbstractLanguage;
/**
* @author pguyot@kallisys.net
*/
public class TypeScriptLanguage extends AbstractLanguage {
public TypeScriptLanguage() {
super("TypeScript", "typescript", new TypeScriptTokenizer(), ".ts");
}
}
| 407 | 21.666667 | 79 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/cpd/EcmascriptLanguage.java | /*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.cpd;
import net.sourceforge.pmd.lang.ecmascript.EcmascriptLanguageModule;
/**
*
* @author Zev Blut zb@ubit.com
*/
public class EcmascriptLanguage extends AbstractLanguage {
public EcmascriptLanguage() {
super(EcmascriptLanguageModule.NAME, EcmascriptLanguageModule.TERSE_NAME, new EcmascriptTokenizer(),
EcmascriptLanguageModule.EXTENSIONS);
}
}
| 499 | 25.315789 | 108 | java |
pmd | pmd-master/pmd-javascript/src/main/java/net/sourceforge/pmd/cpd/EcmascriptTokenizer.java | /*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.cpd;
import net.sourceforge.pmd.cpd.impl.JavaCCTokenizer;
import net.sourceforge.pmd.lang.TokenManager;
import net.sourceforge.pmd.lang.ast.impl.javacc.CharStream;
import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccToken;
import net.sourceforge.pmd.lang.ecmascript5.ast.Ecmascript5TokenKinds;
/**
* The Ecmascript Tokenizer
*/
public class EcmascriptTokenizer extends JavaCCTokenizer {
@Override
protected TokenManager<JavaccToken> makeLexerImpl(CharStream sourceCode) {
return Ecmascript5TokenKinds.newTokenManager(sourceCode);
}
@Override
protected String getImage(JavaccToken jsToken) {
// Remove line continuation characters from string literals
if (jsToken.kind == Ecmascript5TokenKinds.STRING_LITERAL
|| jsToken.kind == Ecmascript5TokenKinds.UNTERMINATED_STRING_LITERAL) {
return jsToken.getImage().replaceAll("(?<!\\\\)\\\\(\\r\\n|\\r|\\n)", "");
}
return jsToken.getImage();
}
}
| 1,100 | 32.363636 | 86 | java |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.