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
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/UnaryExpression.java
package com.semmle.js.ast; /** * A unary expression such as <code>!x</code> or <code>void(0)</code>. * * <p>Note that increment and decrement expressions are represented by {@link UpdateExpression}. */ public class UnaryExpression extends Expression { private final String operator; private final Expression argument; private final boolean prefix; public UnaryExpression(SourceLocation loc, String operator, Expression argument, Boolean prefix) { super("UnaryExpression", loc); this.operator = operator; this.argument = argument; this.prefix = prefix == Boolean.TRUE; } @Override public <Q, A> A accept(Visitor<Q, A> v, Q q) { return v.visit(this, q); } /** The operator of this unary expression. */ public String getOperator() { return operator; } /** The argument of this unary expression. */ public Expression getArgument() { return argument; } /** Is the operator of this unary expression a prefix operator? */ public boolean isPrefix() { return prefix; } }
1,038
24.975
100
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/ExportAllDeclaration.java
package com.semmle.js.ast; /** * A re-export declaration of the form * * <pre> * export * from 'foo'; * </pre> */ public class ExportAllDeclaration extends ExportDeclaration { private final Literal source; public ExportAllDeclaration(SourceLocation loc, Literal source) { super("ExportAllDeclaration", loc); this.source = source; } public Literal getSource() { return source; } @Override public <C, R> R accept(Visitor<C, R> v, C c) { return v.visit(this, c); } }
508
17.851852
67
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/ExportDeclaration.java
package com.semmle.js.ast; public abstract class ExportDeclaration extends Statement { public ExportDeclaration(String type, SourceLocation loc) { super(type, loc); } }
179
19
61
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/Super.java
package com.semmle.js.ast; /** * A <code>super</code> expression, appearing either as the callee of a super constructor call or as * the receiver of a super method call. */ public class Super extends Expression { public Super(SourceLocation loc) { super("Super", loc); } @Override public <Q, A> A accept(Visitor<Q, A> v, Q q) { return v.visit(this, q); } }
380
21.411765
100
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/Visitor.java
package com.semmle.js.ast; import com.semmle.js.ast.jsx.JSXAttribute; import com.semmle.js.ast.jsx.JSXClosingElement; import com.semmle.js.ast.jsx.JSXElement; import com.semmle.js.ast.jsx.JSXEmptyExpression; import com.semmle.js.ast.jsx.JSXExpressionContainer; import com.semmle.js.ast.jsx.JSXIdentifier; import com.semmle.js.ast.jsx.JSXMemberExpression; import com.semmle.js.ast.jsx.JSXNamespacedName; import com.semmle.js.ast.jsx.JSXOpeningElement; import com.semmle.js.ast.jsx.JSXSpreadAttribute; import com.semmle.ts.ast.ArrayTypeExpr; import com.semmle.ts.ast.ConditionalTypeExpr; import com.semmle.ts.ast.DecoratorList; import com.semmle.ts.ast.EnumDeclaration; import com.semmle.ts.ast.EnumMember; import com.semmle.ts.ast.ExportAsNamespaceDeclaration; import com.semmle.ts.ast.ExportWholeDeclaration; import com.semmle.ts.ast.ExpressionWithTypeArguments; import com.semmle.ts.ast.ExternalModuleDeclaration; import com.semmle.ts.ast.ExternalModuleReference; import com.semmle.ts.ast.FunctionTypeExpr; import com.semmle.ts.ast.GenericTypeExpr; import com.semmle.ts.ast.GlobalAugmentationDeclaration; import com.semmle.ts.ast.ImportTypeExpr; import com.semmle.ts.ast.ImportWholeDeclaration; import com.semmle.ts.ast.IndexedAccessTypeExpr; import com.semmle.ts.ast.InferTypeExpr; import com.semmle.ts.ast.InterfaceDeclaration; import com.semmle.ts.ast.InterfaceTypeExpr; import com.semmle.ts.ast.IntersectionTypeExpr; import com.semmle.ts.ast.KeywordTypeExpr; import com.semmle.ts.ast.MappedTypeExpr; import com.semmle.ts.ast.NamespaceDeclaration; import com.semmle.ts.ast.NonNullAssertion; import com.semmle.ts.ast.OptionalTypeExpr; import com.semmle.ts.ast.ParenthesizedTypeExpr; import com.semmle.ts.ast.PredicateTypeExpr; import com.semmle.ts.ast.RestTypeExpr; import com.semmle.ts.ast.TupleTypeExpr; import com.semmle.ts.ast.TypeAliasDeclaration; import com.semmle.ts.ast.TypeAssertion; import com.semmle.ts.ast.TypeParameter; import com.semmle.ts.ast.TypeofTypeExpr; import com.semmle.ts.ast.UnaryTypeExpr; import com.semmle.ts.ast.UnionTypeExpr; /** * Interface for visitors to implement. * * <p>Visit methods take a context argument of type {@link C} and return a result of type {@link R}. */ public interface Visitor<C, R> { public R visit(AssignmentExpression nd, C q); public R visit(AssignmentPattern nd, C q); public R visit(BinaryExpression nd, C q); public R visit(BlockStatement nd, C q); public R visit(CallExpression nd, C q); public R visit(ComprehensionBlock nd, C q); public R visit(ComprehensionExpression nd, C q); public R visit(ExpressionStatement nd, C q); public R visit(FunctionDeclaration nd, C q); public R visit(Identifier nd, C q); public R visit(Literal nd, C q); public R visit(LogicalExpression nd, C q); public R visit(MemberExpression nd, C q); public R visit(Program nd, C q); public R visit(UnaryExpression nd, C q); public R visit(UpdateExpression nd, C q); public R visit(VariableDeclaration nd, C q); public R visit(VariableDeclarator nd, C q); public R visit(SwitchStatement nd, C q); public R visit(SwitchCase nd, C q); public R visit(ForStatement nd, C q); public R visit(ForInStatement nd, C q); public R visit(ForOfStatement nd, C q); public R visit(Property nd, C q); public R visit(ArrayPattern nd, C q); public R visit(ObjectPattern nd, C q); public R visit(IfStatement nd, C q); public R visit(LabeledStatement nd, C q); public R visit(WithStatement nd, C q); public R visit(DoWhileStatement nd, C q); public R visit(WhileStatement nd, C q); public R visit(CatchClause nd, C q); public R visit(TryStatement nd, C q); public R visit(NewExpression nd, C q); public R visit(ReturnStatement nd, C q); public R visit(ThrowStatement nd, C q); public R visit(SpreadElement nd, C q); public R visit(RestElement nd, C q); public R visit(YieldExpression nd, C q); public R visit(ParenthesizedExpression nd, C q); public R visit(EmptyStatement nd, C q); public R visit(BreakStatement nd, C q); public R visit(ContinueStatement nd, C q); public R visit(FunctionExpression nd, C q); public R visit(DebuggerStatement nd, C q); public R visit(ArrayExpression nd, C q); public R visit(ObjectExpression nd, C q); public R visit(ThisExpression nd, C q); public R visit(ConditionalExpression nd, C q); public R visit(SequenceExpression nd, C q); public R visit(TemplateElement nd, C q); public R visit(TemplateLiteral nd, C q); public R visit(TaggedTemplateExpression nd, C q); public R visit(ArrowFunctionExpression nd, C q); public R visit(LetStatement nd, C q); public R visit(LetExpression nd, C c); public R visit(ClassDeclaration nd, C c); public R visit(ClassExpression nd, C c); public R visit(ClassBody nd, C c); public R visit(MethodDefinition nd, C c); public R visit(FieldDefinition nd, C c); public R visit(Super nd, C c); public R visit(MetaProperty nd, C c); public R visit(ExportAllDeclaration nd, C c); public R visit(ExportDefaultDeclaration nd, C c); public R visit(ExportNamedDeclaration nd, C c); public R visit(ExportDefaultSpecifier nd, C c); public R visit(ExportNamespaceSpecifier nd, C c); public R visit(ExportSpecifier nd, C c); public R visit(ImportDeclaration nd, C c); public R visit(ImportDefaultSpecifier nd, C c); public R visit(ImportNamespaceSpecifier nd, C c); public R visit(ImportSpecifier nd, C c); public R visit(JSXIdentifier nd, C c); public R visit(JSXMemberExpression nd, C c); public R visit(JSXNamespacedName nd, C c); public R visit(JSXEmptyExpression nd, C c); public R visit(JSXExpressionContainer nd, C c); public R visit(JSXOpeningElement nd, C c); public R visit(JSXClosingElement nd, C c); public R visit(JSXAttribute nd, C c); public R visit(JSXSpreadAttribute nd, C c); public R visit(JSXElement nd, C c); public R visit(AwaitExpression nd, C c); public R visit(Decorator nd, C c); public R visit(BindExpression nd, C c); public R visit(NamespaceDeclaration nd, C c); public R visit(ImportWholeDeclaration nd, C c); public R visit(ExportWholeDeclaration nd, C c); public R visit(ExternalModuleReference nd, C c); public R visit(DynamicImport nd, C c); public R visit(InterfaceDeclaration nd, C c); public R visit(KeywordTypeExpr nd, C c); public R visit(ArrayTypeExpr nd, C c); public R visit(UnionTypeExpr nd, C c); public R visit(IndexedAccessTypeExpr nd, C c); public R visit(IntersectionTypeExpr nd, C c); public R visit(ParenthesizedTypeExpr nd, C c); public R visit(TupleTypeExpr nd, C c); public R visit(UnaryTypeExpr nd, C c); public R visit(GenericTypeExpr nd, C c); public R visit(TypeofTypeExpr nd, C c); public R visit(PredicateTypeExpr nd, C c); public R visit(InterfaceTypeExpr nd, C c); public R visit(ExpressionWithTypeArguments nd, C c); public R visit(TypeParameter nd, C c); public R visit(FunctionTypeExpr nd, C c); public R visit(TypeAssertion nd, C c); public R visit(MappedTypeExpr nd, C c); public R visit(TypeAliasDeclaration nd, C c); public R visit(EnumDeclaration nd, C c); public R visit(EnumMember nd, C c); public R visit(DecoratorList nd, C c); public R visit(ExternalModuleDeclaration nd, C c); public R visit(ExportAsNamespaceDeclaration nd, C c); public R visit(GlobalAugmentationDeclaration nd, C c); public R visit(NonNullAssertion nd, C c); public R visit(ConditionalTypeExpr nd, C q); public R visit(InferTypeExpr nd, C c); public R visit(ImportTypeExpr nd, C c); public R visit(OptionalTypeExpr nd, C c); public R visit(RestTypeExpr nd, C c); public R visit(XMLAnyName nd, C c); public R visit(XMLAttributeSelector nd, C c); public R visit(XMLFilterExpression nd, C c); public R visit(XMLQualifiedIdentifier nd, C c); public R visit(XMLDotDotExpression nd, C c); }
7,983
24.838188
100
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/FunctionExpression.java
package com.semmle.js.ast; import com.semmle.ts.ast.DecoratorList; import com.semmle.ts.ast.ITypeExpression; import com.semmle.ts.ast.TypeParameter; import com.semmle.util.data.IntList; import java.util.Collections; import java.util.List; /** A plain function expression. */ public class FunctionExpression extends AFunctionExpression { public FunctionExpression( SourceLocation loc, Identifier id, List<Expression> params, Node body, Boolean generator, Boolean async) { super( "FunctionExpression", loc, id, params, body, generator, async, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), null, null, AFunction.noOptionalParams); } public FunctionExpression( SourceLocation loc, Identifier id, List<Expression> params, Node body, Boolean generator, Boolean async, List<TypeParameter> typeParameters, List<ITypeExpression> parameterTypes, List<DecoratorList> parameterDecorators, ITypeExpression returnType, ITypeExpression thisParameterType, IntList optionalParameterIndices) { super( "FunctionExpression", loc, id, params, body, generator, async, typeParameters, parameterTypes, parameterDecorators, returnType, thisParameterType, optionalParameterIndices); } public FunctionExpression(SourceLocation loc, AFunction<? extends Node> fn) { super("FunctionExpression", loc, fn); } @Override public <Q, A> A accept(Visitor<Q, A> v, Q q) { return v.visit(this, q); } }
1,747
22.945205
79
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/package-info.java
/** * This package contains a Java implementation of the <a * href="https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/Parser_API">SpiderMonkey * AST format</a>. * * <p>SpiderMonkey AST node interfaces are represented by Java classes and interfaces with the same * name, plus a few additional abstract classes to improve code reuse. Union types are represented * by additional interfaces. * * <p>The root of the AST class hierarchy is {@link com.semmle.js.ast.Node}, which in turn * implements interface {@link com.semmle.js.ast.INode}. Interfaces representing union types also * extend that interface. * * <p>Every node has a source location ({@link com.semmle.js.ast.SourceLocation}), comprising a * start and an end position ({@link com.semmle.js.ast.Position}). Since other source elements * besides nodes also have source locations, this association is kept track of by {@link * com.semmle.js.ast.SourceElement}, the super class of {@link com.semmle.js.ast.Node}. * * <p>Nodes accept visitors implementing interface {@link com.semmle.js.ast.Visitor}. A default * visitor implementation that provides catch-all visit methods for groups of AST node classes is * also provided ({@link com.semmle.js.ast.DefaultVisitor}). */ package com.semmle.js.ast;
1,294
52.958333
104
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/Expression.java
package com.semmle.js.ast; import com.semmle.ts.ast.ITypedAstNode; /** Common superclass of all expressions. */ public abstract class Expression extends Node implements ITypedAstNode { private int staticTypeId = -1; public Expression(String type, SourceLocation loc) { super(type, loc); } /** This expression, but with any surrounding parentheses stripped off. */ public Expression stripParens() { return this; } @Override public int getStaticTypeId() { return staticTypeId; } @Override public void setStaticTypeId(int staticTypeId) { this.staticTypeId = staticTypeId; } }
619
21.142857
76
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/ContinueStatement.java
package com.semmle.js.ast; /** * A continue statement either with a label (<code>continue outer;</code>) or without (<code> * continue;</code>). */ public class ContinueStatement extends JumpStatement { public ContinueStatement(SourceLocation loc, Identifier label) { super("ContinueStatement", loc, label); } @Override public <Q, A> A accept(Visitor<Q, A> v, Q q) { return v.visit(this, q); } }
419
23.705882
93
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/Comment.java
package com.semmle.js.ast; import static com.semmle.js.ast.Comment.Kind.BLOCK; import static com.semmle.js.ast.Comment.Kind.HTML_END; import static com.semmle.js.ast.Comment.Kind.HTML_START; import static com.semmle.js.ast.Comment.Kind.LINE; /** * A source code comment. * * <p>This is not part of the SpiderMonkey AST format. */ public class Comment extends SourceElement { /** The kinds of comments recognized by the parser. */ public static enum Kind { /** A C++-style line comment starting with two slashes. */ LINE, /** A C-style block comment starting with slash-star and ending with star-slash. */ BLOCK, /** The start of an HTML comment (<code>&lt;!--</code>). */ HTML_START, /** The end of an HTML comment (<code>--&gt;</code>). */ HTML_END }; private final String text; private final Kind kind; public Comment(SourceLocation loc, String text) { super(loc); this.text = text; String raw = getLoc().getSource(); if (raw.startsWith("//")) this.kind = LINE; else if (raw.startsWith("/*")) this.kind = BLOCK; else if (raw.startsWith("<!--")) this.kind = HTML_START; else this.kind = HTML_END; } /** What kind of comment is this? */ public Kind getKind() { return kind; } /** Is this a JSDoc documentation comment? */ public boolean isDocComment() { return kind == BLOCK && text.startsWith("*"); } /** * The text of the comment, not including its delimiters. * * <p>For documentation comments, the leading asterisk is included. */ public String getText() { return text; } }
1,608
25.377049
87
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/JumpStatement.java
package com.semmle.js.ast; /** A jump statement, that is, either a {@link BreakStatement} or a {@link ContinueStatement}. */ public abstract class JumpStatement extends Statement { private final Identifier label; public JumpStatement(String type, SourceLocation loc, Identifier label) { super(type, loc); this.label = label; } /** Does this jump have an explicit target label? */ public boolean hasLabel() { return label != null; } /** Get the target label of this jump; may be null. */ public Identifier getLabel() { return label; } }
574
25.136364
97
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/ComprehensionBlock.java
package com.semmle.js.ast; /** A block in a comprehension expression. */ public class ComprehensionBlock extends Expression { private final IPattern left; private final Expression right; private final boolean of; public ComprehensionBlock(SourceLocation loc, IPattern left, Expression right, Boolean of) { super("ComprehensionBlock", loc); this.left = left; this.right = right; this.of = of != Boolean.FALSE; } @Override public <Q, A> A accept(Visitor<Q, A> v, Q q) { return v.visit(this, q); } /** The iterator variable of this comprehension block. */ public IPattern getLeft() { return left; } /** The expression this comprehension block iterates over. */ public Expression getRight() { return right; } /** Is this a <code>for-of</code> comprehension block? */ public boolean isOf() { return of; } }
874
23.305556
94
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/EnhancedForStatement.java
package com.semmle.js.ast; /** * An enhanced for statement, that is, either a {@link ForInStatement} or a {@link ForOfStatement}. */ public abstract class EnhancedForStatement extends Loop { private final Node left; private final Expression defaultValue; private final Expression right; public EnhancedForStatement( String type, SourceLocation loc, Node left, Expression right, Statement body) { super(type, loc, body); if (left instanceof AssignmentPattern) { AssignmentPattern ap = (AssignmentPattern) left; this.left = ap.getLeft(); this.defaultValue = ap.getRight(); } else { this.left = left; this.defaultValue = null; } this.right = right; } /** * The iterator variable of this statement; may be either a {@link VariableDeclaration} statement, * or an lvalue {@link Expression}. */ public Node getLeft() { return left; } /** Does the iterator variable of this statement have a default value? */ public boolean hasDefaultValue() { return defaultValue != null; } /** Get the default value of the iterator variable of this statement. */ public Expression getDefaultValue() { return defaultValue; } /** The expression this loop iterates over. */ public Expression getRight() { return right; } @Override public Node getContinueTarget() { return this; } }
1,390
25.245283
100
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/SpreadElement.java
package com.semmle.js.ast; /** A spread element <code>...xs</code> in rvalue position. */ public class SpreadElement extends Expression { private final Expression argument; public SpreadElement(SourceLocation loc, Expression argument) { super("SpreadElement", loc); this.argument = argument; } @Override public <Q, A> A accept(Visitor<Q, A> v, Q q) { return v.visit(this, q); } /** The argument expression of this spread element. */ public Expression getArgument() { return argument; } }
526
22.954545
65
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/AClass.java
package com.semmle.js.ast; import com.semmle.ts.ast.INodeWithSymbol; import com.semmle.ts.ast.ITypeExpression; import com.semmle.ts.ast.TypeParameter; import java.util.ArrayList; import java.util.List; /** Common backing class for {@linkplain ClassDeclaration} and {@linkplain ClassExpression}. */ public class AClass implements INodeWithSymbol { private final Identifier id; private final List<TypeParameter> typeParameters; private final Expression superClass; private final List<ITypeExpression> superInterfaces; private final ClassBody body; private final List<Decorator> decorators; private int typeSymbol = -1; public AClass( Identifier id, List<TypeParameter> typeParameters, Expression superClass, List<ITypeExpression> superInterfaces, ClassBody body) { this.id = id; this.typeParameters = typeParameters; this.superClass = superClass; this.superInterfaces = superInterfaces; this.body = body; this.decorators = new ArrayList<Decorator>(); } public Identifier getId() { return id; } public boolean hasId() { return id != null; } public List<TypeParameter> getTypeParameters() { return typeParameters; } public boolean hasTypeParameters() { return !typeParameters.isEmpty(); } public Expression getSuperClass() { return superClass; } public boolean hasSuperClass() { return superClass != null; } public List<ITypeExpression> getSuperInterfaces() { return superInterfaces; } public ClassBody getBody() { return body; } public void addDecorators(List<Decorator> decorators) { this.decorators.addAll(decorators); } public List<Decorator> getDecorators() { return decorators; } @Override public int getSymbol() { return typeSymbol; } @Override public void setSymbol(int symbol) { this.typeSymbol = symbol; } }
1,901
21.915663
95
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/TemplateLiteral.java
package com.semmle.js.ast; import java.util.ArrayList; import java.util.List; /** * A template literal such as <code>`Hello, ${name}!`</code>. * * <p>In SpiderMonkey parlance, a template literal is composed of <i>quasis</i> (the constant parts * of the template literal) and <i>expressions</i> (the variable parts). In the example, <code> * "Hello, "</code> and <code>"!"</code> are the quasis, and <code>name</code> is the single * expression. */ public class TemplateLiteral extends Expression { private final List<Expression> expressions; private final List<TemplateElement> quasis; private final List<Expression> children; public TemplateLiteral( SourceLocation loc, List<Expression> expressions, List<TemplateElement> quasis) { super("TemplateLiteral", loc); this.expressions = expressions; this.quasis = quasis; this.children = mergeChildren(expressions, quasis); } /* * Merge quasis and expressions into a single array in textual order. * Also filter out the empty constant strings that the parser likes to generate. */ private List<Expression> mergeChildren( List<Expression> expressions, List<TemplateElement> quasis) { List<Expression> children = new ArrayList<Expression>(); int j = 0, n = quasis.size(); for (int i = 0, m = expressions.size(); i < m; ++i) { Expression expr = expressions.get(i); for (; j < n; ++j) { TemplateElement quasi = quasis.get(j); if (quasi.getLoc().getStart().compareTo(expr.getLoc().getStart()) > 0) break; if (!quasi.getRaw().isEmpty()) children.add(quasi); } children.add(expr); } for (; j < n; ++j) { TemplateElement quasi = quasis.get(j); if (!quasi.getRaw().isEmpty()) children.add(quasi); } return children; } @Override public <Q, A> A accept(Visitor<Q, A> v, Q q) { return v.visit(this, q); } /** The expressions in this template. */ public List<Expression> getExpressions() { return expressions; } /** The template elements in this template. */ public List<TemplateElement> getQuasis() { return quasis; } /** All expressions and template elements in this template, in lexical order. */ public List<Expression> getChildren() { return children; } }
2,293
30
99
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/AFunctionExpression.java
package com.semmle.js.ast; import com.semmle.ts.ast.DecoratorList; import com.semmle.ts.ast.ITypeExpression; import com.semmle.ts.ast.TypeParameter; import com.semmle.util.data.IntList; import java.util.List; /** * A function expression, which may be either an {@link ArrowFunctionExpression} or a normal {@link * FunctionExpression}. */ public abstract class AFunctionExpression extends Expression implements IFunction { private final AFunction<? extends Node> fn; private int symbol = -1; private int declaredSignature = -1; public AFunctionExpression( String type, SourceLocation loc, Identifier id, List<Expression> params, Node body, Boolean generator, Boolean async, List<TypeParameter> typeParameters, List<ITypeExpression> parameterTypes, List<DecoratorList> parameterDecorators, ITypeExpression returnType, ITypeExpression thisParameterType, IntList optionalParameterIndices) { super(type, loc); this.fn = new AFunction<Node>( id, params, body, generator == Boolean.TRUE, async == Boolean.TRUE, typeParameters, parameterTypes, parameterDecorators, returnType, thisParameterType, optionalParameterIndices); } public AFunctionExpression(String type, SourceLocation loc, AFunction<? extends Node> fn) { super(type, loc); this.fn = fn; } @Override public Identifier getId() { return fn.getId(); } @Override public List<IPattern> getParams() { return fn.getParams(); } @Override public boolean hasDefault(int i) { return fn.hasDefault(i); } @Override public Expression getDefault(int i) { return fn.getDefault(i); } @Override public IPattern getRest() { return fn.getRest(); } @Override public Node getBody() { return fn.getBody(); } @Override public boolean hasRest() { return fn.hasRest(); } public boolean hasId() { return fn.hasId(); } public boolean isGenerator() { return fn.isGenerator(); } public boolean isAsync() { return fn.isAsync(); } public List<IPattern> getAllParams() { return fn.getAllParams(); } @Override public List<Expression> getRawParameters() { return fn.getRawParams(); } public ITypeExpression getReturnType() { return fn.getReturnType(); } public boolean hasParameterType(int i) { return fn.hasParameterType(i); } public ITypeExpression getParameterType(int i) { return fn.getParameterType(i); } public List<ITypeExpression> getParameterTypes() { return fn.getParameterTypes(); } public List<TypeParameter> getTypeParameters() { return fn.getTypeParameters(); } public ITypeExpression getThisParameterType() { return fn.getThisParameterType(); } public List<DecoratorList> getParameterDecorators() { return fn.getParameterDecorators(); } @Override public boolean hasDeclareKeyword() { return false; } @Override public int getSymbol() { return symbol; } @Override public void setSymbol(int symbol) { this.symbol = symbol; } @Override public int getDeclaredSignatureId() { return declaredSignature; } @Override public void setDeclaredSignatureId(int id) { declaredSignature = id; } public IntList getOptionalParameterIndices() { return fn.getOptionalParmaeterIndices(); } }
3,510
20.150602
99
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/Decorator.java
package com.semmle.js.ast; public class Decorator extends Expression { private final Expression expression; public Decorator(SourceLocation loc, Expression expression) { super("Decorator", loc); this.expression = expression; } @Override public <C, R> R accept(Visitor<C, R> v, C c) { return v.visit(this, c); } public Expression getExpression() { return expression; } }
406
19.35
63
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/Identifier.java
package com.semmle.js.ast; import com.semmle.ts.ast.INodeWithSymbol; import com.semmle.ts.ast.ITypeExpression; /** * An identifier. * * <p>Identifiers can either be variable declarations (like <code>x</code> in <code>var x;</code>), * variable references (like <code>x</code> in <code>x = 42</code>), property names (like <code>f * </code> in <code>e.f</code>), statement labels (like <code>l</code> in <code>l: while(true); * </code>), or statement label references (like <code>l</code> in <code>break l;</code>). */ public class Identifier extends Expression implements IPattern, ITypeExpression, INodeWithSymbol { private final String name; private int symbol = -1; public Identifier(SourceLocation loc, String name) { super("Identifier", loc); this.name = name; } @Override public <Q, A> A accept(Visitor<Q, A> v, Q q) { return v.visit(this, q); } /** The name of this identifier. */ public String getName() { return name; } @Override public int getSymbol() { return symbol; } @Override public void setSymbol(int symbol) { this.symbol = symbol; } }
1,123
25.139535
99
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/ImportSpecifier.java
package com.semmle.js.ast; /** * An import specifier such as <code>x</code> and <code>y as z</code> in <code> * import { x, y as z } from 'foo';</code>. * * <p>An import specifier has a local name and an imported name; for instance, <code>y as z</code> * has local name <code>z</code> and imported name <code>y</code>, while <code>x</code> has both * local and imported name <code>x</code>. */ public class ImportSpecifier extends Expression { private final Identifier imported, local; public ImportSpecifier(SourceLocation loc, Identifier imported, Identifier local) { this("ImportSpecifier", loc, imported, local); } public ImportSpecifier(String type, SourceLocation loc, Identifier imported, Identifier local) { super(type, loc); this.imported = imported; this.local = local == imported ? new NodeCopier().copy(local) : local; } public Identifier getImported() { return imported; } public Identifier getLocal() { return local; } @Override public <C, R> R accept(Visitor<C, R> v, C c) { return v.visit(this, c); } }
1,084
28.324324
98
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/ComprehensionExpression.java
package com.semmle.js.ast; import java.util.List; /** A comprehension expression. */ public class ComprehensionExpression extends Expression { private final Expression body; private final List<ComprehensionBlock> blocks; private final Expression filter; private final boolean generator; public ComprehensionExpression( SourceLocation loc, Expression body, List<ComprehensionBlock> blocks, Expression filter, Boolean generator) { super("ComprehensionExpression", loc); this.body = body; this.blocks = blocks; this.filter = filter; this.generator = generator == Boolean.TRUE; } @Override public <Q, A> A accept(Visitor<Q, A> v, Q q) { return v.visit(this, q); } /** The body expression of this comprehension. */ public Expression getBody() { return body; } /** The comprehension blocks of this comprehension. */ public List<ComprehensionBlock> getBlocks() { return blocks; } /** Does this comprehension expression have a filter expression? */ public boolean hasFilter() { return filter != null; } /** The filter expression of this comprehension; may be null. */ public Expression getFilter() { return filter; } /** Is this a generator expression? */ public boolean isGenerator() { return generator; } }
1,332
23.236364
69
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/MethodDefinition.java
package com.semmle.js.ast; import java.util.ArrayList; import java.util.List; public class MethodDefinition extends MemberDefinition<FunctionExpression> { public enum Kind { CONSTRUCTOR, METHOD, GET, SET, FUNCTION_CALL_SIGNATURE, CONSTRUCTOR_CALL_SIGNATURE, INDEX_SIGNATURE }; private final Kind kind; private final List<FieldDefinition> parameterFields; public MethodDefinition( SourceLocation loc, int flags, Kind kind, Expression key, FunctionExpression value) { this(loc, flags, kind, key, value, new ArrayList<>()); } public MethodDefinition( SourceLocation loc, int flags, Kind kind, Expression key, FunctionExpression value, List<FieldDefinition> parameterFields) { super("MethodDefinition", loc, flags, key, value); this.kind = kind; this.parameterFields = parameterFields; } public Kind getKind() { return kind; } @Override public boolean isCallSignature() { return kind == Kind.FUNCTION_CALL_SIGNATURE || kind == Kind.CONSTRUCTOR_CALL_SIGNATURE; } @Override public boolean isIndexSignature() { return kind == Kind.INDEX_SIGNATURE; } @Override public boolean isConstructor() { return !isStatic() && !isComputed() && "constructor".equals(getName()); } @Override public boolean isConcrete() { return getValue().getBody() != null; } @Override public <C, R> R accept(Visitor<C, R> v, C c) { return v.visit(this, c); } /** * Returns the parameter fields synthesized for initializing constructor parameters, if this is a * constructor, or an empty list otherwise. * * <p>The index in this list does not correspond to the parameter index, as there can be ordinary * parameters interleaved with parameter fields. */ public List<FieldDefinition> getParameterFields() { return parameterFields; } }
1,897
23.649351
99
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/DestructuringPattern.java
package com.semmle.js.ast; /** An array or object pattern. */ public interface DestructuringPattern extends IPattern {}
121
23.4
57
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/INode.java
package com.semmle.js.ast; /** The common interface implemented by all AST node types. */ public interface INode extends ISourceElement { /** Accept a visitor object. */ public <C, R> R accept(Visitor<C, R> v, C c); /** Return the node's type tag. */ public String getType(); }
288
25.272727
62
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/AssignmentExpression.java
package com.semmle.js.ast; /** An assignment expression such as <code>x = 23</code> or <code>y += 19</code>. */ public class AssignmentExpression extends ABinaryExpression { public AssignmentExpression( SourceLocation loc, String operator, Expression left, Expression right) { super(loc, "AssignmentExpression", operator, left, right); } @Override public <Q, A> A accept(Visitor<Q, A> v, Q q) { return v.visit(this, q); } }
450
29.066667
84
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/VariableDeclarator.java
package com.semmle.js.ast; import com.semmle.ts.ast.ITypeExpression; /** A variable declarator in a variable declaration statement. */ public class VariableDeclarator extends Expression { private final IPattern id; private final Expression init; private final ITypeExpression typeAnnotation; /** * A bitmask of flags defined in {@linkplain DeclarationFlags}. * * <p>Currently only {@link DeclarationFlags#definiteAssignmentAssertion} may be set on variable * declarators. */ private final int flags; public VariableDeclarator( SourceLocation loc, IPattern id, Expression init, ITypeExpression typeAnnotation, int flags) { super("VariableDeclarator", loc); this.id = id; this.init = init; this.typeAnnotation = typeAnnotation; this.flags = flags; } @Override public <Q, A> A accept(Visitor<Q, A> v, Q q) { return v.visit(this, q); } /** The declared variable(s). */ public IPattern getId() { return id; } /** Does this variable declarator have an initializing expression? */ public boolean hasInit() { return init != null; } /** The initializing expression of this variable declarator; may be null. */ public Expression getInit() { return init; } /** The TypeScript type annotation for this variable; may be null. */ public ITypeExpression getTypeAnnotation() { return typeAnnotation; } /** Returns the modifiers set on this variable, as defined by {@link DeclarationFlags}. */ public int getFlags() { return this.flags; } }
1,549
25.724138
100
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/CallExpression.java
package com.semmle.js.ast; import com.semmle.ts.ast.ITypeExpression; import java.util.List; /** A function call expression such as <code>f(1, 1)</code>. */ public class CallExpression extends InvokeExpression { public CallExpression( SourceLocation loc, Expression callee, List<ITypeExpression> typeArguments, List<Expression> arguments, Boolean optional, Boolean onOptionalChain) { super("CallExpression", loc, callee, typeArguments, arguments, optional, onOptionalChain); } @Override public <Q, A> A accept(Visitor<Q, A> v, Q q) { return v.visit(this, q); } }
619
25.956522
94
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/DebuggerStatement.java
package com.semmle.js.ast; /** A debugger statement <code>debugger;</code>. */ public class DebuggerStatement extends Statement { public DebuggerStatement(SourceLocation loc) { super("DebuggerStatement", loc); } @Override public <Q, A> A accept(Visitor<Q, A> v, Q q) { return v.visit(this, q); } }
318
21.785714
51
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/ImportNamespaceSpecifier.java
package com.semmle.js.ast; /** * A namespace import specifier such as <code>* as foo</code> in <code>import * as foo from 'foo'; * </code>. * * <p>Namespace import specifiers do not have an imported name. */ public class ImportNamespaceSpecifier extends ImportSpecifier { public ImportNamespaceSpecifier(SourceLocation loc, Identifier local) { super("ImportNamespaceSpecifier", loc, null, local); } @Override public <C, R> R accept(Visitor<C, R> v, C c) { return v.visit(this, c); } }
510
25.894737
98
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/Node.java
package com.semmle.js.ast; /** Common superclass of all AST node types. */ public abstract class Node extends SourceElement implements INode { private final String type; public Node(String type, SourceLocation loc) { super(loc); this.type = type; } public final String getType() { return type; } }
323
19.25
67
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/SwitchStatement.java
package com.semmle.js.ast; import java.util.List; /** A switch statement. */ public class SwitchStatement extends Statement { private final Expression discriminant; private final List<SwitchCase> cases; public SwitchStatement(SourceLocation loc, Expression discriminant, List<SwitchCase> cases) { super("SwitchStatement", loc); this.discriminant = discriminant; this.cases = cases; } @Override public <Q, A> A accept(Visitor<Q, A> v, Q q) { return v.visit(this, q); } /** The expression whose value is examined. */ public Expression getDiscriminant() { return discriminant; } /** The cases in this switch statement. */ public List<SwitchCase> getCases() { return cases; } }
730
22.580645
95
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/LabeledStatement.java
package com.semmle.js.ast; /** A labeled statement. */ public class LabeledStatement extends Statement { private final Identifier label; private final Statement body; public LabeledStatement(SourceLocation loc, Identifier label, Statement body) { super("LabeledStatement", loc); this.label = label; this.body = body; } @Override public <Q, A> A accept(Visitor<Q, A> v, Q q) { return v.visit(this, q); } /** The label of the labeled statement. */ public Identifier getLabel() { return label; } /** The statement wrapped by this labeled statement. */ public Statement getBody() { return body; } }
650
21.448276
81
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/ForOfStatement.java
package com.semmle.js.ast; /** * A for-of statement such as * * <pre> * for (var elt of array) * sum += elt; * </pre> */ public class ForOfStatement extends EnhancedForStatement { private boolean isAwait; public ForOfStatement(SourceLocation loc, Node left, Expression right, Statement body) { super("ForOfStatement", loc, left, right, body); } public void setAwait(boolean isAwait) { this.isAwait = isAwait; } public boolean isAwait() { return isAwait; } @Override public <Q, A> A accept(Visitor<Q, A> v, Q q) { return v.visit(this, q); } }
592
18.129032
90
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/IFunction.java
package com.semmle.js.ast; import com.semmle.ts.ast.DecoratorList; import com.semmle.ts.ast.INodeWithSymbol; import com.semmle.ts.ast.ITypeExpression; import com.semmle.ts.ast.ITypedAstNode; import com.semmle.ts.ast.TypeParameter; import com.semmle.util.data.IntList; import java.util.List; /** A function declaration or expression. */ public interface IFunction extends IStatementContainer, INodeWithSymbol, ITypedAstNode { /** The function name; may be null for function expressions. */ public Identifier getId(); /** The parameters of the function, not including the rest parameter. */ public List<IPattern> getParams(); /** The parameters of the function, including the rest parameter. */ public List<IPattern> getAllParams(); /** Does the i'th parameter have a default expression? */ public boolean hasDefault(int i); /** The default expression for the i'th parameter; may be null. */ public Expression getDefault(int i); /** The rest parameter of this function; may be null. */ public IPattern getRest(); /** * The body of the function; usually a {@link BlockStatement}, but may be an {@link Expression} * for function expressions. */ public Node getBody(); /** Does this function have a rest parameter? */ public boolean hasRest(); /** Is this function a generator function? */ public boolean isGenerator(); /** * The raw parameters of this function; parameters with defaults are represented as {@link * AssignmentPattern}s and the rest parameter (if any) as a {@link RestElement}. */ public List<Expression> getRawParameters(); /** Is this function an asynchronous function? */ public boolean isAsync(); /** The return type of the function, if any. */ public ITypeExpression getReturnType(); /** Does the i'th parameter have a type annotation? */ public boolean hasParameterType(int i); /** The type annotation for the i'th parameter; may be null. */ public ITypeExpression getParameterType(int i); public List<TypeParameter> getTypeParameters(); public ITypeExpression getThisParameterType(); public List<DecoratorList> getParameterDecorators(); public boolean hasDeclareKeyword(); /** * Gets the type signature of this function as determined by the TypeScript compiler, or -1 if no * call signature was extracted. * * <p>The ID refers to a signature in a table that is extracted on a per-project basis, and the * meaning of this type ID is not available at the AST level. */ public int getDeclaredSignatureId(); public void setDeclaredSignatureId(int id); public IntList getOptionalParameterIndices(); }
2,644
31.256098
99
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/LetStatement.java
package com.semmle.js.ast; import java.util.List; /** An old-style let statement of the form <code>let(vardecls) stmt</code>. */ public class LetStatement extends Statement { private final List<VariableDeclarator> head; private final Statement body; public LetStatement(SourceLocation loc, List<VariableDeclarator> head, Statement body) { super("LetStatement", loc); this.head = head; this.body = body; } @Override public <C, R> R accept(Visitor<C, R> v, C c) { return v.visit(this, c); } public List<VariableDeclarator> getHead() { return head; } public Statement getBody() { return body; } }
646
21.310345
90
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/ExportSpecifier.java
package com.semmle.js.ast; /** * An export specifier in an {@linkplain ExportNamedDeclaration}; may either be a plain identifier * <code>x</code>, or a rename export <code>x as y</code>. */ public class ExportSpecifier extends Expression { private final Identifier local, exported; public ExportSpecifier(SourceLocation loc, Identifier local, Identifier exported) { this("ExportSpecifier", loc, local, exported); } public ExportSpecifier(String type, SourceLocation loc, Identifier local, Identifier exported) { super(type, loc); this.local = local; this.exported = exported == local ? new NodeCopier().copy(exported) : exported; } public Identifier getLocal() { return local; } public Identifier getExported() { return exported; } @Override public <C, R> R accept(Visitor<C, R> v, C c) { return v.visit(this, c); } }
879
25.666667
98
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/VariableDeclaration.java
package com.semmle.js.ast; import com.semmle.js.extractor.ExtractorConfig.ECMAVersion; import java.util.List; /** * A variable declaration statement containing one or more {@link VariableDeclarator} expressions. */ public class VariableDeclaration extends Statement { private final String kind; private final List<VariableDeclarator> declarations; private final boolean hasDeclareKeyword; public VariableDeclaration( SourceLocation loc, String kind, List<VariableDeclarator> declarations, boolean hasDeclareKeyword) { super("VariableDeclaration", loc); this.kind = kind; this.declarations = declarations; this.hasDeclareKeyword = hasDeclareKeyword; } @Override public <Q, A> A accept(Visitor<Q, A> v, Q q) { return v.visit(this, q); } /** * The kind of this variable declaration statement; one of <code>"var"</code>, <code>"let"</code> * or <code>"const"</code>. */ public String getKind() { return kind; } /** * Is this a block-scoped declaration? * * <p>Note that <code>const</code> declarations are function-scoped pre-ECMAScript 2015. */ public boolean isBlockScoped(ECMAVersion ecmaVersion) { return "let".equals(kind) || ecmaVersion.compareTo(ECMAVersion.ECMA2015) >= 0 && "const".equals(kind); } /** The declarations in this declaration statement. */ public List<VariableDeclarator> getDeclarations() { return declarations; } public boolean hasDeclareKeyword() { return hasDeclareKeyword; } }
1,537
25.982456
99
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/TaggedTemplateExpression.java
package com.semmle.js.ast; import com.semmle.ts.ast.ITypeExpression; import java.util.Collections; import java.util.List; /** A tagged template expression. */ public class TaggedTemplateExpression extends Expression { private final Expression tag; private final TemplateLiteral quasi; private final List<ITypeExpression> typeArguments; public TaggedTemplateExpression( SourceLocation loc, Expression tag, TemplateLiteral quasi, List<ITypeExpression> typeArguments) { super("TaggedTemplateExpression", loc); this.tag = tag; this.quasi = quasi; this.typeArguments = typeArguments; } public TaggedTemplateExpression(SourceLocation loc, Expression tag, TemplateLiteral quasi) { this(loc, tag, quasi, Collections.emptyList()); } @Override public <Q, A> A accept(Visitor<Q, A> v, Q q) { return v.visit(this, q); } /** The tagging expression. */ public Expression getTag() { return tag; } /** The tagged template literal. */ public TemplateLiteral getQuasi() { return quasi; } /** The type arguments, or an empty list if there are none. */ public List<ITypeExpression> getTypeArguments() { return typeArguments; } }
1,215
24.333333
94
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/ABinaryExpression.java
package com.semmle.js.ast; /** * An expression involving an operator and two operands; may be an {@link AssignmentExpression}, a * {@link BinaryExpression} or a {@link LogicalExpression}. */ public abstract class ABinaryExpression extends Expression { private final String operator; private final Expression left, right; public ABinaryExpression( SourceLocation loc, String type, String operator, Expression left, Expression right) { super(type, loc); this.operator = operator; this.left = left; this.right = right; } public String getOperator() { return operator; } public Expression getLeft() { return left; } public Expression getRight() { return right; } }
723
22.354839
98
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/ArrowFunctionExpression.java
package com.semmle.js.ast; import com.semmle.ts.ast.ITypeExpression; import com.semmle.ts.ast.TypeParameter; import com.semmle.util.data.IntList; import java.util.Collections; import java.util.List; /** An arrow function expression such as <code>(x) =&gt; x*x</code>. */ public class ArrowFunctionExpression extends AFunctionExpression { public ArrowFunctionExpression( SourceLocation loc, List<Expression> params, Node body, Boolean generator, Boolean async) { super( "ArrowFunctionExpression", loc, null, params, body, generator, async, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), null, null, AFunction.noOptionalParams); } public ArrowFunctionExpression( SourceLocation loc, List<Expression> params, Node body, Boolean generator, Boolean async, List<TypeParameter> typeParameters, List<ITypeExpression> parameterTypes, ITypeExpression returnType, IntList optionalParameterIndices) { super( "ArrowFunctionExpression", loc, null, params, body, generator, async, typeParameters, parameterTypes, Collections.emptyList(), returnType, null, optionalParameterIndices); } @Override public <Q, A> A accept(Visitor<Q, A> v, Q q) { return v.visit(this, q); } }
1,482
23.716667
97
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/ExportNamespaceSpecifier.java
package com.semmle.js.ast; /** * A namespace export specifier such as <code>* as foo</code> in <code>export * as foo from 'foo'; * </code>. */ public class ExportNamespaceSpecifier extends ExportSpecifier { public ExportNamespaceSpecifier(SourceLocation loc, Identifier exported) { super("ExportNamespaceSpecifier", loc, null, exported); } @Override public <C, R> R accept(Visitor<C, R> v, C c) { return v.visit(this, c); } }
449
25.470588
98
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/IPattern.java
package com.semmle.js.ast; /** * A marker interface encompassing variables ({@link Identifier}) and complex patterns used in * destructuring assignments ({@link ArrayPattern}, {@link ObjectPattern}). */ public interface IPattern extends INode {}
250
30.375
94
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/ForStatement.java
package com.semmle.js.ast; /** * A for statement such as * * <pre> * for (var i=10; i&gt;0; i--) * console.log(i); * console.log("Boom!"); * </pre> */ public class ForStatement extends Loop { private final Node init; private final Expression test, update; public ForStatement( SourceLocation loc, Node init, Expression test, Expression update, Statement body) { super("ForStatement", loc, body); this.init = init; this.test = test; this.update = update; } @Override public <Q, A> A accept(Visitor<Q, A> v, Q q) { return v.visit(this, q); } /** Does this for statement have an initialization part? */ public boolean hasInit() { return init != null; } /** * The initialization part of this for statement; may be a {@link VariableDeclaration} statement, * an {@link Expression}, or {@literal null}. */ public Node getInit() { return init; } /** Does this for statement have a test? */ public boolean hasTest() { return test != null; } /** The test expression of this for statement; may be null. */ public Expression getTest() { return test; } /** Does this for statement have an update expression? */ public boolean hasUpdate() { return update != null; } /** The update expression of this for statement; may be null. */ public Expression getUpdate() { return update; } @Override public Node getContinueTarget() { if (update != null) return update; if (test != null) return test; return body; } }
1,540
21.333333
99
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/XMLFilterExpression.java
package com.semmle.js.ast; public class XMLFilterExpression extends Expression { final Expression left, right; public XMLFilterExpression(SourceLocation loc, Expression left, Expression right) { super("XMLFilterExpression", loc); this.left = left; this.right = right; } public Expression getLeft() { return left; } public Expression getRight() { return right; } @Override public <C, R> R accept(Visitor<C, R> v, C c) { return v.visit(this, c); } }
497
18.92
85
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/BindExpression.java
package com.semmle.js.ast; public class BindExpression extends Expression { private final Expression object, callee; public BindExpression(SourceLocation loc, Expression object, Expression callee) { super("BindExpression", loc); this.object = object; this.callee = callee; } public boolean hasObject() { return object != null; } public Expression getObject() { return object; } public Expression getCallee() { return callee; } @Override public <C, R> R accept(Visitor<C, R> v, C c) { return v.visit(this, c); } }
571
18.724138
83
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/ExpressionStatement.java
package com.semmle.js.ast; /** An expression statement such as <code>alert("Hi!");</code>. */ public class ExpressionStatement extends Statement { private final Expression expression; public ExpressionStatement(SourceLocation loc, Expression expression) { super("ExpressionStatement", loc); this.expression = expression; } @Override public <Q, A> A accept(Visitor<Q, A> v, Q q) { return v.visit(this, q); } /** The expression wrapped by this expression statement. */ public Expression getExpression() { return expression; } }
564
24.681818
73
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/Program.java
package com.semmle.js.ast; import com.semmle.ts.ast.INodeWithSymbol; import java.util.List; /** A top-level program entity forming the root of an AST. */ public class Program extends Node implements IStatementContainer, INodeWithSymbol { private final List<Statement> body; private final String sourceType; private int symbolId = -1; public Program(SourceLocation loc, List<Statement> body, String sourceType) { super("Program", loc); this.body = body; this.sourceType = sourceType; } @Override public <Q, A> A accept(Visitor<Q, A> v, Q q) { return v.visit(this, q); } /** The statements in this program. */ public List<Statement> getBody() { return body; } public String getSourceType() { return sourceType; } public int getSymbol() { return this.symbolId; } public void setSymbol(int symbolId) { this.symbolId = symbolId; } }
902
21.575
83
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/ISourceElement.java
package com.semmle.js.ast; /** A source code element potentially associated with a location. */ public interface ISourceElement { /** Get the source location of this element; may be null. */ public SourceLocation getLoc(); }
230
27.875
68
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/BreakStatement.java
package com.semmle.js.ast; /** * A break statement either with a label (<code>break outer;</code>) or without (<code>break;</code> * ). */ public class BreakStatement extends JumpStatement { public BreakStatement(SourceLocation loc, Identifier label) { super("BreakStatement", loc, label); } @Override public <Q, A> A accept(Visitor<Q, A> v, Q q) { return v.visit(this, q); } }
401
22.647059
100
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/Loop.java
package com.semmle.js.ast; /** * A loop statement, that is, a {@link WhileStatement}, a {@link DoWhileStatement}, a {@link * ForStatement}, or a {@link EnhancedForStatement}. */ public abstract class Loop extends Statement { protected final Statement body; public Loop(String type, SourceLocation loc, Statement body) { super(type, loc); this.body = body; } /** The loop body. */ public final Statement getBody() { return body; } /** * The child node of this loop where execution resumes after a <code>continue</code> statement. */ public abstract Node getContinueTarget(); }
617
23.72
97
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/Literal.java
package com.semmle.js.ast; import com.semmle.jcorn.TokenType; import com.semmle.ts.ast.ITypeExpression; /** * A literal constant. * * <p>A <tt>null</tt> literal may occur as a TypeScript type annotation - other literals are always * expressions. */ public class Literal extends Expression implements ITypeExpression { private final TokenType tokenType; private final Object value; private final String raw; public Literal(SourceLocation loc, TokenType tokenType, Object value) { super("Literal", loc); // for numbers, check whether they can be represented as integers if (value instanceof Double) { Double dvalue = (Double) value; if (dvalue >= Long.MIN_VALUE && dvalue <= Long.MAX_VALUE && (dvalue % 1) == 0) value = dvalue.longValue(); } else if (value instanceof CharSequence) { value = value.toString(); } this.tokenType = tokenType; this.value = value; this.raw = getLoc().getSource(); } @Override public <Q, A> A accept(Visitor<Q, A> v, Q q) { return v.visit(this, q); } /** The type of the token corresponding to this literal. */ public TokenType getTokenType() { return tokenType; } /** * The value of this literal; may be null if this is a null literal or a literal whose value * cannot be represented by the parser. */ public Object getValue() { return value; } /** The source text of this literal. */ public String getRaw() { return raw; } /** Is this a regular expression literal? */ public boolean isRegExp() { return tokenType == TokenType.regexp; } /** Is this a string literal? */ public boolean isStringLiteral() { return tokenType == TokenType.string; } /** The value of this literal expressed as a string. */ public String getStringValue() { // regular expressions may have a null value; use the raw value instead if (isRegExp()) return raw; return String.valueOf(value); } /** Is the value of this literal falsy? */ public boolean isFalsy() { if (isRegExp()) return false; return value == null || value instanceof Number && ((Number) value).intValue() == 0 || value == Boolean.FALSE || value instanceof String && ((String) value).isEmpty(); } /** Is the value of this literal truthy? */ public boolean isTruthy() { return !isFalsy(); } }
2,380
26.056818
99
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/ThisExpression.java
package com.semmle.js.ast; /** A <code>this</code> expression. */ public class ThisExpression extends Expression { public ThisExpression(SourceLocation loc) { super("ThisExpression", loc); } @Override public <Q, A> A accept(Visitor<Q, A> v, Q q) { return v.visit(this, q); } }
297
20.285714
48
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/ExportDefaultDeclaration.java
package com.semmle.js.ast; /** * A default export declaration of the form * * <pre> * export default function f() { return 23; }; * </pre> * * or * * <pre> * export default 42; * </pre> */ public class ExportDefaultDeclaration extends ExportDeclaration { /** * Either an {@linkplain Expression} or a {@linkplain FunctionDeclaration} or a {@linkplain * ClassDeclaration}. */ private final Node declaration; public ExportDefaultDeclaration(SourceLocation loc, Node declaration) { super("ExportDefaultDeclaration", loc); this.declaration = declaration; } public Node getDeclaration() { return declaration; } @Override public <C, R> R accept(Visitor<C, R> v, C c) { return v.visit(this, c); } }
754
19.405405
93
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/WhileStatement.java
package com.semmle.js.ast; /** A while loop. */ public class WhileStatement extends Loop { private final Expression test; public WhileStatement(SourceLocation loc, Expression test, Statement body) { super("WhileStatement", loc, body); this.test = test; } @Override public <Q, A> A accept(Visitor<Q, A> v, Q q) { return v.visit(this, q); } /** The test expression of this while loop. */ public Expression getTest() { return test; } @Override public Node getContinueTarget() { return test; } }
541
19.074074
78
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/Position.java
package com.semmle.js.ast; /** A source position identifying a single character. */ public class Position implements Comparable<Position> { private final int line, column, offset; public Position(int line, int column, int offset) { this.line = line; this.column = column; this.offset = offset; } /** The line number (1-based) of this position. */ public int getLine() { return line; } /** The column number (0-based) of this position. */ public int getColumn() { return column; } /** * The offset (0-based) of this position from the start of the file, that is, the number of * characters that precede it. */ public int getOffset() { return offset; } @Override public int compareTo(Position that) { if (this.line < that.line) return -1; if (this.line == that.line) if (this.column < that.column) return -1; else if (this.column == that.column) return 0; else return 1; return 1; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + column; result = prime * result + line; return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Position other = (Position) obj; if (column != other.column) return false; if (line != other.line) return false; return true; } @Override public String toString() { return line + ":" + column; } }
1,559
22.636364
93
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/FunctionDeclaration.java
package com.semmle.js.ast; import com.semmle.ts.ast.DecoratorList; import com.semmle.ts.ast.ITypeExpression; import com.semmle.ts.ast.TypeParameter; import com.semmle.util.data.IntList; import java.util.Collections; import java.util.List; /** * A function declaration such as * * <pre> * function add(x, y) { * return x+y; * } * </pre> */ public class FunctionDeclaration extends Statement implements IFunction { private final AFunction<? extends Node> fn; private final boolean hasDeclareKeyword; private int symbol = -1; private int staticType = -1; private int declaredSignature = -1; public FunctionDeclaration( SourceLocation loc, Identifier id, List<Expression> params, Node body, boolean generator, boolean async) { this( loc, new AFunction<>( id, params, body, generator, async, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), null, null, AFunction.noOptionalParams), false); } public FunctionDeclaration( SourceLocation loc, Identifier id, List<Expression> params, Node body, boolean generator, boolean async, boolean hasDeclareKeyword, List<TypeParameter> typeParameters, List<ITypeExpression> parameterTypes, ITypeExpression returnType, ITypeExpression thisParameterType, IntList optionalParameterIndices) { this( loc, new AFunction<>( id, params, body, generator, async, typeParameters, parameterTypes, Collections.emptyList(), returnType, thisParameterType, optionalParameterIndices), hasDeclareKeyword); } private FunctionDeclaration(SourceLocation loc, AFunction<Node> fn, boolean hasDeclareKeyword) { super("FunctionDeclaration", loc); this.fn = fn; this.hasDeclareKeyword = hasDeclareKeyword; } @Override public <Q, A> A accept(Visitor<Q, A> v, Q q) { return v.visit(this, q); } public FunctionExpression asFunctionExpression() { return new FunctionExpression(getLoc(), fn); } @Override public Identifier getId() { return fn.getId(); } @Override public List<IPattern> getParams() { return fn.getParams(); } @Override public boolean hasDefault(int i) { return fn.hasDefault(i); } @Override public Expression getDefault(int i) { return fn.getDefault(i); } @Override public IPattern getRest() { return fn.getRest(); } @Override public Node getBody() { return fn.getBody(); } @Override public boolean hasRest() { return fn.hasRest(); } public boolean hasId() { return fn.hasId(); } public boolean isGenerator() { return fn.isGenerator(); } public boolean isAsync() { return fn.isAsync(); } public List<IPattern> getAllParams() { return fn.getAllParams(); } @Override public List<Expression> getRawParameters() { return fn.getRawParams(); } public ITypeExpression getReturnType() { return fn.getReturnType(); } @Override public boolean hasParameterType(int i) { return fn.hasParameterType(i); } @Override public ITypeExpression getParameterType(int i) { return fn.getParameterType(i); } public List<ITypeExpression> getParameterTypes() { return fn.getParameterTypes(); } public List<TypeParameter> getTypeParameters() { return fn.getTypeParameters(); } public ITypeExpression getThisParameterType() { return fn.getThisParameterType(); } public List<DecoratorList> getParameterDecorators() { return fn.getParameterDecorators(); } public boolean hasDeclareKeyword() { return hasDeclareKeyword; } @Override public int getSymbol() { return this.symbol; } @Override public void setSymbol(int symbol) { this.symbol = symbol; } @Override public int getStaticTypeId() { return staticType; } @Override public void setStaticTypeId(int id) { staticType = id; } @Override public int getDeclaredSignatureId() { return declaredSignature; } @Override public void setDeclaredSignatureId(int id) { declaredSignature = id; } public IntList getOptionalParameterIndices() { return fn.getOptionalParmaeterIndices(); } }
4,510
19.598174
98
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/ArrayExpression.java
package com.semmle.js.ast; import java.util.List; /** An array expression such as <code>[x, , "hello"]</code>. */ public class ArrayExpression extends Expression { private final List<Expression> elements; public ArrayExpression(SourceLocation loc, List<Expression> elements) { super("ArrayExpression", loc); this.elements = elements; } @Override public <Q, A> A accept(Visitor<Q, A> v, Q q) { return v.visit(this, q); } /** The elements of the array; omitted elements are represented by {@literal null}. */ public List<Expression> getElements() { return elements; } }
607
24.333333
88
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/CatchClause.java
package com.semmle.js.ast; /** A catch clause with or without a guarding expression. */ public class CatchClause extends Statement { private final IPattern param; private final Expression guard; private final BlockStatement body; public CatchClause(SourceLocation loc, IPattern param, Expression guard, BlockStatement body) { super("CatchClause", loc); this.param = param; this.guard = guard; this.body = body; } @Override public <Q, A> A accept(Visitor<Q, A> v, Q q) { return v.visit(this, q); } /** The parameter of the catch clause. */ public IPattern getParam() { return param; } /** Does this catch clause have a guarding expression? */ public boolean hasGuard() { return guard != null; } /** The guarding expression of the catch clause; may be null. */ public Expression getGuard() { return guard; } /** The body of the catch clause. */ public BlockStatement getBody() { return body; } }
977
22.853659
97
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/DynamicImport.java
package com.semmle.js.ast; public class DynamicImport extends Expression { private final Expression source; public DynamicImport(SourceLocation loc, Expression source) { super("DynamicImport", loc); this.source = source; } public Expression getSource() { return source; } @Override public <C, R> R accept(Visitor<C, R> v, C c) { return v.visit(this, c); } }
394
18.75
63
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/ArrayPattern.java
package com.semmle.js.ast; import java.util.ArrayList; import java.util.List; /** An array pattern as in <code>var [x, y] = z;</code>. */ public class ArrayPattern extends Expression implements DestructuringPattern { private final List<Expression> elements, rawElements; private final List<Expression> defaults; private final Expression restPattern; public ArrayPattern(SourceLocation loc, List<Expression> elements) { super("ArrayPattern", loc); this.rawElements = elements; this.elements = new ArrayList<Expression>(elements.size()); this.defaults = new ArrayList<Expression>(elements.size()); Expression rest = null; for (Expression element : elements) { if (element instanceof RestElement) { rest = ((RestElement) element).getArgument(); } else { if (element instanceof AssignmentPattern) { AssignmentPattern assgn = (AssignmentPattern) element; this.defaults.add(assgn.getRight()); this.elements.add(assgn.getLeft()); } else { this.defaults.add(null); this.elements.add(element); } } } this.restPattern = rest; } @Override public <Q, A> A accept(Visitor<Q, A> v, Q q) { return v.visit(this, q); } /** * The element patterns of the array pattern; omitted element patterns are represented by * {@literal null}. */ public List<Expression> getElements() { return elements; } /** The default expressions for the element patterns of the array pattern. */ public List<Expression> getDefaults() { return defaults; } /** Return the rest pattern of this array pattern, if any. */ public Expression getRest() { return restPattern; } /** Does this array pattern have a rest pattern? */ public boolean hasRest() { return restPattern != null; } /** * The raw element patterns of the array pattern; patterns with defaults are represented as {@link * AssignmentPattern}s. */ public List<Expression> getRawElements() { return rawElements; } }
2,060
28.028169
100
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/RestElement.java
package com.semmle.js.ast; /** * A rest element <code>...xs</code> in lvalue position. * * <p>Rest elements can only appear as part of a function's parameter list or in an array pattern; * they are rewritten away by the constructors of {@linkplain AFunction} and {@link ArrayPattern}, * and don't appear in the AST the extractor works on. */ public class RestElement extends Expression implements IPattern { private final Expression argument; public RestElement(SourceLocation loc, Expression argument) { super("RestElement", loc); this.argument = argument; } @Override public <Q, A> A accept(Visitor<Q, A> v, Q q) { return v.visit(this, q); } /** The argument expression of this spread element. */ public Expression getArgument() { return argument; } }
798
27.535714
98
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/YieldExpression.java
package com.semmle.js.ast; /** A yield expression. */ public class YieldExpression extends Expression { private final Expression argument; private final boolean delegating; public YieldExpression(SourceLocation loc, Expression argument, Boolean delegating) { super("YieldExpression", loc); this.argument = argument; this.delegating = delegating == Boolean.TRUE; } @Override public <Q, A> A accept(Visitor<Q, A> v, Q q) { return v.visit(this, q); } /** The argument of this yield expression. */ public Expression getArgument() { return argument; } /** Is this a delegating yield expression? */ public boolean isDelegating() { return delegating; } }
703
23.275862
87
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/ParenthesizedExpression.java
package com.semmle.js.ast; /** A parenthesized expression. */ public class ParenthesizedExpression extends Expression { private final Expression expression; public ParenthesizedExpression(SourceLocation loc, Expression expression) { super("ParenthesizedExpression", loc); this.expression = expression; } @Override public <Q, A> A accept(Visitor<Q, A> v, Q q) { return v.visit(this, q); } /** The expression between parentheses. */ public Expression getExpression() { return expression; } @Override public Expression stripParens() { return expression.stripParens(); } }
618
21.925926
77
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/BlockStatement.java
package com.semmle.js.ast; import java.util.List; /** A block statement such as <code>{ console.log("Hi"); }</code>. */ public class BlockStatement extends Statement { private final List<Statement> body; public BlockStatement(SourceLocation loc, List<Statement> body) { super("BlockStatement", loc); this.body = body; } @Override public <Q, A> A accept(Visitor<Q, A> v, Q q) { return v.visit(this, q); } /** The statements in the block. */ public List<Statement> getBody() { return body; } }
531
21.166667
69
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/WithStatement.java
package com.semmle.js.ast; /** A with statement. */ public class WithStatement extends Statement { private final Expression object; private final Statement body; public WithStatement(SourceLocation loc, Expression object, Statement body) { super("WithStatement", loc); this.object = object; this.body = body; } @Override public <Q, A> A accept(Visitor<Q, A> v, Q q) { return v.visit(this, q); } /** The expression put into the context chain by this with statement. */ public Expression getObject() { return object; } /** The body of this with statement. */ public Statement getBody() { return body; } }
658
21.724138
79
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/XMLQualifiedIdentifier.java
package com.semmle.js.ast; public class XMLQualifiedIdentifier extends Expression { final Expression left, right; final boolean computed; public XMLQualifiedIdentifier( SourceLocation loc, Expression left, Expression right, boolean computed) { super("XMLQualifiedIdentifier", loc); this.left = left; this.right = right; this.computed = computed; } public Expression getLeft() { return left; } public Expression getRight() { return right; } public boolean isComputed() { return computed; } @Override public <C, R> R accept(Visitor<C, R> v, C c) { return v.visit(this, c); } }
645
19.1875
80
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/Chainable.java
package com.semmle.js.ast; /** A chainable expression, such as a member access or function call. */ public interface Chainable { /** Is this step of the chain optional? */ abstract boolean isOptional(); /** Is this on an optional chain? */ abstract boolean isOnOptionalChain(); /** * Returns true if a chainable node is on an optional chain. * * @param optional true if the node in question is itself optional (has the ?. token) * @param base the calle or base of the optional access */ public static boolean isOnOptionalChain(boolean optional, Expression base) { return optional || base instanceof Chainable && ((Chainable) base).isOnOptionalChain(); } }
692
32
91
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/IStatementContainer.java
package com.semmle.js.ast; /** A statement container, that is, either a {@link Program} or a {@link IFunction}. */ public interface IStatementContainer extends INode {}
170
33.2
87
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/UpdateExpression.java
package com.semmle.js.ast; /** An increment or decrement expression. */ public class UpdateExpression extends Expression { private final String operator; private final Expression argument; private final boolean prefix; public UpdateExpression( SourceLocation loc, String operator, Expression argument, Boolean prefix) { super("UpdateExpression", loc); this.operator = operator; this.argument = argument; this.prefix = prefix == Boolean.TRUE; } @Override public <Q, A> A accept(Visitor<Q, A> v, Q q) { return v.visit(this, q); } /** The operator of this expression. */ public String getOperator() { return operator; } /** The argument of this expression. */ public Expression getArgument() { return argument; } /** Is this a prefix increment or decrement expression? */ public boolean isPrefix() { return prefix; } }
894
23.189189
81
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/LetExpression.java
package com.semmle.js.ast; import java.util.List; /** An old-style let expression of the form <code>let (vardecls) expr</code>. */ public class LetExpression extends Expression { private final List<VariableDeclarator> head; private final Expression body; public LetExpression(SourceLocation loc, List<VariableDeclarator> head, Expression body) { super("LetExpression", loc); this.head = head; this.body = body; } @Override public <C, R> R accept(Visitor<C, R> v, C c) { return v.visit(this, c); } public List<VariableDeclarator> getHead() { return head; } public Expression getBody() { return body; } }
655
21.62069
92
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/ThrowStatement.java
package com.semmle.js.ast; /** A <code>throw</code> statement. */ public class ThrowStatement extends Statement { private final Expression argument; public ThrowStatement(SourceLocation loc, Expression argument) { super("ThrowStatement", loc); this.argument = argument; } @Override public <Q, A> A accept(Visitor<Q, A> v, Q q) { return v.visit(this, q); } /** The thrown expression. */ public Expression getArgument() { return argument; } }
479
20.818182
66
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/DefaultVisitor.java
package com.semmle.js.ast; import com.semmle.js.ast.jsx.IJSXAttribute; import com.semmle.js.ast.jsx.IJSXExpression; import com.semmle.js.ast.jsx.IJSXName; import com.semmle.js.ast.jsx.JSXAttribute; import com.semmle.js.ast.jsx.JSXBoundaryElement; import com.semmle.js.ast.jsx.JSXClosingElement; import com.semmle.js.ast.jsx.JSXElement; import com.semmle.js.ast.jsx.JSXEmptyExpression; import com.semmle.js.ast.jsx.JSXExpressionContainer; import com.semmle.js.ast.jsx.JSXIdentifier; import com.semmle.js.ast.jsx.JSXMemberExpression; import com.semmle.js.ast.jsx.JSXNamespacedName; import com.semmle.js.ast.jsx.JSXOpeningElement; import com.semmle.js.ast.jsx.JSXSpreadAttribute; import com.semmle.ts.ast.ArrayTypeExpr; import com.semmle.ts.ast.ConditionalTypeExpr; import com.semmle.ts.ast.DecoratorList; import com.semmle.ts.ast.EnumDeclaration; import com.semmle.ts.ast.EnumMember; import com.semmle.ts.ast.ExportAsNamespaceDeclaration; import com.semmle.ts.ast.ExportWholeDeclaration; import com.semmle.ts.ast.ExpressionWithTypeArguments; import com.semmle.ts.ast.ExternalModuleDeclaration; import com.semmle.ts.ast.ExternalModuleReference; import com.semmle.ts.ast.FunctionTypeExpr; import com.semmle.ts.ast.GenericTypeExpr; import com.semmle.ts.ast.GlobalAugmentationDeclaration; import com.semmle.ts.ast.ImportTypeExpr; import com.semmle.ts.ast.ImportWholeDeclaration; import com.semmle.ts.ast.IndexedAccessTypeExpr; import com.semmle.ts.ast.InferTypeExpr; import com.semmle.ts.ast.InterfaceDeclaration; import com.semmle.ts.ast.InterfaceTypeExpr; import com.semmle.ts.ast.IntersectionTypeExpr; import com.semmle.ts.ast.KeywordTypeExpr; import com.semmle.ts.ast.MappedTypeExpr; import com.semmle.ts.ast.NamespaceDeclaration; import com.semmle.ts.ast.NonNullAssertion; import com.semmle.ts.ast.OptionalTypeExpr; import com.semmle.ts.ast.ParenthesizedTypeExpr; import com.semmle.ts.ast.PredicateTypeExpr; import com.semmle.ts.ast.RestTypeExpr; import com.semmle.ts.ast.TupleTypeExpr; import com.semmle.ts.ast.TypeAliasDeclaration; import com.semmle.ts.ast.TypeAssertion; import com.semmle.ts.ast.TypeExpression; import com.semmle.ts.ast.TypeParameter; import com.semmle.ts.ast.TypeofTypeExpr; import com.semmle.ts.ast.UnaryTypeExpr; import com.semmle.ts.ast.UnionTypeExpr; import com.semmle.util.exception.CatastrophicError; /** * A convenience implementation of {@link Visitor} that provides default implementations of all * visitor methods, and catch-all methods for treating similar classes of AST nodes. */ public class DefaultVisitor<C, R> implements Visitor<C, R> { public R visit(Node nd, C c) { return null; } public R visit(Expression nd, C c) { return visit((Node) nd, c); } public R visit(Statement nd, C c) { return visit((Node) nd, c); } /** Default visitor for type expressions that are not also expressions. */ public R visit(TypeExpression nd, C c) { return visit((Node) nd, c); } public R visit(EnhancedForStatement nd, C c) { return visit((Loop) nd, c); } public R visit(InvokeExpression nd, C c) { return visit((Expression) nd, c); } public R visit(Loop nd, C c) { return visit((Statement) nd, c); } public R visit(IFunction nd, C c) { if (nd instanceof Statement) return visit((Statement) nd, c); else return visit((Expression) nd, c); } @Override public R visit(AssignmentExpression nd, C c) { return visit((Expression) nd, c); } @Override public R visit(AssignmentPattern nd, C c) { // assignment patterns should not appear in the AST, but can do for malformed // programs; the ASTExtractor raises a ParseError in this case, other visitors // should just ignore them return visit(nd.getLeft(), c); } @Override public R visit(BinaryExpression nd, C c) { return visit((Expression) nd, c); } @Override public R visit(BlockStatement nd, C c) { return visit((Statement) nd, c); } @Override public R visit(CallExpression nd, C c) { return visit((InvokeExpression) nd, c); } @Override public R visit(ComprehensionBlock nd, C c) { return visit((Expression) nd, c); } @Override public R visit(ComprehensionExpression nd, C c) { return visit((Expression) nd, c); } @Override public R visit(ExpressionStatement nd, C c) { return visit((Statement) nd, c); } @Override public R visit(FunctionDeclaration nd, C c) { return visit((IFunction) nd, c); } @Override public R visit(Identifier nd, C c) { return visit((Expression) nd, c); } @Override public R visit(Literal nd, C c) { return visit((Expression) nd, c); } @Override public R visit(LogicalExpression nd, C c) { return visit((Expression) nd, c); } @Override public R visit(MemberExpression nd, C c) { return visit((Expression) nd, c); } @Override public R visit(Program nd, C c) { return visit((Node) nd, c); } @Override public R visit(RestElement nd, C q) { throw new CatastrophicError("Rest elements should not appear in the AST."); } @Override public R visit(UnaryExpression nd, C c) { return visit((Expression) nd, c); } @Override public R visit(UpdateExpression nd, C c) { return visit((Expression) nd, c); } @Override public R visit(VariableDeclaration nd, C c) { return visit((Statement) nd, c); } @Override public R visit(VariableDeclarator nd, C c) { return visit((Expression) nd, c); } @Override public R visit(SwitchStatement nd, C c) { return visit((Statement) nd, c); } @Override public R visit(SwitchCase nd, C c) { return visit((Statement) nd, c); } @Override public R visit(ForStatement nd, C c) { return visit((Loop) nd, c); } @Override public R visit(ForInStatement nd, C c) { return visit((EnhancedForStatement) nd, c); } @Override public R visit(ForOfStatement nd, C c) { return visit((EnhancedForStatement) nd, c); } @Override public R visit(Property nd, C c) { return visit((Node) nd, c); } @Override public R visit(ArrayPattern nd, C c) { return visit((Expression) nd, c); } @Override public R visit(IfStatement nd, C c) { return visit((Statement) nd, c); } @Override public R visit(LabeledStatement nd, C c) { return visit((Statement) nd, c); } @Override public R visit(ObjectPattern nd, C c) { return visit((Expression) nd, c); } @Override public R visit(WithStatement nd, C c) { return visit((Statement) nd, c); } @Override public R visit(DoWhileStatement nd, C c) { return visit((Loop) nd, c); } @Override public R visit(WhileStatement nd, C c) { return visit((Loop) nd, c); } @Override public R visit(CatchClause nd, C c) { return visit((Statement) nd, c); } @Override public R visit(TryStatement nd, C c) { return visit((Statement) nd, c); } @Override public R visit(NewExpression nd, C c) { return visit((InvokeExpression) nd, c); } @Override public R visit(ReturnStatement nd, C c) { return visit((Statement) nd, c); } @Override public R visit(ThrowStatement nd, C c) { return visit((Statement) nd, c); } @Override public R visit(SpreadElement nd, C c) { return visit((Expression) nd, c); } @Override public R visit(YieldExpression nd, C c) { return visit((Expression) nd, c); } @Override public R visit(ParenthesizedExpression nd, C c) { return visit((Expression) nd, c); } @Override public R visit(EmptyStatement nd, C c) { return visit((Statement) nd, c); } public R visit(JumpStatement nd, C c) { return visit((Statement) nd, c); } @Override public R visit(BreakStatement nd, C c) { return visit((JumpStatement) nd, c); } @Override public R visit(ContinueStatement nd, C c) { return visit((JumpStatement) nd, c); } public R visit(AFunctionExpression nd, C c) { return visit((IFunction) nd, c); } @Override public R visit(FunctionExpression nd, C c) { return visit((AFunctionExpression) nd, c); } @Override public R visit(ArrowFunctionExpression nd, C c) { return visit((AFunctionExpression) nd, c); } @Override public R visit(DebuggerStatement nd, C c) { return visit((Statement) nd, c); } @Override public R visit(ArrayExpression nd, C c) { return visit((Expression) nd, c); } @Override public R visit(ObjectExpression nd, C c) { return visit((Expression) nd, c); } @Override public R visit(ThisExpression nd, C c) { return visit((Expression) nd, c); } @Override public R visit(ConditionalExpression nd, C c) { return visit((Expression) nd, c); } @Override public R visit(SequenceExpression nd, C c) { return visit((Expression) nd, c); } @Override public R visit(TemplateElement nd, C c) { return visit((Expression) nd, c); } @Override public R visit(TemplateLiteral nd, C c) { return visit((Expression) nd, c); } @Override public R visit(TaggedTemplateExpression nd, C c) { return visit((Expression) nd, c); } @Override public R visit(LetStatement nd, C c) { return visit((Statement) nd, c); } @Override public R visit(LetExpression nd, C c) { return visit((Expression) nd, c); } @Override public R visit(ClassDeclaration nd, C c) { return visit((Statement) nd, c); } @Override public R visit(ClassExpression nd, C c) { return visit((Expression) nd, c); } @Override public R visit(ClassBody nd, C c) { return visit((Node) nd, c); } public R visit(MemberDefinition<?> nd, C c) { return visit((Node) nd, c); } @Override public R visit(MethodDefinition nd, C c) { return visit((MemberDefinition<FunctionExpression>) nd, c); } @Override public R visit(FieldDefinition nd, C c) { return visit((MemberDefinition<Expression>) nd, c); } @Override public R visit(Super nd, C c) { return visit((Expression) nd, c); } @Override public R visit(MetaProperty nd, C c) { return visit((Expression) nd, c); } public R visit(ExportDeclaration nd, C c) { return visit((Statement) nd, c); } @Override public R visit(ExportAllDeclaration nd, C c) { return visit((ExportDeclaration) nd, c); } @Override public R visit(ExportDefaultDeclaration nd, C c) { return visit((ExportDeclaration) nd, c); } @Override public R visit(ExportNamedDeclaration nd, C c) { return visit((ExportDeclaration) nd, c); } @Override public R visit(ExportSpecifier nd, C c) { return visit((Expression) nd, c); } @Override public R visit(ExportDefaultSpecifier nd, C c) { return visit((ExportSpecifier) nd, c); } @Override public R visit(ExportNamespaceSpecifier nd, C c) { return visit((ExportSpecifier) nd, c); } @Override public R visit(ImportDeclaration nd, C c) { return visit((Statement) nd, c); } @Override public R visit(ImportDefaultSpecifier nd, C c) { return visit((ImportSpecifier) nd, c); } @Override public R visit(ImportNamespaceSpecifier nd, C c) { return visit((ImportSpecifier) nd, c); } @Override public R visit(ImportSpecifier nd, C c) { return visit((Expression) nd, c); } public R visit(IJSXAttribute nd, C c) { return visit((Node) nd, c); } @Override public R visit(JSXAttribute nd, C c) { return visit((IJSXAttribute) nd, c); } @Override public R visit(JSXSpreadAttribute nd, C c) { return visit((IJSXAttribute) nd, c); } public R visit(IJSXName nd, C c) { return visit((Expression) nd, c); } @Override public R visit(JSXIdentifier nd, C c) { return visit((IJSXName) nd, c); } @Override public R visit(JSXMemberExpression nd, C c) { return visit((IJSXName) nd, c); } @Override public R visit(JSXNamespacedName nd, C c) { return visit((IJSXName) nd, c); } public R visit(IJSXExpression nd, C c) { return visit((Node) nd, c); } @Override public R visit(JSXEmptyExpression nd, C c) { return visit((IJSXExpression) nd, c); } @Override public R visit(JSXExpressionContainer nd, C c) { return visit((IJSXExpression) nd, c); } public R visit(JSXBoundaryElement nd, C c) { return visit((Node) nd, c); } @Override public R visit(JSXOpeningElement nd, C c) { return visit((JSXBoundaryElement) nd, c); } @Override public R visit(JSXClosingElement nd, C c) { return visit((JSXBoundaryElement) nd, c); } @Override public R visit(JSXElement nd, C c) { return visit((Expression) nd, c); } @Override public R visit(AwaitExpression nd, C c) { return visit((Expression) nd, c); } @Override public R visit(Decorator nd, C c) { return visit((Expression) nd, c); } @Override public R visit(BindExpression nd, C c) { return visit((Expression) nd, c); } @Override public R visit(NamespaceDeclaration nd, C c) { return visit((Statement) nd, c); } @Override public R visit(ImportWholeDeclaration nd, C c) { return visit((Statement) nd, c); } @Override public R visit(ExportWholeDeclaration nd, C c) { return visit((Statement) nd, c); } @Override public R visit(ExternalModuleReference nd, C c) { return visit((Expression) nd, c); } @Override public R visit(DynamicImport nd, C c) { return visit((Expression) nd, c); } @Override public R visit(InterfaceDeclaration nd, C c) { return visit((Statement) nd, c); } @Override public R visit(KeywordTypeExpr nd, C c) { return visit((TypeExpression) nd, c); } @Override public R visit(ArrayTypeExpr nd, C c) { return visit((TypeExpression) nd, c); } @Override public R visit(UnionTypeExpr nd, C c) { return visit((TypeExpression) nd, c); } @Override public R visit(IndexedAccessTypeExpr nd, C c) { return visit((TypeExpression) nd, c); } @Override public R visit(IntersectionTypeExpr nd, C c) { return visit((TypeExpression) nd, c); } @Override public R visit(ParenthesizedTypeExpr nd, C c) { return visit((TypeExpression) nd, c); } @Override public R visit(TupleTypeExpr nd, C c) { return visit((TypeExpression) nd, c); } @Override public R visit(UnaryTypeExpr nd, C c) { return visit((TypeExpression) nd, c); } @Override public R visit(GenericTypeExpr nd, C c) { return visit((TypeExpression) nd, c); } @Override public R visit(TypeofTypeExpr nd, C c) { return visit((TypeExpression) nd, c); } @Override public R visit(PredicateTypeExpr nd, C c) { return visit((TypeExpression) nd, c); } @Override public R visit(InterfaceTypeExpr nd, C c) { return visit((TypeExpression) nd, c); } @Override public R visit(ExpressionWithTypeArguments nd, C c) { return visit((Expression) nd, c); } @Override public R visit(TypeParameter nd, C c) { return visit((TypeExpression) nd, c); } @Override public R visit(FunctionTypeExpr nd, C c) { return visit((TypeExpression) nd, c); } @Override public R visit(TypeAssertion nd, C c) { return visit((Expression) nd, c); } @Override public R visit(MappedTypeExpr nd, C c) { return visit((TypeExpression) nd, c); } @Override public R visit(TypeAliasDeclaration nd, C c) { return visit((Statement) nd, c); } @Override public R visit(EnumDeclaration nd, C c) { return visit((Statement) nd, c); } @Override public R visit(EnumMember nd, C c) { return visit((Node) nd, c); } @Override public R visit(DecoratorList nd, C c) { return visit((Expression) nd, c); } @Override public R visit(ExternalModuleDeclaration nd, C c) { return visit((Statement) nd, c); } @Override public R visit(ExportAsNamespaceDeclaration nd, C c) { return visit((Statement) nd, c); } @Override public R visit(GlobalAugmentationDeclaration nd, C c) { return visit((Statement) nd, c); } @Override public R visit(NonNullAssertion nd, C c) { return visit((Expression) nd, c); } @Override public R visit(ConditionalTypeExpr nd, C c) { return visit((TypeExpression) nd, c); } @Override public R visit(InferTypeExpr nd, C c) { return visit((TypeExpression) nd, c); } @Override public R visit(ImportTypeExpr nd, C c) { return visit((Expression) nd, c); } @Override public R visit(OptionalTypeExpr nd, C c) { return visit((TypeExpression) nd, c); } @Override public R visit(RestTypeExpr nd, C c) { return visit((TypeExpression) nd, c); } @Override public R visit(XMLAnyName nd, C c) { return visit((Expression) nd, c); } @Override public R visit(XMLAttributeSelector nd, C c) { return visit((Expression) nd, c); } @Override public R visit(XMLFilterExpression nd, C c) { return visit((Expression) nd, c); } @Override public R visit(XMLQualifiedIdentifier nd, C c) { return visit((Expression) nd, c); } @Override public R visit(XMLDotDotExpression nd, C c) { return visit((Expression) nd, c); } }
17,144
21.441099
95
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/Statement.java
package com.semmle.js.ast; /** Common superclass of all statements. */ public abstract class Statement extends Node { public Statement(String type, SourceLocation loc) { super(type, loc); } }
201
21.444444
53
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/ImportDeclaration.java
package com.semmle.js.ast; import java.util.List; import com.semmle.ts.ast.INodeWithSymbol; /** * An import declaration, which can be of one of the following forms: * * <pre> * import v from "m"; * import * as ns from "m"; * import {x, y, w as z} from "m"; * import v, * as ns from "m"; * import v, {x, y, w as z} from "m"; * import "m"; * </pre> */ public class ImportDeclaration extends Statement implements INodeWithSymbol { /** List of import specifiers detailing how declarations are imported; may be empty. */ private final List<ImportSpecifier> specifiers; /** The module from which declarations are imported. */ private final Literal source; private int symbol = -1; private boolean hasTypeKeyword; public ImportDeclaration(SourceLocation loc, List<ImportSpecifier> specifiers, Literal source) { this(loc, specifiers, source, false); } public ImportDeclaration(SourceLocation loc, List<ImportSpecifier> specifiers, Literal source, boolean hasTypeKeyword) { super("ImportDeclaration", loc); this.specifiers = specifiers; this.source = source; this.hasTypeKeyword = hasTypeKeyword; } public Literal getSource() { return source; } public List<ImportSpecifier> getSpecifiers() { return specifiers; } @Override public <C, R> R accept(Visitor<C, R> v, C c) { return v.visit(this, c); } @Override public int getSymbol() { return this.symbol; } @Override public void setSymbol(int symbol) { this.symbol = symbol; } /** Returns true if this is an <code>import type</code> declaration. */ public boolean hasTypeKeyword() { return hasTypeKeyword; } }
1,681
23.376812
122
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/IfStatement.java
package com.semmle.js.ast; /** An if statement. */ public class IfStatement extends Statement { private final Expression test; private final Statement consequent, alternate; public IfStatement( SourceLocation loc, Expression test, Statement consequent, Statement alternate) { super("IfStatement", loc); this.test = test; this.consequent = consequent; this.alternate = alternate; } @Override public <Q, A> A accept(Visitor<Q, A> v, Q q) { return v.visit(this, q); } /** The test expression of this if statement. */ public Expression getTest() { return test; } /** The then-branch of this if statement. */ public Statement getConsequent() { return consequent; } /** The else-branch of this if statement; may be null. */ public Statement getAlternate() { return alternate; } /** Does this if statement have an else branch? */ public boolean hasAlternate() { return alternate != null; } }
972
22.731707
87
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/MetaProperty.java
package com.semmle.js.ast; /** * A meta property access (cf. ECMAScript 2015 Language Specification, Chapter 12.3.8). * * <p>Currently the only recognised meta properties are <code>new.target</code>, * <code>import.meta</code> and <code> function.sent</code>. */ public class MetaProperty extends Expression { private final Identifier meta, property; public MetaProperty(SourceLocation loc, Identifier meta, Identifier property) { super("MetaProperty", loc); this.meta = meta; this.property = property; } public Identifier getMeta() { return meta; } public Identifier getProperty() { return property; } @Override public <Q, A> A accept(Visitor<Q, A> v, Q q) { return v.visit(this, q); } }
744
23.032258
87
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/ClassBody.java
package com.semmle.js.ast; import java.util.List; /** The body of a {@linkplain ClassDeclaration} or {@linkplain ClassExpression}. */ public class ClassBody extends Node { private final List<MemberDefinition<?>> body; public ClassBody(SourceLocation loc, List<MemberDefinition<?>> body) { super("ClassBody", loc); this.body = body; } public List<MemberDefinition<?>> getBody() { return body; } public void addMember(MemberDefinition<?> md) { body.add(md); } public MethodDefinition getConstructor() { for (MemberDefinition<?> md : body) if (md.isConstructor()) return (MethodDefinition) md; return null; } @Override public <C, R> R accept(Visitor<C, R> v, C c) { return v.visit(this, c); } }
751
22.5
93
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/FieldDefinition.java
package com.semmle.js.ast; import com.semmle.ts.ast.ITypeExpression; public class FieldDefinition extends MemberDefinition<Expression> { private final ITypeExpression typeAnnotation; private final int fieldParameterIndex; private static final int notFieldParameter = -1; public FieldDefinition(SourceLocation loc, int flags, Expression key, Expression value) { this(loc, flags, key, value, null); } public FieldDefinition( SourceLocation loc, int flags, Expression key, Expression value, ITypeExpression typeAnnotation) { this(loc, flags, key, value, typeAnnotation, notFieldParameter); } public FieldDefinition( SourceLocation loc, int flags, Expression key, Expression value, ITypeExpression typeAnnotation, int fieldParameterIndex) { super("FieldDefinition", loc, flags, key, value); this.typeAnnotation = typeAnnotation; this.fieldParameterIndex = fieldParameterIndex; } public ITypeExpression getTypeAnnotation() { return typeAnnotation; } @Override public <C, R> R accept(Visitor<C, R> v, C c) { return v.visit(this, c); } @Override public boolean isConcrete() { return !isAbstract(); } @Override public boolean isParameterField() { return fieldParameterIndex != notFieldParameter; } /** * If this is a field parameter, returns the index of the parameter that generated it, or -1 if * this is not a field parameter. */ public int getFieldParameterIndex() { return fieldParameterIndex; } }
1,567
23.888889
97
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/InvokeExpression.java
package com.semmle.js.ast; import com.semmle.ts.ast.INodeWithSymbol; import com.semmle.ts.ast.ITypeExpression; import java.util.List; /** An invocation, that is, either a {@link CallExpression} or a {@link NewExpression}. */ public abstract class InvokeExpression extends Expression implements INodeWithSymbol, Chainable { private final Expression callee; private final List<ITypeExpression> typeArguments; private final List<Expression> arguments; private final boolean optional; private final boolean onOptionalChain; private int resolvedSignatureId = -1; private int overloadIndex = -1; private int symbol = -1; public InvokeExpression( String type, SourceLocation loc, Expression callee, List<ITypeExpression> typeArguments, List<Expression> arguments, Boolean optional, Boolean onOptionalChain) { super(type, loc); this.callee = callee; this.typeArguments = typeArguments; this.arguments = arguments; this.optional = optional == Boolean.TRUE; this.onOptionalChain = onOptionalChain == Boolean.TRUE; } /** The callee expression of this invocation. */ public Expression getCallee() { return callee; } /** The type arguments of this invocation. */ public List<ITypeExpression> getTypeArguments() { return typeArguments; } /** The argument expressions of this invocation. */ public List<Expression> getArguments() { return arguments; } @Override public boolean isOptional() { return optional; } @Override public boolean isOnOptionalChain() { return onOptionalChain; } public int getResolvedSignatureId() { return resolvedSignatureId; } public void setResolvedSignatureId(int resolvedSignatureId) { this.resolvedSignatureId = resolvedSignatureId; } public int getOverloadIndex() { return overloadIndex; } public void setOverloadIndex(int overloadIndex) { this.overloadIndex = overloadIndex; } @Override public int getSymbol() { return symbol; } @Override public void setSymbol(int symbol) { this.symbol = symbol; } }
2,119
23.941176
97
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/AST2JSON.java
package com.semmle.js.ast; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonNull; import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; import com.semmle.js.ast.jsx.JSXAttribute; import com.semmle.js.ast.jsx.JSXClosingElement; import com.semmle.js.ast.jsx.JSXElement; import com.semmle.js.ast.jsx.JSXEmptyExpression; import com.semmle.js.ast.jsx.JSXExpressionContainer; import com.semmle.js.ast.jsx.JSXIdentifier; import com.semmle.js.ast.jsx.JSXMemberExpression; import com.semmle.js.ast.jsx.JSXNamespacedName; import com.semmle.js.ast.jsx.JSXOpeningElement; import com.semmle.js.ast.jsx.JSXSpreadAttribute; import com.semmle.ts.ast.ExportWholeDeclaration; import com.semmle.ts.ast.ExternalModuleReference; import com.semmle.ts.ast.ImportWholeDeclaration; import com.semmle.ts.ast.InterfaceDeclaration; import com.semmle.ts.ast.NamespaceDeclaration; import com.semmle.util.data.StringUtil; import java.util.List; /** Convert ASTs to their JSON representation. */ public class AST2JSON extends DefaultVisitor<Void, JsonElement> { public static JsonElement convert(INode nd) { return new AST2JSON().visit(nd); } private JsonElement visit(INode nd) { if (nd == null) return JsonNull.INSTANCE; return nd.accept(this, null); } private JsonArray visit(List<? extends INode> nds) { JsonArray result = new JsonArray(); nds.stream() .forEach( (nd) -> { result.add(visit(nd)); }); return result; } private JsonElement visitPrimitive(Object o) { if (o == null) return JsonNull.INSTANCE; if (o instanceof Boolean) return new JsonPrimitive((Boolean) o); if (o instanceof Number) return new JsonPrimitive((Number) o); return new JsonPrimitive(String.valueOf(o)); } private JsonObject mkNode(INode nd) { String type = nd.getType(); return mkNode(nd, type); } private JsonObject mkNode(INode nd, String type) { JsonObject result = new JsonObject(); result.add("type", new JsonPrimitive(type)); if (nd.getLoc() != null) result.add("loc", visit(nd.getLoc())); return result; } private JsonObject visit(SourceLocation loc) { JsonObject result = new JsonObject(); result.add("start", visit(loc.getStart())); result.add("end", visit(loc.getEnd())); return result; } private JsonObject visit(Position pos) { JsonObject result = new JsonObject(); result.add("line", visitPrimitive(pos.getLine())); result.add("column", visitPrimitive(pos.getColumn())); result.add("offset", visitPrimitive(pos.getOffset())); return result; } @Override public JsonElement visit(ArrayExpression nd, Void c) { JsonObject result = this.mkNode(nd); result.add("elements", visit(nd.getElements())); return result; } @Override public JsonElement visit(AssignmentExpression nd, Void c) { JsonObject result = this.mkNode(nd); result.add("operator", visitPrimitive(nd.getOperator())); result.add("left", visit(nd.getLeft())); result.add("right", visit(nd.getRight())); return result; } @Override public JsonElement visit(AssignmentPattern nd, Void q) { JsonObject result = this.mkNode(nd); result.add("left", visit(nd.getLeft())); result.add("right", visit(nd.getRight())); return result; } @Override public JsonElement visit(BinaryExpression nd, Void c) { JsonObject result = this.mkNode(nd); result.add("left", visit(nd.getLeft())); result.add("operator", visitPrimitive(nd.getOperator())); result.add("right", visit(nd.getRight())); return result; } @Override public JsonElement visit(BlockStatement nd, Void c) { JsonObject result = this.mkNode(nd); result.add("body", visit(nd.getBody())); return result; } @Override public JsonElement visit(BreakStatement nd, Void c) { JsonObject result = this.mkNode(nd); result.add("label", visit(nd.getLabel())); return result; } @Override public JsonElement visit(ContinueStatement nd, Void c) { JsonObject result = this.mkNode(nd); result.add("label", visit(nd.getLabel())); return result; } @Override public JsonElement visit(CallExpression nd, Void c) { JsonObject result = this.mkNode(nd); result.add("callee", visit(nd.getCallee())); result.add("arguments", visit(nd.getArguments())); result.add("optional", new JsonPrimitive(nd.isOptional())); return result; } @Override public JsonElement visit(CatchClause nd, Void c) { JsonObject result = this.mkNode(nd); result.add("param", visit(nd.getParam())); result.add("body", visit(nd.getBody())); return result; } @Override public JsonElement visit(ClassBody nd, Void c) { JsonObject result = this.mkNode(nd); result.add("body", visit(nd.getBody())); return result; } @Override public JsonElement visit(ClassDeclaration nd, Void c) { JsonObject result = this.mkNode(nd); visit(nd.getClassDef(), result); return result; } @Override public JsonElement visit(ClassExpression nd, Void c) { JsonObject result = this.mkNode(nd); visit(nd.getClassDef(), result); return result; } private void visit(AClass classDef, JsonObject result) { result.add("id", visit(classDef.getId())); result.add("superClass", visit(classDef.getSuperClass())); result.add("body", visit(classDef.getBody())); if (!classDef.getDecorators().isEmpty()) result.add("decorators", visit(classDef.getDecorators())); } @Override public JsonElement visit(ComprehensionBlock nd, Void c) { JsonObject result = this.mkNode(nd); result.add("left", visit(nd.getLeft())); result.add("right", visit(nd.getRight())); result.add("each", visitPrimitive(nd.isOf())); return result; } @Override public JsonElement visit(ComprehensionExpression nd, Void c) { JsonObject result = this.mkNode(nd); result.add("body", visit(nd.getBody())); result.add("blocks", visit(nd.getBlocks())); result.add("filter", visit(nd.getFilter())); return result; } @Override public JsonElement visit(ConditionalExpression nd, Void c) { JsonObject result = this.mkNode(nd); result.add("test", visit(nd.getTest())); result.add("consequent", visit(nd.getConsequent())); result.add("alternate", visit(nd.getAlternate())); return result; } @Override public JsonElement visit(DoWhileStatement nd, Void c) { JsonObject result = this.mkNode(nd); result.add("body", visit(nd.getBody())); result.add("test", visit(nd.getTest())); return result; } @Override public JsonElement visit(EmptyStatement nd, Void c) { return this.mkNode(nd); } @Override public JsonElement visit(ExportNamedDeclaration nd, Void c) { JsonObject result = this.mkNode(nd); result.add("declaration", visit(nd.getDeclaration())); result.add("specifiers", visit(nd.getSpecifiers())); result.add("source", visit(nd.getSource())); return result; } @Override public JsonElement visit(ExportSpecifier nd, Void c) { JsonObject result = this.mkNode(nd); if (nd.getLocal() != null) result.add("local", visit(nd.getLocal())); result.add("exported", visit(nd.getExported())); return result; } @Override public JsonElement visit(ExpressionStatement nd, Void c) { JsonObject result = this.mkNode(nd); result.add("expression", visit(nd.getExpression())); return result; } @Override public JsonElement visit(EnhancedForStatement nd, Void c) { JsonObject result = this.mkNode(nd); result.add("left", visit(nd.getLeft())); result.add("right", visit(nd.getRight())); result.add("body", visit(nd.getBody())); return result; } @Override public JsonElement visit(ForStatement nd, Void c) { JsonObject result = this.mkNode(nd); result.add("init", visit(nd.getInit())); result.add("test", visit(nd.getTest())); result.add("update", visit(nd.getUpdate())); result.add("body", visit(nd.getBody())); return result; } @Override public JsonElement visit(IFunction nd, Void c) { JsonObject result = this.mkNode(nd); result.add("id", visit(nd.getId())); result.add("generator", new JsonPrimitive(nd.isGenerator())); result.add("expression", new JsonPrimitive(nd.getBody() instanceof Expression)); result.add("async", new JsonPrimitive(nd.isAsync())); result.add("params", visit(nd.getRawParameters())); result.add("body", visit(nd.getBody())); return result; } @Override public JsonElement visit(Identifier nd, Void c) { JsonObject result = this.mkNode(nd); result.add("name", new JsonPrimitive(nd.getName())); return result; } @Override public JsonElement visit(IfStatement nd, Void c) { JsonObject result = this.mkNode(nd); result.add("test", visit(nd.getTest())); result.add("consequent", visit(nd.getConsequent())); result.add("alternate", visit(nd.getAlternate())); return result; } @Override public JsonElement visit(ImportDeclaration nd, Void c) { JsonObject result = this.mkNode(nd); result.add("specifiers", visit(nd.getSpecifiers())); result.add("source", visit(nd.getSource())); return result; } @Override public JsonElement visit(ImportSpecifier nd, Void c) { JsonObject result = this.mkNode(nd); result.add("imported", visit(nd.getImported())); result.add("local", visit(nd.getLocal())); return result; } @Override public JsonElement visit(ImportNamespaceSpecifier nd, Void c) { JsonObject result = this.mkNode(nd); result.add("local", visit(nd.getLocal())); return result; } @Override public JsonElement visit(LabeledStatement nd, Void c) { JsonObject result = this.mkNode(nd); result.add("body", visit(nd.getBody())); result.add("label", visit(nd.getLabel())); return result; } @Override public JsonElement visit(Literal nd, Void c) { JsonObject result = this.mkNode(nd); if (nd.isRegExp()) result.add("value", new JsonObject()); else result.add("value", visitPrimitive(nd.getValue())); result.add("raw", new JsonPrimitive(nd.getRaw())); return result; } @Override public JsonElement visit(LogicalExpression nd, Void c) { JsonObject result = this.mkNode(nd); result.add("left", visit(nd.getLeft())); result.add("operator", visitPrimitive(nd.getOperator())); result.add("right", visit(nd.getRight())); return result; } @Override public JsonElement visit(MemberExpression nd, Void c) { JsonObject result = this.mkNode(nd); result.add("object", visit(nd.getObject())); result.add("property", visit(nd.getProperty())); result.add("computed", new JsonPrimitive(nd.isComputed())); result.add("optional", new JsonPrimitive(nd.isOptional())); return result; } @Override public JsonElement visit(MemberDefinition<?> nd, Void c) { JsonObject result = this.mkNode(nd); result.add("computed", visitPrimitive(nd.isComputed())); result.add("key", visit(nd.getKey())); result.add("static", visitPrimitive(nd.isStatic())); result.add("value", visit(nd.getValue())); if (!nd.getDecorators().isEmpty()) result.add("decorators", visit(nd.getDecorators())); return result; } @Override public JsonElement visit(MethodDefinition nd, Void c) { JsonObject result = (JsonObject) super.visit(nd, c); result.add("kind", visitPrimitive(StringUtil.lc(nd.getKind().toString()))); return result; } @Override public JsonElement visit(NewExpression nd, Void c) { JsonObject result = this.mkNode(nd); result.add("callee", visit(nd.getCallee())); result.add("arguments", visit(nd.getArguments())); return result; } @Override public JsonObject visit(Node nd, Void c) { throw new UnsupportedOperationException(nd.getType()); } @Override public JsonElement visit(ObjectExpression nd, Void c) { JsonObject result = this.mkNode(nd); result.add("properties", visit(nd.getProperties())); return result; } @Override public JsonElement visit(ObjectPattern nd, Void c) { JsonObject result = this.mkNode(nd); result.add("properties", visit(nd.getRawProperties())); return result; } @Override public JsonElement visit(ParenthesizedExpression nd, Void c) { JsonObject result = this.mkNode(nd); result.add("expression", visit(nd.getExpression())); return result; } @Override public JsonElement visit(Program nd, Void c) { JsonObject result = this.mkNode(nd); result.add("body", visit(nd.getBody())); result.add("sourceType", visitPrimitive(nd.getSourceType())); return result; } @Override public JsonElement visit(Property nd, Void c) { JsonObject result = this.mkNode(nd); result.add("method", new JsonPrimitive(nd.isMethod())); result.add("shorthand", new JsonPrimitive(nd.isShorthand())); result.add("computed", new JsonPrimitive(nd.isComputed())); result.add("key", visit(nd.getKey())); result.add("kind", new JsonPrimitive(StringUtil.lc(nd.getKind().name()))); result.add("value", visit(nd.getRawValue())); if (!nd.getDecorators().isEmpty()) result.add("decorators", visit(nd.getDecorators())); return result; } @Override public JsonElement visit(RestElement nd, Void q) { JsonObject result = this.mkNode(nd); result.add("argument", visit(nd.getArgument())); return result; } @Override public JsonElement visit(ReturnStatement nd, Void c) { JsonObject result = this.mkNode(nd); result.add("argument", visit(nd.getArgument())); return result; } @Override public JsonElement visit(SequenceExpression nd, Void c) { JsonObject result = this.mkNode(nd); result.add("expressions", visit(nd.getExpressions())); return result; } @Override public JsonElement visit(SwitchCase nd, Void c) { JsonObject result = this.mkNode(nd); result.add("consequent", visit(nd.getConsequent())); result.add("test", visit(nd.getTest())); return result; } @Override public JsonElement visit(SwitchStatement nd, Void c) { JsonObject result = this.mkNode(nd); result.add("discriminant", visit(nd.getDiscriminant())); result.add("cases", visit(nd.getCases())); return result; } @Override public JsonElement visit(ThisExpression nd, Void c) { return this.mkNode(nd); } @Override public JsonElement visit(ThrowStatement nd, Void c) { JsonObject result = this.mkNode(nd); result.add("argument", visit(nd.getArgument())); return result; } @Override public JsonElement visit(TryStatement nd, Void c) { JsonObject result = this.mkNode(nd); result.add("block", visit(nd.getBlock())); result.add("handler", visit(nd.getHandler())); result.add("finalizer", visit(nd.getFinalizer())); return result; } @Override public JsonElement visit(UnaryExpression nd, Void c) { JsonObject result = this.mkNode(nd); result.add("operator", visitPrimitive(nd.getOperator())); result.add("prefix", new JsonPrimitive(nd.isPrefix())); result.add("argument", visit(nd.getArgument())); return result; } @Override public JsonElement visit(UpdateExpression nd, Void c) { JsonObject result = this.mkNode(nd); result.add("operator", visitPrimitive(nd.getOperator())); result.add("prefix", new JsonPrimitive(nd.isPrefix())); result.add("argument", visit(nd.getArgument())); return result; } @Override public JsonElement visit(VariableDeclaration nd, Void c) { JsonObject result = this.mkNode(nd); result.add("declarations", visit(nd.getDeclarations())); result.add("kind", new JsonPrimitive(nd.getKind())); return result; } @Override public JsonElement visit(VariableDeclarator nd, Void c) { JsonObject result = this.mkNode(nd); result.add("id", visit(nd.getId())); result.add("init", visit(nd.getInit())); return result; } @Override public JsonElement visit(WhileStatement nd, Void c) { JsonObject result = this.mkNode(nd); result.add("test", visit(nd.getTest())); result.add("body", visit(nd.getBody())); return result; } @Override public JsonElement visit(ArrayPattern nd, Void q) { JsonObject result = this.mkNode(nd); result.add("elements", visit(nd.getRawElements())); return result; } @Override public JsonElement visit(WithStatement nd, Void q) { JsonObject result = this.mkNode(nd); result.add("object", visit(nd.getObject())); result.add("body", visit(nd.getBody())); return result; } @Override public JsonElement visit(SpreadElement nd, Void q) { JsonObject result = this.mkNode(nd); result.add("argument", visit(nd.getArgument())); return result; } @Override public JsonElement visit(YieldExpression nd, Void q) { JsonObject result = this.mkNode(nd); result.add("argument", visit(nd.getArgument())); result.add("delegate", visitPrimitive(nd.isDelegating())); return result; } @Override public JsonElement visit(DebuggerStatement nd, Void q) { JsonObject result = this.mkNode(nd); return result; } @Override public JsonElement visit(TemplateElement nd, Void q) { JsonObject result = this.mkNode(nd); JsonObject value = new JsonObject(); value.add("cooked", visitPrimitive(nd.getCooked())); value.add("raw", visitPrimitive(nd.getRaw())); result.add("value", value); result.add("tail", visitPrimitive(nd.isTail())); return result; } @Override public JsonElement visit(TemplateLiteral nd, Void q) { JsonObject result = this.mkNode(nd); result.add("quasis", visit(nd.getQuasis())); result.add("expressions", visit(nd.getExpressions())); return result; } @Override public JsonElement visit(TaggedTemplateExpression nd, Void q) { JsonObject result = this.mkNode(nd); result.add("tag", visit(nd.getTag())); result.add("quasi", visit(nd.getQuasi())); return result; } @Override public JsonElement visit(LetStatement nd, Void q) { JsonObject result = this.mkNode(nd); result.add("head", visit(nd.getHead())); result.add("body", visit(nd.getBody())); return result; } @Override public JsonElement visit(LetExpression nd, Void c) { JsonObject result = this.mkNode(nd); result.add("head", visit(nd.getHead())); result.add("body", visit(nd.getBody())); return result; } @Override public JsonElement visit(Super nd, Void c) { JsonObject result = this.mkNode(nd); return result; } @Override public JsonElement visit(MetaProperty nd, Void c) { JsonObject result = this.mkNode(nd); result.add("meta", visit(nd.getMeta())); result.add("property", visit(nd.getProperty())); return result; } @Override public JsonElement visit(ExportAllDeclaration nd, Void c) { JsonObject result = this.mkNode(nd); result.add("source", visit(nd.getSource())); return result; } @Override public JsonElement visit(ExportDefaultDeclaration nd, Void c) { JsonObject result = this.mkNode(nd); result.add("declaration", visit(nd.getDeclaration())); return result; } @Override public JsonElement visit(JSXIdentifier nd, Void c) { JsonObject result = this.mkNode(nd, "JSXIdentifier"); result.add("name", visitPrimitive(nd.getName())); return result; } @Override public JsonElement visit(JSXMemberExpression nd, Void c) { JsonObject result = this.mkNode(nd); result.add("object", visit(nd.getObject())); result.add("property", visit(nd.getName())); return result; } @Override public JsonElement visit(JSXNamespacedName nd, Void c) { JsonObject result = this.mkNode(nd); result.add("namespace", visit(nd.getNamespace())); result.add("name", visit(nd.getName())); return result; } @Override public JsonElement visit(JSXEmptyExpression nd, Void c) { JsonObject result = this.mkNode(nd); return result; } @Override public JsonElement visit(JSXExpressionContainer nd, Void c) { JsonObject result = this.mkNode(nd); result.add("expression", visit(nd.getExpression())); return result; } @Override public JsonElement visit(JSXOpeningElement nd, Void c) { JsonObject result = this.mkNode(nd); result.add("name", visit(nd.getName())); result.add("attributes", visit(nd.getAttributes())); result.add("selfClosing", visitPrimitive(nd.isSelfClosing())); return result; } @Override public JsonElement visit(JSXClosingElement nd, Void c) { JsonObject result = this.mkNode(nd); result.add("name", visit(nd.getName())); return result; } @Override public JsonElement visit(JSXAttribute nd, Void c) { JsonObject result = this.mkNode(nd); result.add("name", visit(nd.getName())); result.add("value", visit(nd.getValue())); return result; } @Override public JsonElement visit(JSXSpreadAttribute nd, Void c) { JsonObject result = this.mkNode(nd); result.add("argument", visit(nd.getArgument())); return result; } @Override public JsonElement visit(JSXElement nd, Void c) { JsonObject result = this.mkNode(nd); result.add("openingElement", visit(nd.getOpeningElement())); result.add("children", visit(nd.getChildren())); result.add("closingElement", visit(nd.getClosingElement())); return result; } @Override public JsonElement visit(AwaitExpression nd, Void c) { JsonObject result = this.mkNode(nd); result.add("argument", visit(nd.getArgument())); return result; } @Override public JsonElement visit(Decorator nd, Void c) { JsonObject result = this.mkNode(nd); result.add("expression", visit(nd.getExpression())); return result; } @Override public JsonElement visit(BindExpression nd, Void c) { JsonObject result = this.mkNode(nd); result.add("object", visit(nd.getObject())); result.add("callee", visit(nd.getCallee())); return result; } @Override public JsonElement visit(NamespaceDeclaration nd, Void c) { JsonObject result = this.mkNode(nd); result.add("name", visit(nd.getName())); result.add("body", visit(nd.getBody())); return result; } @Override public JsonElement visit(ImportWholeDeclaration nd, Void c) { JsonObject result = this.mkNode(nd); result.add("name", visit(nd.getLhs())); result.add("moduleReference", visit(nd.getRhs())); return result; } @Override public JsonElement visit(ExportWholeDeclaration nd, Void c) { JsonObject result = this.mkNode(nd); result.add("expression", visit(nd.getRhs())); return result; } @Override public JsonElement visit(ExternalModuleReference nd, Void c) { JsonObject result = this.mkNode(nd); result.add("expression", visit(nd.getExpression())); return result; } @Override public JsonElement visit(DynamicImport nd, Void c) { JsonObject result = this.mkNode(nd); result.add("source", visit(nd.getSource())); return result; } @Override public JsonElement visit(InterfaceDeclaration nd, Void c) { JsonObject result = this.mkNode(nd); result.add("body", visit(nd.getBody())); return result; } }
23,335
29.188875
91
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/NodeCopier.java
package com.semmle.js.ast; import com.semmle.js.ast.jsx.JSXAttribute; import com.semmle.js.ast.jsx.JSXClosingElement; import com.semmle.js.ast.jsx.JSXElement; import com.semmle.js.ast.jsx.JSXEmptyExpression; import com.semmle.js.ast.jsx.JSXExpressionContainer; import com.semmle.js.ast.jsx.JSXIdentifier; import com.semmle.js.ast.jsx.JSXMemberExpression; import com.semmle.js.ast.jsx.JSXNamespacedName; import com.semmle.js.ast.jsx.JSXOpeningElement; import com.semmle.js.ast.jsx.JSXSpreadAttribute; import com.semmle.ts.ast.ArrayTypeExpr; import com.semmle.ts.ast.ConditionalTypeExpr; import com.semmle.ts.ast.DecoratorList; import com.semmle.ts.ast.EnumDeclaration; import com.semmle.ts.ast.EnumMember; import com.semmle.ts.ast.ExportAsNamespaceDeclaration; import com.semmle.ts.ast.ExportWholeDeclaration; import com.semmle.ts.ast.ExpressionWithTypeArguments; import com.semmle.ts.ast.ExternalModuleDeclaration; import com.semmle.ts.ast.ExternalModuleReference; import com.semmle.ts.ast.FunctionTypeExpr; import com.semmle.ts.ast.GenericTypeExpr; import com.semmle.ts.ast.GlobalAugmentationDeclaration; import com.semmle.ts.ast.ImportTypeExpr; import com.semmle.ts.ast.ImportWholeDeclaration; import com.semmle.ts.ast.IndexedAccessTypeExpr; import com.semmle.ts.ast.InferTypeExpr; import com.semmle.ts.ast.InterfaceDeclaration; import com.semmle.ts.ast.InterfaceTypeExpr; import com.semmle.ts.ast.IntersectionTypeExpr; import com.semmle.ts.ast.KeywordTypeExpr; import com.semmle.ts.ast.MappedTypeExpr; import com.semmle.ts.ast.NamespaceDeclaration; import com.semmle.ts.ast.NonNullAssertion; import com.semmle.ts.ast.OptionalTypeExpr; import com.semmle.ts.ast.ParenthesizedTypeExpr; import com.semmle.ts.ast.PredicateTypeExpr; import com.semmle.ts.ast.RestTypeExpr; import com.semmle.ts.ast.TupleTypeExpr; import com.semmle.ts.ast.TypeAliasDeclaration; import com.semmle.ts.ast.TypeAssertion; import com.semmle.ts.ast.TypeParameter; import com.semmle.ts.ast.TypeofTypeExpr; import com.semmle.ts.ast.UnaryTypeExpr; import com.semmle.ts.ast.UnionTypeExpr; import com.semmle.util.data.IntList; import java.util.ArrayList; import java.util.List; /** Deep cloning of AST nodes. */ public class NodeCopier implements Visitor<Void, INode> { private Position visit(Position pos) { return new Position(pos.getLine(), pos.getColumn(), pos.getOffset()); } private SourceLocation visit(SourceLocation loc) { return new SourceLocation(loc.getSource(), visit(loc.getStart()), visit(loc.getEnd())); } @SuppressWarnings("unchecked") public <T extends INode> T copy(T t) { if (t == null) return null; return (T) t.accept(this, null); } private <T extends INode> List<T> copy(List<T> ts) { List<T> result = new ArrayList<T>(); for (T t : ts) result.add(copy(t)); return result; } private IntList copy(IntList list) { return new IntList(list); } @Override public AssignmentExpression visit(AssignmentExpression nd, Void q) { return new AssignmentExpression( visit(nd.getLoc()), nd.getOperator(), copy(nd.getLeft()), copy(nd.getRight())); } @Override public AssignmentPattern visit(AssignmentPattern nd, Void q) { return new AssignmentPattern( visit(nd.getLoc()), nd.getOperator(), copy(nd.getLeft()), copy(nd.getRight())); } @Override public BinaryExpression visit(BinaryExpression nd, Void q) { return new BinaryExpression( visit(nd.getLoc()), nd.getOperator(), copy(nd.getLeft()), copy(nd.getRight())); } @Override public BlockStatement visit(BlockStatement nd, Void q) { return new BlockStatement(visit(nd.getLoc()), copy(nd.getBody())); } @Override public CallExpression visit(CallExpression nd, Void q) { return new CallExpression( visit(nd.getLoc()), copy(nd.getCallee()), copy(nd.getTypeArguments()), copy(nd.getArguments()), nd.isOptional(), nd.isOnOptionalChain()); } @Override public ComprehensionBlock visit(ComprehensionBlock nd, Void q) { return new ComprehensionBlock( visit(nd.getLoc()), copy(nd.getLeft()), copy(nd.getRight()), nd.isOf()); } @Override public ComprehensionExpression visit(ComprehensionExpression nd, Void q) { return new ComprehensionExpression( visit(nd.getLoc()), copy(nd.getBody()), copy(nd.getBlocks()), copy(nd.getFilter()), nd.isGenerator()); } @Override public ExpressionStatement visit(ExpressionStatement nd, Void q) { return new ExpressionStatement(visit(nd.getLoc()), copy(nd.getExpression())); } @Override public FunctionDeclaration visit(FunctionDeclaration nd, Void q) { return new FunctionDeclaration( visit(nd.getLoc()), copy(nd.getId()), copy(nd.getRawParameters()), copy(nd.getBody()), nd.isGenerator(), nd.isAsync(), nd.hasDeclareKeyword(), copy(nd.getTypeParameters()), copy(nd.getParameterTypes()), copy(nd.getReturnType()), copy(nd.getThisParameterType()), copy(nd.getOptionalParameterIndices())); } @Override public Identifier visit(Identifier nd, Void q) { return new Identifier(visit(nd.getLoc()), nd.getName()); } @Override public Literal visit(Literal nd, Void q) { return new Literal(visit(nd.getLoc()), nd.getTokenType(), nd.getValue()); } @Override public LogicalExpression visit(LogicalExpression nd, Void q) { return new LogicalExpression( visit(nd.getLoc()), nd.getOperator(), copy(nd.getLeft()), copy(nd.getRight())); } @Override public MemberExpression visit(MemberExpression nd, Void q) { return new MemberExpression( visit(nd.getLoc()), copy(nd.getObject()), copy(nd.getProperty()), nd.isComputed(), nd.isOptional(), nd.isOnOptionalChain()); } @Override public Program visit(Program nd, Void q) { return new Program(visit(nd.getLoc()), copy(nd.getBody()), nd.getSourceType()); } @Override public UnaryExpression visit(UnaryExpression nd, Void q) { return new UnaryExpression( visit(nd.getLoc()), nd.getOperator(), copy(nd.getArgument()), nd.isPrefix()); } @Override public UpdateExpression visit(UpdateExpression nd, Void q) { return new UpdateExpression( visit(nd.getLoc()), nd.getOperator(), copy(nd.getArgument()), nd.isPrefix()); } @Override public VariableDeclaration visit(VariableDeclaration nd, Void q) { return new VariableDeclaration( visit(nd.getLoc()), nd.getKind(), copy(nd.getDeclarations()), nd.hasDeclareKeyword()); } @Override public VariableDeclarator visit(VariableDeclarator nd, Void q) { return new VariableDeclarator( visit(nd.getLoc()), copy(nd.getId()), copy(nd.getInit()), copy(nd.getTypeAnnotation()), nd.getFlags()); } @Override public SwitchStatement visit(SwitchStatement nd, Void q) { return new SwitchStatement(visit(nd.getLoc()), copy(nd.getDiscriminant()), copy(nd.getCases())); } @Override public SwitchCase visit(SwitchCase nd, Void q) { return new SwitchCase(visit(nd.getLoc()), copy(nd.getTest()), copy(nd.getConsequent())); } @Override public ForStatement visit(ForStatement nd, Void q) { return new ForStatement( visit(nd.getLoc()), copy(nd.getInit()), copy(nd.getTest()), copy(nd.getUpdate()), copy(nd.getBody())); } @Override public ForInStatement visit(ForInStatement nd, Void q) { return new ForInStatement( visit(nd.getLoc()), copy(nd.getLeft()), copy(nd.getRight()), copy(nd.getBody()), nd.isEach()); } @Override public ForOfStatement visit(ForOfStatement nd, Void q) { return new ForOfStatement( visit(nd.getLoc()), copy(nd.getLeft()), copy(nd.getRight()), copy(nd.getBody())); } @Override public Property visit(Property nd, Void q) { return new Property( visit(nd.getLoc()), copy(nd.getKey()), copy(nd.getRawValue()), nd.getKind().name(), nd.isComputed(), nd.isMethod()); } @Override public ArrayPattern visit(ArrayPattern nd, Void q) { return new ArrayPattern(visit(nd.getLoc()), copy(nd.getElements())); } @Override public ObjectPattern visit(ObjectPattern nd, Void q) { return new ObjectPattern(visit(nd.getLoc()), copy(nd.getRawProperties())); } @Override public IfStatement visit(IfStatement nd, Void q) { return new IfStatement( visit(nd.getLoc()), copy(nd.getTest()), copy(nd.getConsequent()), copy(nd.getAlternate())); } @Override public LabeledStatement visit(LabeledStatement nd, Void q) { return new LabeledStatement(visit(nd.getLoc()), copy(nd.getLabel()), copy(nd.getBody())); } @Override public WithStatement visit(WithStatement nd, Void q) { return new WithStatement(visit(nd.getLoc()), copy(nd.getObject()), copy(nd.getBody())); } @Override public DoWhileStatement visit(DoWhileStatement nd, Void q) { return new DoWhileStatement(visit(nd.getLoc()), copy(nd.getTest()), copy(nd.getBody())); } @Override public WhileStatement visit(WhileStatement nd, Void q) { return new WhileStatement(visit(nd.getLoc()), copy(nd.getTest()), copy(nd.getBody())); } @Override public CatchClause visit(CatchClause nd, Void q) { return new CatchClause( visit(nd.getLoc()), copy(nd.getParam()), copy(nd.getGuard()), copy(nd.getBody())); } @Override public TryStatement visit(TryStatement nd, Void q) { return new TryStatement( visit(nd.getLoc()), copy(nd.getBlock()), copy(nd.getHandler()), copy(nd.getGuardedHandlers()), copy(nd.getFinalizer())); } @Override public NewExpression visit(NewExpression nd, Void q) { return new NewExpression( visit(nd.getLoc()), copy(nd.getCallee()), copy(nd.getTypeArguments()), copy(nd.getArguments())); } @Override public ReturnStatement visit(ReturnStatement nd, Void q) { return new ReturnStatement(visit(nd.getLoc()), copy(nd.getArgument())); } @Override public ThrowStatement visit(ThrowStatement nd, Void q) { return new ThrowStatement(visit(nd.getLoc()), copy(nd.getArgument())); } @Override public SpreadElement visit(SpreadElement nd, Void q) { return new SpreadElement(visit(nd.getLoc()), copy(nd.getArgument())); } @Override public RestElement visit(RestElement nd, Void q) { return new RestElement(visit(nd.getLoc()), copy(nd.getArgument())); } @Override public YieldExpression visit(YieldExpression nd, Void q) { return new YieldExpression(visit(nd.getLoc()), copy(nd.getArgument()), nd.isDelegating()); } @Override public ParenthesizedExpression visit(ParenthesizedExpression nd, Void q) { return new ParenthesizedExpression(visit(nd.getLoc()), copy(nd.getExpression())); } @Override public EmptyStatement visit(EmptyStatement nd, Void q) { return new EmptyStatement(visit(nd.getLoc())); } @Override public BreakStatement visit(BreakStatement nd, Void q) { return new BreakStatement(visit(nd.getLoc()), copy(nd.getLabel())); } @Override public ContinueStatement visit(ContinueStatement nd, Void q) { return new ContinueStatement(visit(nd.getLoc()), copy(nd.getLabel())); } @Override public FunctionExpression visit(FunctionExpression nd, Void q) { return new FunctionExpression( visit(nd.getLoc()), copy(nd.getId()), copy(nd.getRawParameters()), copy(nd.getBody()), nd.isGenerator(), nd.isAsync(), copy(nd.getTypeParameters()), copy(nd.getParameterTypes()), copy(nd.getParameterDecorators()), copy(nd.getReturnType()), copy(nd.getThisParameterType()), copy(nd.getOptionalParameterIndices())); } @Override public DebuggerStatement visit(DebuggerStatement nd, Void q) { return new DebuggerStatement(visit(nd.getLoc())); } @Override public ArrayExpression visit(ArrayExpression nd, Void q) { return new ArrayExpression(visit(nd.getLoc()), copy(nd.getElements())); } @Override public ObjectExpression visit(ObjectExpression nd, Void q) { return new ObjectExpression(visit(nd.getLoc()), copy(nd.getProperties())); } @Override public ThisExpression visit(ThisExpression nd, Void q) { return new ThisExpression(visit(nd.getLoc())); } @Override public ConditionalExpression visit(ConditionalExpression nd, Void q) { return new ConditionalExpression( visit(nd.getLoc()), copy(nd.getTest()), copy(nd.getConsequent()), copy(nd.getAlternate())); } @Override public SequenceExpression visit(SequenceExpression nd, Void q) { return new SequenceExpression(visit(nd.getLoc()), copy(nd.getExpressions())); } @Override public TemplateElement visit(TemplateElement nd, Void q) { return new TemplateElement(visit(nd.getLoc()), nd.getCooked(), nd.getRaw(), nd.isTail()); } @Override public TemplateLiteral visit(TemplateLiteral nd, Void q) { return new TemplateLiteral(visit(nd.getLoc()), copy(nd.getExpressions()), copy(nd.getQuasis())); } @Override public TaggedTemplateExpression visit(TaggedTemplateExpression nd, Void q) { return new TaggedTemplateExpression( visit(nd.getLoc()), copy(nd.getTag()), copy(nd.getQuasi()), copy(nd.getTypeArguments())); } @Override public ArrowFunctionExpression visit(ArrowFunctionExpression nd, Void q) { return new ArrowFunctionExpression( visit(nd.getLoc()), copy(nd.getRawParameters()), copy(nd.getBody()), nd.isGenerator(), nd.isAsync(), copy(nd.getTypeParameters()), copy(nd.getParameterTypes()), copy(nd.getReturnType()), copy(nd.getOptionalParameterIndices())); } @Override public LetStatement visit(LetStatement nd, Void q) { return new LetStatement(visit(nd.getLoc()), copy(nd.getHead()), copy(nd.getBody())); } @Override public LetExpression visit(LetExpression nd, Void c) { return new LetExpression(visit(nd.getLoc()), copy(nd.getHead()), copy(nd.getBody())); } @Override public ClassDeclaration visit(ClassDeclaration nd, Void c) { return new ClassDeclaration( visit(nd.getLoc()), visit(nd.getClassDef()), nd.hasDeclareKeyword(), nd.hasAbstractKeyword()); } @Override public ClassExpression visit(ClassExpression nd, Void c) { return new ClassExpression(visit(nd.getLoc()), visit(nd.getClassDef())); } private AClass visit(AClass nd) { return new AClass( copy(nd.getId()), copy(nd.getTypeParameters()), copy(nd.getSuperClass()), copy(nd.getSuperInterfaces()), copy(nd.getBody())); } @Override public ClassBody visit(ClassBody nd, Void c) { return new ClassBody(visit(nd.getLoc()), copy(nd.getBody())); } @Override public MethodDefinition visit(MethodDefinition nd, Void c) { return new MethodDefinition( visit(nd.getLoc()), nd.getFlags(), nd.getKind(), copy(nd.getKey()), copy(nd.getValue()), copy(nd.getParameterFields())); } @Override public FieldDefinition visit(FieldDefinition nd, Void c) { return new FieldDefinition( visit(nd.getLoc()), nd.getFlags(), copy(nd.getKey()), copy(nd.getValue()), copy(nd.getTypeAnnotation())); } @Override public Super visit(Super nd, Void c) { return new Super(visit(nd.getLoc())); } @Override public MetaProperty visit(MetaProperty nd, Void c) { return new MetaProperty(visit(nd.getLoc()), copy(nd.getMeta()), copy(nd.getProperty())); } @Override public ExportAllDeclaration visit(ExportAllDeclaration nd, Void c) { return new ExportAllDeclaration(visit(nd.getLoc()), copy(nd.getSource())); } @Override public ExportDefaultDeclaration visit(ExportDefaultDeclaration nd, Void c) { return new ExportDefaultDeclaration(visit(nd.getLoc()), copy(nd.getDeclaration())); } @Override public ExportNamedDeclaration visit(ExportNamedDeclaration nd, Void c) { return new ExportNamedDeclaration( visit(nd.getLoc()), copy(nd.getDeclaration()), copy(nd.getSpecifiers()), copy(nd.getSource())); } @Override public ExportDefaultSpecifier visit(ExportDefaultSpecifier nd, Void c) { return new ExportDefaultSpecifier(visit(nd.getLoc()), copy(nd.getExported())); } @Override public ExportNamespaceSpecifier visit(ExportNamespaceSpecifier nd, Void c) { return new ExportNamespaceSpecifier(visit(nd.getLoc()), copy(nd.getExported())); } @Override public ExportSpecifier visit(ExportSpecifier nd, Void c) { return new ExportSpecifier(visit(nd.getLoc()), copy(nd.getLocal()), copy(nd.getExported())); } @Override public ImportDeclaration visit(ImportDeclaration nd, Void c) { return new ImportDeclaration( visit(nd.getLoc()), copy(nd.getSpecifiers()), copy(nd.getSource())); } @Override public ImportDefaultSpecifier visit(ImportDefaultSpecifier nd, Void c) { return new ImportDefaultSpecifier(visit(nd.getLoc()), copy(nd.getLocal())); } @Override public ImportNamespaceSpecifier visit(ImportNamespaceSpecifier nd, Void c) { return new ImportNamespaceSpecifier(visit(nd.getLoc()), copy(nd.getLocal())); } @Override public ImportSpecifier visit(ImportSpecifier nd, Void c) { return new ImportSpecifier(visit(nd.getLoc()), copy(nd.getImported()), copy(nd.getLocal())); } @Override public INode visit(JSXIdentifier nd, Void c) { return new JSXIdentifier(visit(nd.getLoc()), nd.getName()); } @Override public INode visit(JSXMemberExpression nd, Void c) { return new JSXMemberExpression(visit(nd.getLoc()), copy(nd.getObject()), copy(nd.getName())); } @Override public INode visit(JSXNamespacedName nd, Void c) { return new JSXNamespacedName(visit(nd.getLoc()), copy(nd.getNamespace()), copy(nd.getName())); } @Override public INode visit(JSXEmptyExpression nd, Void c) { return new JSXEmptyExpression(visit(nd.getLoc())); } @Override public INode visit(JSXExpressionContainer nd, Void c) { return new JSXExpressionContainer(visit(nd.getLoc()), copy(nd.getExpression())); } @Override public INode visit(JSXOpeningElement nd, Void c) { return new JSXOpeningElement( visit(nd.getLoc()), copy(nd.getName()), copy(nd.getAttributes()), nd.isSelfClosing()); } @Override public INode visit(JSXClosingElement nd, Void c) { return new JSXClosingElement(visit(nd.getLoc()), copy(nd.getName())); } @Override public INode visit(JSXAttribute nd, Void c) { return new JSXAttribute(visit(nd.getLoc()), copy(nd.getName()), copy(nd.getValue())); } @Override public INode visit(JSXSpreadAttribute nd, Void c) { return new JSXSpreadAttribute(visit(nd.getLoc()), copy(nd.getArgument())); } @Override public INode visit(JSXElement nd, Void c) { return new JSXElement( visit(nd.getLoc()), copy(nd.getOpeningElement()), copy(nd.getChildren()), copy(nd.getClosingElement())); } @Override public INode visit(AwaitExpression nd, Void c) { return new AwaitExpression(visit(nd.getLoc()), copy(nd.getArgument())); } @Override public INode visit(Decorator nd, Void c) { return new Decorator(visit(nd.getLoc()), copy(nd.getExpression())); } @Override public INode visit(BindExpression nd, Void c) { return new BindExpression(visit(nd.getLoc()), copy(nd.getObject()), copy(nd.getCallee())); } @Override public INode visit(NamespaceDeclaration nd, Void c) { return new NamespaceDeclaration( visit(nd.getLoc()), copy(nd.getName()), copy(nd.getBody()), nd.isInstantiated(), nd.hasDeclareKeyword()); } @Override public INode visit(ImportWholeDeclaration nd, Void c) { return new ImportWholeDeclaration(visit(nd.getLoc()), copy(nd.getLhs()), copy(nd.getRhs())); } @Override public INode visit(ExportWholeDeclaration nd, Void c) { return new ExportWholeDeclaration(visit(nd.getLoc()), copy(nd.getRhs())); } @Override public INode visit(ExternalModuleReference nd, Void c) { return new ExternalModuleReference(visit(nd.getLoc()), copy(nd.getExpression())); } @Override public INode visit(DynamicImport nd, Void c) { return new DynamicImport(visit(nd.getLoc()), copy(nd.getSource())); } @Override public INode visit(InterfaceDeclaration nd, Void c) { return new InterfaceDeclaration( visit(nd.getLoc()), copy(nd.getName()), copy(nd.getTypeParameters()), copy(nd.getSuperInterfaces()), copy(nd.getBody())); } @Override public INode visit(KeywordTypeExpr nd, Void c) { return new KeywordTypeExpr(visit(nd.getLoc()), nd.getKeyword()); } @Override public INode visit(ArrayTypeExpr nd, Void c) { return new ArrayTypeExpr(visit(nd.getLoc()), copy(nd.getElementType())); } @Override public INode visit(UnionTypeExpr nd, Void c) { return new UnionTypeExpr(visit(nd.getLoc()), copy(nd.getElementTypes())); } @Override public INode visit(IndexedAccessTypeExpr nd, Void c) { return new IndexedAccessTypeExpr( visit(nd.getLoc()), copy(nd.getObjectType()), copy(nd.getIndexType())); } @Override public INode visit(IntersectionTypeExpr nd, Void c) { return new IntersectionTypeExpr(visit(nd.getLoc()), copy(nd.getElementTypes())); } @Override public INode visit(ParenthesizedTypeExpr nd, Void c) { return new ParenthesizedTypeExpr(visit(nd.getLoc()), copy(nd.getElementType())); } @Override public INode visit(TupleTypeExpr nd, Void c) { return new TupleTypeExpr(visit(nd.getLoc()), copy(nd.getElementTypes())); } @Override public INode visit(UnaryTypeExpr nd, Void c) { return new UnaryTypeExpr(visit(nd.getLoc()), nd.getKind(), copy(nd.getElementType())); } @Override public INode visit(GenericTypeExpr nd, Void c) { return new GenericTypeExpr( visit(nd.getLoc()), copy(nd.getTypeName()), copy(nd.getTypeArguments())); } @Override public INode visit(TypeofTypeExpr nd, Void c) { return new TypeofTypeExpr(visit(nd.getLoc()), copy(nd.getExpression())); } @Override public INode visit(PredicateTypeExpr nd, Void c) { return new PredicateTypeExpr( visit(nd.getLoc()), copy(nd.getExpression()), copy(nd.getTypeExpr()), nd.hasAssertsKeyword()); } @Override public INode visit(InterfaceTypeExpr nd, Void c) { return new InterfaceTypeExpr(visit(nd.getLoc()), copy(nd.getBody())); } @Override public INode visit(ExpressionWithTypeArguments nd, Void c) { return new ExpressionWithTypeArguments( visit(nd.getLoc()), copy(nd.getExpression()), copy(nd.getTypeArguments())); } @Override public INode visit(TypeParameter nd, Void c) { return new TypeParameter( visit(nd.getLoc()), copy(nd.getId()), copy(nd.getBound()), copy(nd.getDefault())); } @Override public INode visit(FunctionTypeExpr nd, Void c) { return new FunctionTypeExpr(visit(nd.getLoc()), copy(nd.getFunction()), nd.isConstructor()); } @Override public INode visit(TypeAssertion nd, Void c) { return new TypeAssertion( visit(nd.getLoc()), copy(nd.getExpression()), copy(nd.getTypeAnnotation()), nd.isAsExpression()); } @Override public INode visit(MappedTypeExpr nd, Void c) { return new MappedTypeExpr( visit(nd.getLoc()), copy(nd.getTypeParameter()), copy(nd.getElementType())); } @Override public INode visit(TypeAliasDeclaration nd, Void c) { return new TypeAliasDeclaration( visit(nd.getLoc()), copy(nd.getId()), copy(nd.getTypeParameters()), copy(nd.getDefinition())); } @Override public INode visit(EnumDeclaration nd, Void c) { return new EnumDeclaration( visit(nd.getLoc()), nd.isConst(), nd.hasDeclareKeyword(), copy(nd.getDecorators()), copy(nd.getId()), copy(nd.getMembers())); } @Override public INode visit(EnumMember nd, Void c) { return new EnumMember(visit(nd.getLoc()), copy(nd.getId()), copy(nd.getInitializer())); } @Override public INode visit(DecoratorList nd, Void c) { return new DecoratorList(visit(nd.getLoc()), copy(nd.getDecorators())); } @Override public INode visit(ExternalModuleDeclaration nd, Void c) { return new ExternalModuleDeclaration( visit(nd.getLoc()), copy(nd.getName()), copy(nd.getBody())); } @Override public INode visit(ExportAsNamespaceDeclaration nd, Void c) { return new ExportAsNamespaceDeclaration(visit(nd.getLoc()), copy(nd.getId())); } @Override public INode visit(GlobalAugmentationDeclaration nd, Void c) { return new GlobalAugmentationDeclaration(visit(nd.getLoc()), copy(nd.getBody())); } @Override public INode visit(NonNullAssertion nd, Void c) { return new NonNullAssertion(visit(nd.getLoc()), copy(nd.getExpression())); } @Override public INode visit(ConditionalTypeExpr nd, Void q) { return new ConditionalTypeExpr( visit(nd.getLoc()), copy(nd.getCheckType()), copy(nd.getExtendsType()), copy(nd.getTrueType()), copy(nd.getFalseType())); } @Override public INode visit(InferTypeExpr nd, Void c) { return new InferTypeExpr(visit(nd.getLoc()), copy(nd.getTypeParameter())); } @Override public INode visit(ImportTypeExpr nd, Void c) { return new ImportTypeExpr(visit(nd.getLoc()), copy(nd.getPath())); } @Override public INode visit(OptionalTypeExpr nd, Void c) { return new OptionalTypeExpr(visit(nd.getLoc()), copy(nd.getElementType())); } @Override public INode visit(RestTypeExpr nd, Void c) { return new RestTypeExpr(visit(nd.getLoc()), copy(nd.getArrayType())); } @Override public INode visit(XMLAnyName nd, Void c) { return new XMLAnyName(visit(nd.getLoc())); } @Override public INode visit(XMLAttributeSelector nd, Void c) { return new XMLAttributeSelector(visit(nd.getLoc()), copy(nd.getAttribute()), nd.isComputed()); } @Override public INode visit(XMLFilterExpression nd, Void c) { return new XMLFilterExpression(visit(nd.getLoc()), copy(nd.getLeft()), copy(nd.getRight())); } @Override public INode visit(XMLQualifiedIdentifier nd, Void c) { return new XMLQualifiedIdentifier( visit(nd.getLoc()), copy(nd.getLeft()), copy(nd.getRight()), nd.isComputed()); } @Override public INode visit(XMLDotDotExpression nd, Void c) { return new XMLDotDotExpression(visit(nd.getLoc()), copy(nd.getLeft()), copy(nd.getRight())); } }
26,943
29.618182
100
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/ReturnStatement.java
package com.semmle.js.ast; /** A return statement. */ public class ReturnStatement extends Statement { private final Expression argument; public ReturnStatement(SourceLocation loc, Expression argument) { super("ReturnStatement", loc); this.argument = argument; } @Override public <Q, A> A accept(Visitor<Q, A> v, Q q) { return v.visit(this, q); } /** Does this return statement have an argument expression? */ public boolean hasArgument() { return argument != null; } /** The argument expression of this return statement; may be null. */ public Expression getArgument() { return argument; } }
642
22.814815
71
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/AssignmentPattern.java
package com.semmle.js.ast; /** * An assignment pattern occurring in an lvalue position. * * <p>Assignment patterns specify default values for function parameters, for-in/for-of loop * variables and in destructuring assignments. We normalise them away during AST construction, * attaching information about the default value directly to the parameter or variable in question. * Hence, assignment patterns are not expected to appear in the AST the extractor works on. */ public class AssignmentPattern extends ABinaryExpression implements IPattern { public AssignmentPattern(SourceLocation loc, String operator, Expression left, Expression right) { super(loc, "AssignmentPattern", operator, left, right); } @Override public <Q, A> A accept(Visitor<Q, A> v, Q q) { return v.visit(this, q); } }
818
38
100
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/ExportNamedDeclaration.java
package com.semmle.js.ast; import java.util.List; /** * A named export declaration, which can be of one of the following forms: * * <ul> * <li><code>export var x = 23;</code> * <li><code>export { x, y } from 'foo';</code> * <li><code>export { x, y };</code> * </ul> */ public class ExportNamedDeclaration extends ExportDeclaration { private final Statement declaration; private final List<ExportSpecifier> specifiers; private final Literal source; private final boolean hasTypeKeyword; public ExportNamedDeclaration( SourceLocation loc, Statement declaration, List<ExportSpecifier> specifiers, Literal source) { this(loc, declaration, specifiers, source, false); } public ExportNamedDeclaration( SourceLocation loc, Statement declaration, List<ExportSpecifier> specifiers, Literal source, boolean hasTypeKeyword) { super("ExportNamedDeclaration", loc); this.declaration = declaration; this.specifiers = specifiers; this.source = source; this.hasTypeKeyword = hasTypeKeyword; } public Statement getDeclaration() { return declaration; } public boolean hasDeclaration() { return declaration != null; } public List<ExportSpecifier> getSpecifiers() { return specifiers; } public Literal getSource() { return source; } public boolean hasSource() { return source != null; } @Override public <C, R> R accept(Visitor<C, R> v, C c) { return v.visit(this, c); } /** Returns true if this is an <code>export type</code> declaration. */ public boolean hasTypeKeyword() { return hasTypeKeyword; } }
1,627
24.046154
100
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/XMLAnyName.java
package com.semmle.js.ast; public class XMLAnyName extends Expression { public XMLAnyName(SourceLocation loc) { super("XMLAnyName", loc); } @Override public <C, R> R accept(Visitor<C, R> v, C c) { return v.visit(this, c); } }
246
18
48
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/SequenceExpression.java
package com.semmle.js.ast; import java.util.List; /** A comma expression containing two or more expressions evaluated in sequence. */ public class SequenceExpression extends Expression { private final List<Expression> expressions; public SequenceExpression(SourceLocation loc, List<Expression> expressions) { super("SequenceExpression", loc); this.expressions = expressions; } @Override public <Q, A> A accept(Visitor<Q, A> v, Q q) { return v.visit(this, q); } /** The expressions in this sequence. */ public List<Expression> getExpressions() { return expressions; } }
608
24.375
83
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/AFunction.java
package com.semmle.js.ast; import com.semmle.ts.ast.DecoratorList; import com.semmle.ts.ast.ITypeExpression; import com.semmle.ts.ast.TypeParameter; import com.semmle.util.data.IntList; import java.util.ArrayList; import java.util.List; public class AFunction<B> { private final Identifier id; private final List<IPattern> params, allParams; private final List<Expression> rawParams, defaults; private final IPattern rest; private final B body; private final boolean generator, async; private final List<TypeParameter> typeParameters; private final ITypeExpression returnType; private final List<ITypeExpression> parameterTypes; private final ITypeExpression thisParameterType; private final List<DecoratorList> parameterDecorators; private final IntList optionalParameterIndices; public static final IntList noOptionalParams = IntList.create(0, 0); public AFunction( Identifier id, List<Expression> params, B body, boolean generator, boolean async, List<TypeParameter> typeParameters, List<ITypeExpression> parameterTypes, List<DecoratorList> parameterDecorators, ITypeExpression returnType, ITypeExpression thisParameterType, IntList optionalParameterIndices) { this.id = id; this.params = new ArrayList<IPattern>(params.size()); this.defaults = new ArrayList<Expression>(params.size()); this.parameterTypes = parameterTypes; this.body = body; this.generator = generator; this.async = async; this.rawParams = params; this.typeParameters = typeParameters; this.returnType = returnType; this.thisParameterType = thisParameterType; this.parameterDecorators = parameterDecorators; this.optionalParameterIndices = optionalParameterIndices; IPattern rest = null; for (Expression param : params) { if (param instanceof RestElement) { rest = (IPattern) ((RestElement) param).getArgument(); } else if (param instanceof AssignmentPattern) { AssignmentPattern ap = (AssignmentPattern) param; this.params.add((IPattern) ap.getLeft()); this.defaults.add(ap.getRight()); } else { // workaround for parser bug, which currently (erroneously) accepts // async arrow functions with parens around their parameters param = param.stripParens(); this.params.add((IPattern) param); this.defaults.add(null); } } this.rest = rest; this.allParams = new ArrayList<IPattern>(this.params); if (rest != null) this.allParams.add(rest); } /** Does this function have a name? */ public boolean hasId() { return id != null; } public Identifier getId() { return id; } public List<IPattern> getParams() { return params; } public boolean hasDefault(int i) { return i < defaults.size(); } public Expression getDefault(int i) { if (i >= defaults.size()) return null; return defaults.get(i); } public boolean hasRest() { return rest != null; } public IPattern getRest() { return rest; } public B getBody() { return body; } public boolean isGenerator() { return generator; } public boolean isAsync() { return async; } public List<IPattern> getAllParams() { return allParams; } public List<Expression> getRawParams() { return rawParams; } public ITypeExpression getReturnType() { return returnType; } public boolean hasParameterType(int i) { return getParameterType(i) != null; } public ITypeExpression getParameterType(int i) { if (i >= parameterTypes.size()) return null; return parameterTypes.get(i); } public List<ITypeExpression> getParameterTypes() { return parameterTypes; } public List<TypeParameter> getTypeParameters() { return typeParameters; } public ITypeExpression getThisParameterType() { return thisParameterType; } public List<DecoratorList> getParameterDecorators() { return parameterDecorators; } public IntList getOptionalParmaeterIndices() { return optionalParameterIndices; } }
4,124
25.273885
75
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/EmptyStatement.java
package com.semmle.js.ast; /** An empty statement <code>;</code>. */ public class EmptyStatement extends Statement { public EmptyStatement(SourceLocation loc) { super("EmptyStatement", loc); } @Override public <Q, A> A accept(Visitor<Q, A> v, Q q) { return v.visit(this, q); } }
299
20.428571
48
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/MemberExpression.java
package com.semmle.js.ast; import com.semmle.ts.ast.INodeWithSymbol; import com.semmle.ts.ast.ITypeExpression; /** A member expression, either computed (<code>e[f]</code>) or static (<code>e.f</code>). */ public class MemberExpression extends Expression implements ITypeExpression, INodeWithSymbol, Chainable { private final Expression object, property; private final boolean computed; private final boolean optional; private final boolean onOptionalChain; private int symbol = -1; public MemberExpression( SourceLocation loc, Expression object, Expression property, Boolean computed, Boolean optional, Boolean onOptionalChain) { super("MemberExpression", loc); this.object = object; this.property = property; this.computed = computed == Boolean.TRUE; this.optional = optional == Boolean.TRUE; this.onOptionalChain = onOptionalChain == Boolean.TRUE; } @Override public <Q, A> A accept(Visitor<Q, A> v, Q q) { return v.visit(this, q); } /** The base expression of this member expression. */ public Expression getObject() { return object; } /** * The property expression of this member expression; for static member expressions this is always * an {@link Identifier}. */ public Expression getProperty() { return property; } /** Is this a computed member expression? */ public boolean isComputed() { return computed; } @Override public boolean isOptional() { return optional; } @Override public boolean isOnOptionalChain() { return onOptionalChain; } @Override public int getSymbol() { return symbol; } @Override public void setSymbol(int symbol) { this.symbol = symbol; } }
1,750
22.986301
100
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/ConditionalExpression.java
package com.semmle.js.ast; /** A conditional expression such as <code>i &gt;= 0 ? a[i] : null</code>. */ public class ConditionalExpression extends Expression { private final Expression test; private final Expression consequent, alternate; public ConditionalExpression( SourceLocation loc, Expression test, Expression consequent, Expression alternate) { super("ConditionalExpression", loc); this.test = test; this.consequent = consequent; this.alternate = alternate; } @Override public <Q, A> A accept(Visitor<Q, A> v, Q q) { return v.visit(this, q); } /** The test expression of this conditional expression. */ public Expression getTest() { return test; } /** The then-branch of this conditional expression. */ public Expression getConsequent() { return consequent; } /** The else-branch of this conditional expression. */ public Expression getAlternate() { return alternate; } }
957
25.611111
89
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/LogicalExpression.java
package com.semmle.js.ast; /** * A short-circuiting binary expression, i.e., either <code>&amp;&amp;</code> or <code>||</code>. */ public class LogicalExpression extends ABinaryExpression { public LogicalExpression(SourceLocation loc, String operator, Expression left, Expression right) { super(loc, "LogicalExpression", operator, left, right); } @Override public <Q, A> A accept(Visitor<Q, A> v, Q q) { return v.visit(this, q); } }
455
27.5
100
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/SourceLocation.java
package com.semmle.js.ast; /** A source location representing a range of characters. */ public class SourceLocation { private String source; private Position start, end; public SourceLocation(String source, Position start, Position end) { this.source = source; this.start = start; this.end = end; } public SourceLocation(Position start) { this(null, start, null); } public SourceLocation(String source, Position start) { this(source, start, null); } public SourceLocation(SourceLocation that) { this(that.source, that.start, that.end); } /** The source code contained in this location. */ public String getSource() { return source; } /** Set the source code contain in this location. */ public void setSource(String source) { this.source = source; } /** The start position of the location. */ public Position getStart() { return start; } /** Set the start position of this location. */ public void setStart(Position start) { this.start = start; } /** The end position of the location. */ public Position getEnd() { return end; } /** Set the end position of this location. */ public void setEnd(Position end) { this.end = end; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((end == null) ? 0 : end.hashCode()); result = prime * result + ((start == null) ? 0 : start.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; SourceLocation other = (SourceLocation) obj; if (end == null) { if (other.end != null) return false; } else if (!end.equals(other.end)) return false; if (start == null) { if (other.start != null) return false; } else if (!start.equals(other.start)) return false; return true; } }
1,981
23.775
71
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/SourceElement.java
package com.semmle.js.ast; /** Common superclass of all source elements. */ public class SourceElement implements ISourceElement { private final SourceLocation loc; public SourceElement(SourceLocation loc) { this.loc = loc; } public boolean hasLoc() { return loc != null; } @Override public final SourceLocation getLoc() { return loc; } }
371
17.6
54
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/XMLAttributeSelector.java
package com.semmle.js.ast; public class XMLAttributeSelector extends Expression { final Expression attribute; final boolean computed; public XMLAttributeSelector(SourceLocation loc, Expression attribute, boolean computed) { super("XMLAttributeSelector", loc); this.attribute = attribute; this.computed = computed; } public Expression getAttribute() { return attribute; } public boolean isComputed() { return computed; } @Override public <C, R> R accept(Visitor<C, R> v, C c) { return v.visit(this, c); } }
557
20.461538
91
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/DoWhileStatement.java
package com.semmle.js.ast; /** A do-while statement of the form <code>do { ... } while(...);</code>. */ public class DoWhileStatement extends Loop { private final Expression test; public DoWhileStatement(SourceLocation loc, Expression test, Statement body) { super("DoWhileStatement", loc, body); this.test = test; } @Override public <Q, A> A accept(Visitor<Q, A> v, Q q) { return v.visit(this, q); } /** The test expression of this loop. */ public Expression getTest() { return test; } @Override public Node getContinueTarget() { return test; } }
597
21.148148
80
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/ClassExpression.java
package com.semmle.js.ast; import com.semmle.ts.ast.ITypeExpression; import com.semmle.ts.ast.TypeParameter; import java.util.Collections; import java.util.List; /** * A class expression as in * * <pre> * let ColouredPoint = class extends Point { * constructor(x, y, colour) { * super(x, y); * this.colour = colour; * } * }; * </pre> */ public class ClassExpression extends Expression { private final AClass klass; public ClassExpression(SourceLocation loc, Identifier id, Expression superClass, ClassBody body) { this(loc, id, Collections.emptyList(), superClass, Collections.emptyList(), body); } public ClassExpression( SourceLocation loc, Identifier id, List<TypeParameter> typeParameters, Expression superClass, List<ITypeExpression> superInterfaces, ClassBody body) { this(loc, new AClass(id, typeParameters, superClass, superInterfaces, body)); } public ClassExpression(SourceLocation loc, AClass klass) { super("ClassExpression", loc); this.klass = klass; } public AClass getClassDef() { return klass; } @Override public <C, R> R accept(Visitor<C, R> v, C c) { return v.visit(this, c); } public void addDecorators(List<Decorator> decorators) { klass.addDecorators(decorators); } public Iterable<Decorator> getDecorators() { return klass.getDecorators(); } }
1,398
22.711864
100
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/AwaitExpression.java
package com.semmle.js.ast; public class AwaitExpression extends Expression { private Expression argument; public AwaitExpression(SourceLocation loc, Expression argument) { super("AwaitExpression", loc); this.argument = argument; } public Expression getArgument() { return argument; } @Override public <C, R> R accept(Visitor<C, R> v, C c) { return v.visit(this, c); } }
406
19.35
67
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/ExportDefaultSpecifier.java
package com.semmle.js.ast; /** A default export specifier, such as <code>f</code> in <code>export f from 'foo';</code>. */ public class ExportDefaultSpecifier extends ExportSpecifier { public ExportDefaultSpecifier(SourceLocation loc, Identifier exported) { super("ExportDefaultSpecifier", loc, null, exported); } @Override public <C, R> R accept(Visitor<C, R> v, C c) { return v.visit(this, c); } }
420
29.071429
95
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/XMLDotDotExpression.java
package com.semmle.js.ast; public class XMLDotDotExpression extends Expression { final Expression left, right; public XMLDotDotExpression(SourceLocation loc, Expression left, Expression right) { super("XMLDotDotExpression", loc); this.left = left; this.right = right; } public Expression getLeft() { return left; } public Expression getRight() { return right; } @Override public <C, R> R accept(Visitor<C, R> v, C c) { return v.visit(this, c); } }
497
18.92
85
java
codeql
codeql-master/javascript/extractor/src/com/semmle/js/ast/ObjectExpression.java
package com.semmle.js.ast; import java.util.List; /** An object literal. */ public class ObjectExpression extends Expression { private final List<Property> properties; public ObjectExpression(SourceLocation loc, List<Property> properties) { super("ObjectExpression", loc); this.properties = properties; } @Override public <Q, A> A accept(Visitor<Q, A> v, Q q) { return v.visit(this, q); } /** The properties in this literal. */ public List<Property> getProperties() { return properties; } }
530
21.125
74
java