JavaScript: Autoformat extractor sources using google-java-format.

No special settings; command:

  find javascript/extractor/src -name "*.java" | xargs java -jar /path/to/google-java-format-1.7-all-deps.jar --replace
This commit is contained in:
Max Schaefer
2019-02-28 14:30:06 +00:00
parent 5478e0da62
commit c4fa29dd0f
304 changed files with 30389 additions and 30395 deletions

View File

@@ -1,29 +1,30 @@
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}.
* 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;
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 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 String getOperator() {
return operator;
}
public Expression getLeft() {
return left;
}
public Expression getLeft() {
return left;
}
public Expression getRight() {
return right;
}
public Expression getRight() {
return right;
}
}

View File

@@ -1,81 +1,82 @@
package com.semmle.js.ast;
import java.util.ArrayList;
import java.util.List;
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}.
*/
/** 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;
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 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 Identifier getId() {
return id;
}
public boolean hasId() {
return id != null;
}
public boolean hasId() {
return id != null;
}
public List<TypeParameter> getTypeParameters() {
return typeParameters;
}
public List<TypeParameter> getTypeParameters() {
return typeParameters;
}
public boolean hasTypeParameters() {
return !typeParameters.isEmpty();
}
public boolean hasTypeParameters() {
return !typeParameters.isEmpty();
}
public Expression getSuperClass() {
return superClass;
}
public Expression getSuperClass() {
return superClass;
}
public boolean hasSuperClass() {
return superClass != null;
}
public boolean hasSuperClass() {
return superClass != null;
}
public List<ITypeExpression> getSuperInterfaces() {
return superInterfaces;
}
public List<ITypeExpression> getSuperInterfaces() {
return superInterfaces;
}
public ClassBody getBody() {
return body;
}
public ClassBody getBody() {
return body;
}
public void addDecorators(List<Decorator> decorators) {
this.decorators.addAll(decorators);
}
public void addDecorators(List<Decorator> decorators) {
this.decorators.addAll(decorators);
}
public List<Decorator> getDecorators() {
return decorators;
}
public List<Decorator> getDecorators() {
return decorators;
}
@Override
public int getSymbol() {
return typeSymbol;
}
@Override
public int getSymbol() {
return typeSymbol;
}
@Override
public void setSymbol(int symbol) {
this.typeSymbol = symbol;
}
@Override
public void setSymbol(int symbol) {
this.typeSymbol = symbol;
}
}

View File

@@ -1,144 +1,146 @@
package com.semmle.js.ast;
import java.util.ArrayList;
import java.util.List;
import com.semmle.ts.ast.DecoratorList;
import com.semmle.ts.ast.ITypeExpression;
import com.semmle.ts.ast.TypeParameter;
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 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;
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) {
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;
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) {
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;
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;
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);
}
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;
}
/** Does this function have a name? */
public boolean hasId() {
return id != null;
}
public Identifier getId() {
return id;
}
public Identifier getId() {
return id;
}
public List<IPattern> getParams() {
return params;
}
public List<IPattern> getParams() {
return params;
}
public boolean hasDefault(int i) {
return i < defaults.size();
}
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 Expression getDefault(int i) {
if (i >= defaults.size()) return null;
return defaults.get(i);
}
public boolean hasRest() {
return rest != null;
}
public boolean hasRest() {
return rest != null;
}
public IPattern getRest() {
return rest;
}
public IPattern getRest() {
return rest;
}
public B getBody() {
return body;
}
public B getBody() {
return body;
}
public boolean isGenerator() {
return generator;
}
public boolean isGenerator() {
return generator;
}
public boolean isAsync() {
return async;
}
public boolean isAsync() {
return async;
}
public List<IPattern> getAllParams() {
return allParams;
}
public List<IPattern> getAllParams() {
return allParams;
}
public List<Expression> getRawParams() {
return rawParams;
}
public List<Expression> getRawParams() {
return rawParams;
}
public ITypeExpression getReturnType() {
return returnType;
}
public ITypeExpression getReturnType() {
return returnType;
}
public boolean hasParameterType(int i) {
return getParameterType(i) != null;
}
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 ITypeExpression getParameterType(int i) {
if (i >= parameterTypes.size()) return null;
return parameterTypes.get(i);
}
public List<ITypeExpression> getParameterTypes() {
return parameterTypes;
}
public List<ITypeExpression> getParameterTypes() {
return parameterTypes;
}
public List<TypeParameter> getTypeParameters() {
return typeParameters;
}
public List<TypeParameter> getTypeParameters() {
return typeParameters;
}
public ITypeExpression getThisParameterType() {
return thisParameterType;
}
public ITypeExpression getThisParameterType() {
return thisParameterType;
}
public List<DecoratorList> getParameterDecorators() {
return parameterDecorators;
}
}
public List<DecoratorList> getParameterDecorators() {
return parameterDecorators;
}
}

View File

@@ -1,65 +1,147 @@
package com.semmle.js.ast;
import java.util.List;
import com.semmle.ts.ast.DecoratorList;
import com.semmle.ts.ast.ITypeExpression;
import com.semmle.ts.ast.TypeParameter;
import java.util.List;
/**
* A function expression, which may be either an {@link ArrowFunctionExpression} or
* a normal {@link FunctionExpression}.
* 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 final AFunction<? extends Node> fn;
private int symbol = -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) {
super(type, loc);
this.fn = new AFunction<Node>(id, params, body, generator == Boolean.TRUE, async == Boolean.TRUE, typeParameters, parameterTypes,
parameterDecorators, returnType, thisParameterType);
}
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) {
super(type, loc);
this.fn =
new AFunction<Node>(
id,
params,
body,
generator == Boolean.TRUE,
async == Boolean.TRUE,
typeParameters,
parameterTypes,
parameterDecorators,
returnType,
thisParameterType);
}
public AFunctionExpression(String type, SourceLocation loc, AFunction<? extends Node> fn) {
super(type, loc);
this.fn = fn;
}
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 Identifier getId() {
return fn.getId();
}
@Override
public boolean hasDeclareKeyword() {
return false;
}
@Override
public List<IPattern> getParams() {
return fn.getParams();
}
@Override
public int getSymbol() {
return symbol;
}
@Override
public boolean hasDefault(int i) {
return fn.hasDefault(i);
}
@Override
public void setSymbol(int symbol) {
this.symbol = symbol;
}
@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;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -2,26 +2,22 @@ package com.semmle.js.ast;
import java.util.List;
/**
* An array expression such as <code>[x, , "hello"]</code>.
*/
/** An array expression such as <code>[x, , "hello"]</code>. */
public class ArrayExpression extends Expression {
private final List<Expression> elements;
private final List<Expression> elements;
public ArrayExpression(SourceLocation loc, List<Expression> elements) {
super("ArrayExpression", loc);
this.elements = 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);
}
@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;
}
/** The elements of the array; omitted elements are represented by {@literal null}. */
public List<Expression> getElements() {
return elements;
}
}

View File

@@ -3,76 +3,68 @@ package com.semmle.js.ast;
import java.util.ArrayList;
import java.util.List;
/**
* An array pattern as in <code>var [x, y] = z;</code>.
*/
/** 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;
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;
}
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);
}
@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 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;
}
/** 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;
}
/** 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;
}
/** 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;
}
/**
* The raw element patterns of the array pattern; patterns with defaults are represented as {@link
* AssignmentPattern}s.
*/
public List<Expression> getRawElements() {
return rawElements;
}
}

View File

@@ -1,30 +1,55 @@
package com.semmle.js.ast;
import java.util.Collections;
import java.util.List;
import com.semmle.ts.ast.ITypeExpression;
import com.semmle.ts.ast.TypeParameter;
import java.util.Collections;
import java.util.List;
/**
* An arrow function expression such as <code>(x) =&gt; x*x</code>.
*/
/** 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);
}
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);
}
public ArrowFunctionExpression(SourceLocation loc,
List<Expression> params, Node body, Boolean generator, Boolean async,
List<TypeParameter> typeParameters, List<ITypeExpression> parameterTypes, ITypeExpression returnType) {
super("ArrowFunctionExpression", loc, null, params, body, generator, async, typeParameters, parameterTypes, Collections.emptyList(),
returnType, null);
}
public ArrowFunctionExpression(
SourceLocation loc,
List<Expression> params,
Node body,
Boolean generator,
Boolean async,
List<TypeParameter> typeParameters,
List<ITypeExpression> parameterTypes,
ITypeExpression returnType) {
super(
"ArrowFunctionExpression",
loc,
null,
params,
body,
generator,
async,
typeParameters,
parameterTypes,
Collections.emptyList(),
returnType,
null);
}
@Override
public <Q, A> A accept(Visitor<Q, A> v, Q q) {
return v.visit(this, q);
}
@Override
public <Q, A> A accept(Visitor<Q, A> v, Q q) {
return v.visit(this, q);
}
}

View File

@@ -1,15 +1,14 @@
package com.semmle.js.ast;
/**
* An assignment expression such as <code>x = 23</code> or <code>y += 19</code>.
*/
/** 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);
}
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);
}
@Override
public <Q, A> A accept(Visitor<Q, A> v, Q q) {
return v.visit(this, q);
}
}

View File

@@ -1,21 +1,20 @@
package com.semmle.js.ast;
/**
* An assignment pattern occurring in an lvalue position.
*
* 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.
* <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);
}
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);
}
@Override
public <Q, A> A accept(Visitor<Q, A> v, Q q) {
return v.visit(this, q);
}
}

View File

@@ -1,20 +1,19 @@
package com.semmle.js.ast;
public class AwaitExpression extends Expression {
private Expression argument;
private Expression argument;
public AwaitExpression(SourceLocation loc, Expression argument) {
super("AwaitExpression", loc);
this.argument = 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);
}
public Expression getArgument() {
return argument;
}
@Override
public <C, R> R accept(Visitor<C, R> v, C c) {
return v.visit(this, c);
}
}

View File

@@ -1,15 +1,13 @@
package com.semmle.js.ast;
/**
* A binary expression such as <code>x + y</code>.
*/
/** A binary expression such as <code>x + y</code>. */
public class BinaryExpression extends ABinaryExpression {
public BinaryExpression(SourceLocation loc, String operator, Expression left, Expression right) {
super(loc, "BinaryExpression", operator, left, right);
}
public BinaryExpression(SourceLocation loc, String operator, Expression left, Expression right) {
super(loc, "BinaryExpression", operator, left, right);
}
@Override
public <Q, A> A accept(Visitor<Q, A> v, Q q) {
return v.visit(this, q);
}
@Override
public <Q, A> A accept(Visitor<Q, A> v, Q q) {
return v.visit(this, q);
}
}

View File

@@ -1,28 +1,28 @@
package com.semmle.js.ast;
public class BindExpression extends Expression {
private final Expression object, callee;
private final Expression object, callee;
public BindExpression(SourceLocation loc, Expression object, Expression callee) {
super("BindExpression", loc);
this.object = object;
this.callee = 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 boolean hasObject() {
return object != null;
}
public Expression getObject() {
return object;
}
public Expression getObject() {
return object;
}
public Expression getCallee() {
return callee;
}
public Expression getCallee() {
return callee;
}
@Override
public <C, R> R accept(Visitor<C, R> v, C c) {
return v.visit(this, c);
}
@Override
public <C, R> R accept(Visitor<C, R> v, C c) {
return v.visit(this, c);
}
}

View File

@@ -2,26 +2,22 @@ package com.semmle.js.ast;
import java.util.List;
/**
* A block statement such as <code>{ console.log("Hi"); }</code>.
*/
/** A block statement such as <code>{ console.log("Hi"); }</code>. */
public class BlockStatement extends Statement {
private final List<Statement> body;
private final List<Statement> body;
public BlockStatement(SourceLocation loc, List<Statement> body) {
super("BlockStatement", loc);
this.body = 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);
}
@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;
}
/** The statements in the block. */
public List<Statement> getBody() {
return body;
}
}

View File

@@ -1,15 +1,16 @@
package com.semmle.js.ast;
/**
* A break statement either with a label (<code>break outer;</code>) or without (<code>break;</code>).
* 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);
}
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);
}
@Override
public <Q, A> A accept(Visitor<Q, A> v, Q q) {
return v.visit(this, q);
}
}

View File

@@ -1,19 +1,22 @@
package com.semmle.js.ast;
import com.semmle.ts.ast.ITypeExpression;
import java.util.List;
import com.semmle.ts.ast.ITypeExpression;
/**
* A function call expression such as <code>f(1, 1)</code>.
*/
/** 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);
}
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);
}
@Override
public <Q, A> A accept(Visitor<Q, A> v, Q q) {
return v.visit(this, q);
}
}

View File

@@ -1,50 +1,40 @@
package com.semmle.js.ast;
/**
* A catch clause with or without a guarding expression.
*/
/** 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;
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;
}
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);
}
@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;
}
/** 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;
}
/** 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 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;
}
/** The body of the catch clause. */
public BlockStatement getBody() {
return body;
}
}

View File

@@ -1,16 +1,10 @@
package com.semmle.js.ast;
/**
* A chainable expression, such as a member access or function call.
*/
/** 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 step of the chain optional? */
abstract boolean isOptional();
/**
* Is this on an optional chain?
*/
abstract boolean isOnOptionalChain();
/** Is this on an optional chain? */
abstract boolean isOnOptionalChain();
}

View File

@@ -2,35 +2,30 @@ package com.semmle.js.ast;
import java.util.List;
/**
* The body of a {@linkplain ClassDeclaration} or {@linkplain ClassExpression}.
*/
/** The body of a {@linkplain ClassDeclaration} or {@linkplain ClassExpression}. */
public class ClassBody extends Node {
private final List<MemberDefinition<?>> body;
private final List<MemberDefinition<?>> body;
public ClassBody(SourceLocation loc, List<MemberDefinition<?>> body) {
super("ClassBody", loc);
this.body = body;
}
public ClassBody(SourceLocation loc, List<MemberDefinition<?>> body) {
super("ClassBody", loc);
this.body = body;
}
public List<MemberDefinition<?>> getBody() {
return body;
}
public List<MemberDefinition<?>> getBody() {
return body;
}
public void addMember(MemberDefinition<?> md) {
body.add(md);
}
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);
}
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);
}
}

View File

@@ -1,10 +1,9 @@
package com.semmle.js.ast;
import java.util.Collections;
import java.util.List;
import com.semmle.ts.ast.ITypeExpression;
import com.semmle.ts.ast.TypeParameter;
import java.util.Collections;
import java.util.List;
/**
* A class declaration such as
@@ -19,48 +18,61 @@ import com.semmle.ts.ast.TypeParameter;
* </pre>
*/
public class ClassDeclaration extends Statement {
private final AClass klass;
private final boolean hasDeclareKeyword;
private final boolean hasAbstractKeyword;
private final AClass klass;
private final boolean hasDeclareKeyword;
private final boolean hasAbstractKeyword;
public ClassDeclaration(SourceLocation loc, Identifier id, Expression superClass, ClassBody body) {
this(loc, id, Collections.emptyList(), superClass, Collections.emptyList(), body, false, false);
}
public ClassDeclaration(
SourceLocation loc, Identifier id, Expression superClass, ClassBody body) {
this(loc, id, Collections.emptyList(), superClass, Collections.emptyList(), body, false, false);
}
public ClassDeclaration(SourceLocation loc, Identifier id, List<TypeParameter> typeParameters, Expression superClass,
List<ITypeExpression> superInterfaces, ClassBody body, boolean hasDeclareKeyword, boolean hasAbstractKeyword) {
this(loc, new AClass(id, typeParameters, superClass, superInterfaces, body), hasDeclareKeyword, hasAbstractKeyword);
}
public ClassDeclaration(
SourceLocation loc,
Identifier id,
List<TypeParameter> typeParameters,
Expression superClass,
List<ITypeExpression> superInterfaces,
ClassBody body,
boolean hasDeclareKeyword,
boolean hasAbstractKeyword) {
this(
loc,
new AClass(id, typeParameters, superClass, superInterfaces, body),
hasDeclareKeyword,
hasAbstractKeyword);
}
public ClassDeclaration(SourceLocation loc, AClass klass, boolean hasDeclareKeyword, boolean hasAbstractKeyword) {
super("ClassDeclaration", loc);
this.klass = klass;
this.hasDeclareKeyword = hasDeclareKeyword;
this.hasAbstractKeyword = hasAbstractKeyword;
}
public ClassDeclaration(
SourceLocation loc, AClass klass, boolean hasDeclareKeyword, boolean hasAbstractKeyword) {
super("ClassDeclaration", loc);
this.klass = klass;
this.hasDeclareKeyword = hasDeclareKeyword;
this.hasAbstractKeyword = hasAbstractKeyword;
}
public AClass getClassDef() {
return klass;
}
public AClass getClassDef() {
return klass;
}
@Override
public <C, R> R accept(Visitor<C, R> v, C c) {
return v.visit(this, c);
}
@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 void addDecorators(List<Decorator> decorators) {
klass.addDecorators(decorators);
}
public List<Decorator> getDecorators() {
return klass.getDecorators();
}
public List<Decorator> getDecorators() {
return klass.getDecorators();
}
public boolean hasDeclareKeyword() {
return hasDeclareKeyword;
}
public boolean hasDeclareKeyword() {
return hasDeclareKeyword;
}
public boolean hasAbstractKeyword() {
return hasAbstractKeyword;
}
public boolean hasAbstractKeyword() {
return hasAbstractKeyword;
}
}

View File

@@ -1,10 +1,9 @@
package com.semmle.js.ast;
import java.util.Collections;
import java.util.List;
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
@@ -19,36 +18,41 @@ import com.semmle.ts.ast.TypeParameter;
* </pre>
*/
public class ClassExpression extends Expression {
private final AClass klass;
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, 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,
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 ClassExpression(SourceLocation loc, AClass klass) {
super("ClassExpression", loc);
this.klass = klass;
}
public AClass getClassDef() {
return klass;
}
public AClass getClassDef() {
return klass;
}
@Override
public <C, R> R accept(Visitor<C, R> v, C c) {
return v.visit(this, c);
}
@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 void addDecorators(List<Decorator> decorators) {
klass.addDecorators(decorators);
}
public Iterable<Decorator> getDecorators() {
return klass.getDecorators();
}
public Iterable<Decorator> getDecorators() {
return klass.getDecorators();
}
}

View File

@@ -8,71 +8,53 @@ import static com.semmle.js.ast.Comment.Kind.LINE;
/**
* A source code comment.
*
* This is not part of the SpiderMonkey AST format.
* <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,
/** 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,
/** 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 start of an HTML comment (<code>&lt;!--</code>). */
HTML_START,
/**
* The end of an HTML comment (<code>--&gt;</code>).
*/
HTML_END
};
/** The end of an HTML comment (<code>--&gt;</code>). */
HTML_END
};
private final String text;
private final Kind kind;
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;
}
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;
}
/** 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("*");
}
/** Is this a JSDoc documentation comment? */
public boolean isDocComment() {
return kind == BLOCK && text.startsWith("*");
}
/**
* The text of the comment, not including its delimiters.
*
* For documentation comments, the leading asterisk is included.
*/
public String getText() {
return text;
}
/**
* The text of the comment, not including its delimiters.
*
* <p>For documentation comments, the leading asterisk is included.
*/
public String getText() {
return text;
}
}

View File

@@ -1,43 +1,35 @@
package com.semmle.js.ast;
/**
* A block in a comprehension expression.
*/
/** A block in a comprehension expression. */
public class ComprehensionBlock extends Expression {
private final IPattern left;
private final Expression right;
private final boolean of;
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;
}
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);
}
@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 iterator variable of this comprehension block. */
public IPattern getLeft() {
return left;
}
/**
* The expression this comprehension block iterates over.
*/
public Expression getRight() {
return right;
}
/** 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;
}
/** Is this a <code>for-of</code> comprehension block? */
public boolean isOf() {
return of;
}
}

View File

@@ -2,60 +2,53 @@ package com.semmle.js.ast;
import java.util.List;
/**
* A comprehension expression.
*/
/** 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;
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;
}
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);
}
@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 body expression of this comprehension. */
public Expression getBody() {
return body;
}
/**
* The comprehension blocks of this comprehension.
*/
public List<ComprehensionBlock> getBlocks() {
return blocks;
}
/** 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;
}
/** 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;
}
/** The filter expression of this comprehension; may be null. */
public Expression getFilter() {
return filter;
}
/**
* Is this a generator expression?
*/
public boolean isGenerator() {
return generator;
}
/** Is this a generator expression? */
public boolean isGenerator() {
return generator;
}
}

View File

@@ -1,42 +1,35 @@
package com.semmle.js.ast;
/**
* A conditional expression such as <code>i &gt;= 0 ? a[i] : null</code>.
*/
/** 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;
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;
}
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);
}
@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 test expression of this conditional expression. */
public Expression getTest() {
return test;
}
/**
* The then-branch of this conditional expression.
*/
public Expression getConsequent() {
return consequent;
}
/** The then-branch of this conditional expression. */
public Expression getConsequent() {
return consequent;
}
/**
* The else-branch of this conditional expression.
*/
public Expression getAlternate() {
return alternate;
}
/** The else-branch of this conditional expression. */
public Expression getAlternate() {
return alternate;
}
}

View File

@@ -1,15 +1,16 @@
package com.semmle.js.ast;
/**
* A continue statement either with a label (<code>continue outer;</code>) or without (<code>continue;</code>).
* 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);
}
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);
}
@Override
public <Q, A> A accept(Visitor<Q, A> v, Q q) {
return v.visit(this, q);
}
}

View File

@@ -1,15 +1,13 @@
package com.semmle.js.ast;
/**
* A debugger statement <code>debugger;</code>.
*/
/** A debugger statement <code>debugger;</code>. */
public class DebuggerStatement extends Statement {
public DebuggerStatement(SourceLocation loc) {
super("DebuggerStatement", loc);
}
public DebuggerStatement(SourceLocation loc) {
super("DebuggerStatement", loc);
}
@Override
public <Q, A> A accept(Visitor<Q, A> v, Q q) {
return v.visit(this, q);
}
@Override
public <Q, A> A accept(Visitor<Q, A> v, Q q) {
return v.visit(this, q);
}
}

View File

@@ -4,125 +4,145 @@ import java.util.Arrays;
import java.util.List;
/**
* Defines bitmasks where each bit corresponds to a flag on
* {@linkplain MemberDefinition} or {@linkplain VariableDeclarator}.
* Defines bitmasks where each bit corresponds to a flag on {@linkplain MemberDefinition} or
* {@linkplain VariableDeclarator}.
*/
public class DeclarationFlags {
public static final int computed = 1 << 0;
public static final int abstract_ = 1 << 1;
public static final int static_ = 1 << 2;
public static final int readonly = 1 << 3;
public static final int public_ = 1 << 4;
public static final int private_ = 1 << 5;
public static final int protected_ = 1 << 6;
public static final int optional = 1 << 7;
public static final int definiteAssignmentAssertion = 1 << 8;
public static final int computed = 1 << 0;
public static final int abstract_ = 1 << 1;
public static final int static_ = 1 << 2;
public static final int readonly = 1 << 3;
public static final int public_ = 1 << 4;
public static final int private_ = 1 << 5;
public static final int protected_ = 1 << 6;
public static final int optional = 1 << 7;
public static final int definiteAssignmentAssertion = 1 << 8;
public static final int none = 0;
public static final int numberOfFlags = 9;
public static final int none = 0;
public static final int numberOfFlags = 9;
public static final List<String> names = Arrays.asList("computed", "abstract", "static", "readonly", "public", "private", "protected",
"optional", "definiteAssignmentAssertion");
public static final List<String> names =
Arrays.asList(
"computed",
"abstract",
"static",
"readonly",
"public",
"private",
"protected",
"optional",
"definiteAssignmentAssertion");
public static final List<String> relationNames = Arrays.asList("isComputed", "isAbstractMember", "isStatic", "hasReadonlyKeyword",
"hasPublicKeyword", "hasPrivateKeyword", "hasProtectedKeyword", "isOptionalMember", "hasDefiniteAssignmentAssertion");
public static final List<String> relationNames =
Arrays.asList(
"isComputed",
"isAbstractMember",
"isStatic",
"hasReadonlyKeyword",
"hasPublicKeyword",
"hasPrivateKeyword",
"hasProtectedKeyword",
"isOptionalMember",
"hasDefiniteAssignmentAssertion");
public static boolean isComputed(int flags) {
return (flags & computed) != 0;
}
public static boolean isComputed(int flags) {
return (flags & computed) != 0;
}
public static boolean isAbstract(int flags) {
return (flags & abstract_) != 0;
}
public static boolean isAbstract(int flags) {
return (flags & abstract_) != 0;
}
public static boolean isStatic(int flags) {
return (flags & static_) != 0;
}
public static boolean isStatic(int flags) {
return (flags & static_) != 0;
}
public static boolean isReadonly(int flags) {
return (flags & readonly) != 0;
}
public static boolean isReadonly(int flags) {
return (flags & readonly) != 0;
}
public static boolean isPublic(int flags) {
return (flags & public_) != 0;
}
public static boolean isPublic(int flags) {
return (flags & public_) != 0;
}
public static boolean isPrivate(int flags) {
return (flags & private_) != 0;
}
public static boolean isPrivate(int flags) {
return (flags & private_) != 0;
}
public static boolean isProtected(int flags) {
return (flags & protected_) != 0;
}
public static boolean isProtected(int flags) {
return (flags & protected_) != 0;
}
public static boolean isOptional(int flags) {
return (flags & optional) != 0;
}
public static boolean isOptional(int flags) {
return (flags & optional) != 0;
}
public static boolean hasDefiniteAssignmentAssertion(int flags) {
return (flags & definiteAssignmentAssertion) != 0;
}
public static boolean hasDefiniteAssignmentAssertion(int flags) {
return (flags & definiteAssignmentAssertion) != 0;
}
/** Returns a mask with the computed bit set to the value of <tt>enable</tt>. */
public static int getComputed(boolean enable) {
return enable ? computed : 0;
}
/** Returns a mask with the computed bit set to the value of <tt>enable</tt>. */
public static int getComputed(boolean enable) {
return enable ? computed : 0;
}
/** Returns a mask with the abstract bit set to the value of <tt>enable</tt>. */
public static int getAbstract(boolean enable) {
return enable ? abstract_ : 0;
}
/** Returns a mask with the abstract bit set to the value of <tt>enable</tt>. */
public static int getAbstract(boolean enable) {
return enable ? abstract_ : 0;
}
/** Returns a mask with the static bit set to the value of <tt>enable</tt>. */
public static int getStatic(boolean enable) {
return enable ? static_ : 0;
}
/** Returns a mask with the static bit set to the value of <tt>enable</tt>. */
public static int getStatic(boolean enable) {
return enable ? static_ : 0;
}
/** Returns a mask with the public bit set to the value of <tt>enable</tt>. */
public static int getPublic(boolean enable) {
return enable ? public_ : 0;
}
/** Returns a mask with the public bit set to the value of <tt>enable</tt>. */
public static int getPublic(boolean enable) {
return enable ? public_ : 0;
}
/** Returns a mask with the readonly bit set to the value of <tt>enable</tt>. */
public static int getReadonly(boolean enable) {
return enable ? readonly : 0;
}
/** Returns a mask with the readonly bit set to the value of <tt>enable</tt>. */
public static int getReadonly(boolean enable) {
return enable ? readonly : 0;
}
/** Returns a mask with the private bit set to the value of <tt>enable</tt>. */
public static int getPrivate(boolean enable) {
return enable ? private_ : 0;
}
/** Returns a mask with the private bit set to the value of <tt>enable</tt>. */
public static int getPrivate(boolean enable) {
return enable ? private_ : 0;
}
/** Returns a mask with the protected bit set to the value of <tt>enable</tt>. */
public static int getProtected(boolean enable) {
return enable ? protected_ : 0;
}
/** Returns a mask with the protected bit set to the value of <tt>enable</tt>. */
public static int getProtected(boolean enable) {
return enable ? protected_ : 0;
}
/** Returns a mask with the optional bit set to the value of <tt>enable</tt>. */
public static int getOptional(boolean enable) {
return enable ? optional : 0;
}
/** Returns a mask with the optional bit set to the value of <tt>enable</tt>. */
public static int getOptional(boolean enable) {
return enable ? optional : 0;
}
/** Returns a mask with the definite assignment assertion bit set to the value of <tt>enable</tt>. */
public static int getDefiniteAssignmentAssertion(boolean enable) {
return enable ? definiteAssignmentAssertion : 0;
}
/**
* Returns a mask with the definite assignment assertion bit set to the value of <tt>enable</tt>.
*/
public static int getDefiniteAssignmentAssertion(boolean enable) {
return enable ? definiteAssignmentAssertion : 0;
}
/** Returns true if the <tt>n</tt>th bit is set in <tt>flags</tt>. */
public static boolean hasNthFlag(int flags, int n) {
return (flags & (1 << n)) != 0;
}
/** Returns true if the <tt>n</tt>th bit is set in <tt>flags</tt>. */
public static boolean hasNthFlag(int flags, int n) {
return (flags & (1 << n)) != 0;
}
public static String getFlagNames(int flags) {
StringBuilder b = new StringBuilder();
for (int i = 0; i < numberOfFlags; ++i) {
if (hasNthFlag(flags, i)) {
if (b.length() > 0) {
b.append(", ");
}
b.append(names.get(i));
}
}
return b.toString();
}
public static String getFlagNames(int flags) {
StringBuilder b = new StringBuilder();
for (int i = 0; i < numberOfFlags; ++i) {
if (hasNthFlag(flags, i)) {
if (b.length() > 0) {
b.append(", ");
}
b.append(names.get(i));
}
}
return b.toString();
}
}

View File

@@ -1,19 +1,19 @@
package com.semmle.js.ast;
public class Decorator extends Expression {
private final Expression expression;
private final Expression expression;
public Decorator(SourceLocation loc, Expression expression) {
super("Decorator", loc);
this.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);
}
@Override
public <C, R> R accept(Visitor<C, R> v, C c) {
return v.visit(this, c);
}
public Expression getExpression() {
return expression;
}
public Expression getExpression() {
return expression;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,4 @@
package com.semmle.js.ast;
/**
* An array or object pattern.
*/
public interface DestructuringPattern extends IPattern {
}
/** An array or object pattern. */
public interface DestructuringPattern extends IPattern {}

View File

@@ -1,30 +1,26 @@
package com.semmle.js.ast;
/**
* A do-while statement of the form <code>do { ... } while(...);</code>.
*/
/** A do-while statement of the form <code>do { ... } while(...);</code>. */
public class DoWhileStatement extends Loop {
private final Expression test;
private final Expression test;
public DoWhileStatement(SourceLocation loc, Expression test, Statement body) {
super("DoWhileStatement", loc, body);
this.test = 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);
}
@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;
}
/** The test expression of this loop. */
public Expression getTest() {
return test;
}
@Override
public Node getContinueTarget() {
return test;
}
@Override
public Node getContinueTarget() {
return test;
}
}

View File

@@ -1,19 +1,19 @@
package com.semmle.js.ast;
public class DynamicImport extends Expression {
private final Expression source;
private final Expression source;
public DynamicImport(SourceLocation loc, Expression source) {
super("DynamicImport", loc);
this.source = source;
}
public DynamicImport(SourceLocation loc, Expression source) {
super("DynamicImport", loc);
this.source = source;
}
public Expression getSource() {
return source;
}
public Expression getSource() {
return source;
}
@Override
public <C, R> R accept(Visitor<C, R> v, C c) {
return v.visit(this, c);
}
@Override
public <C, R> R accept(Visitor<C, R> v, C c) {
return v.visit(this, c);
}
}

View File

@@ -1,15 +1,13 @@
package com.semmle.js.ast;
/**
* An empty statement <code>;</code>.
*/
/** An empty statement <code>;</code>. */
public class EmptyStatement extends Statement {
public EmptyStatement(SourceLocation loc) {
super("EmptyStatement", loc);
}
public EmptyStatement(SourceLocation loc) {
super("EmptyStatement", loc);
}
@Override
public <Q, A> A accept(Visitor<Q, A> v, Q q) {
return v.visit(this, q);
}
@Override
public <Q, A> A accept(Visitor<Q, A> v, Q q) {
return v.visit(this, q);
}
}

View File

@@ -4,55 +4,49 @@ 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;
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;
}
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;
}
/**
* 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;
}
/** 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;
}
/** 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;
}
/** The expression this loop iterates over. */
public Expression getRight() {
return right;
}
@Override
public Node getContinueTarget() {
return this;
}
@Override
public Node getContinueTarget() {
return this;
}
}

View File

@@ -8,19 +8,19 @@ package com.semmle.js.ast;
* </pre>
*/
public class ExportAllDeclaration extends ExportDeclaration {
private final Literal source;
private final Literal source;
public ExportAllDeclaration(SourceLocation loc, Literal source) {
super("ExportAllDeclaration", loc);
this.source = source;
}
public ExportAllDeclaration(SourceLocation loc, Literal source) {
super("ExportAllDeclaration", loc);
this.source = source;
}
public Literal getSource() {
return source;
}
public Literal getSource() {
return source;
}
@Override
public <C, R> R accept(Visitor<C, R> v, C c) {
return v.visit(this, c);
}
@Override
public <C, R> R accept(Visitor<C, R> v, C c) {
return v.visit(this, c);
}
}

View File

@@ -2,8 +2,7 @@ package com.semmle.js.ast;
public abstract class ExportDeclaration extends Statement {
public ExportDeclaration(String type, SourceLocation loc) {
super(type, loc);
}
public ExportDeclaration(String type, SourceLocation loc) {
super(type, loc);
}
}

View File

@@ -14,23 +14,23 @@ package com.semmle.js.ast;
* </pre>
*/
public class ExportDefaultDeclaration extends ExportDeclaration {
/**
* Either an {@linkplain Expression} or a {@linkplain FunctionDeclaration} or
* a {@linkplain ClassDeclaration}.
*/
private final Node declaration;
/**
* 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 ExportDefaultDeclaration(SourceLocation loc, Node declaration) {
super("ExportDefaultDeclaration", loc);
this.declaration = declaration;
}
public Node getDeclaration() {
return declaration;
}
public Node getDeclaration() {
return declaration;
}
@Override
public <C, R> R accept(Visitor<C, R> v, C c) {
return v.visit(this, c);
}
@Override
public <C, R> R accept(Visitor<C, R> v, C c) {
return v.visit(this, c);
}
}

View File

@@ -1,16 +1,13 @@
package com.semmle.js.ast;
/**
* A default export specifier, such as <code>f</code> in
* <code>export f from 'foo';</code>.
*/
/** 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);
}
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);
}
@Override
public <C, R> R accept(Visitor<C, R> v, C c) {
return v.visit(this, c);
}
}

View File

@@ -6,45 +6,46 @@ 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>
* <li><code>export { x, y } from 'foo';</code></li>
* <li><code>export { x, y };</code></li>
* <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 Statement declaration;
private final List<ExportSpecifier> specifiers;
private final Literal source;
public ExportNamedDeclaration(SourceLocation loc, Statement declaration, List<ExportSpecifier> specifiers, Literal source) {
super("ExportNamedDeclaration", loc);
this.declaration = declaration;
this.specifiers = specifiers;
this.source = source;
}
public ExportNamedDeclaration(
SourceLocation loc, Statement declaration, List<ExportSpecifier> specifiers, Literal source) {
super("ExportNamedDeclaration", loc);
this.declaration = declaration;
this.specifiers = specifiers;
this.source = source;
}
public Statement getDeclaration() {
return declaration;
}
public Statement getDeclaration() {
return declaration;
}
public boolean hasDeclaration() {
return declaration != null;
}
public boolean hasDeclaration() {
return declaration != null;
}
public List<ExportSpecifier> getSpecifiers() {
return specifiers;
}
public List<ExportSpecifier> getSpecifiers() {
return specifiers;
}
public Literal getSource() {
return source;
}
public Literal getSource() {
return source;
}
public boolean hasSource() {
return source != null;
}
public boolean hasSource() {
return source != null;
}
@Override
public <C, R> R accept(Visitor<C, R> v, C c) {
return v.visit(this, c);
}
@Override
public <C, R> R accept(Visitor<C, R> v, C c) {
return v.visit(this, c);
}
}

View File

@@ -1,16 +1,16 @@
package com.semmle.js.ast;
/**
* A namespace export specifier such as <code>* as foo</code> in
* <code>export * as foo from 'foo';</code>.
* 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);
}
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);
}
@Override
public <C, R> R accept(Visitor<C, R> v, C c) {
return v.visit(this, c);
}
}

View File

@@ -1,32 +1,32 @@
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>.
* 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;
private final Identifier local, exported;
public ExportSpecifier(SourceLocation loc, Identifier local, Identifier exported) {
this("ExportSpecifier", loc, 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 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 getLocal() {
return local;
}
public Identifier getExported() {
return exported;
}
public Identifier getExported() {
return exported;
}
@Override
public <C, R> R accept(Visitor<C, R> v, C c) {
return v.visit(this, c);
}
@Override
public <C, R> R accept(Visitor<C, R> v, C c) {
return v.visit(this, c);
}
}

View File

@@ -2,30 +2,26 @@ package com.semmle.js.ast;
import com.semmle.ts.ast.ITypedAstNode;
/**
* Common superclass of all expressions.
*/
/** Common superclass of all expressions. */
public abstract class Expression extends Node implements ITypedAstNode {
private int staticTypeId = -1;
private int staticTypeId = -1;
public Expression(String type, SourceLocation loc) {
super(type, loc);
}
public Expression(String type, SourceLocation loc) {
super(type, loc);
}
/**
* This expression, but with any surrounding parentheses stripped off.
*/
public Expression stripParens() {
return this;
}
/** This expression, but with any surrounding parentheses stripped off. */
public Expression stripParens() {
return this;
}
@Override
public int getStaticTypeId() {
return staticTypeId;
}
@Override
public int getStaticTypeId() {
return staticTypeId;
}
@Override
public void setStaticTypeId(int staticTypeId) {
this.staticTypeId = staticTypeId;
}
@Override
public void setStaticTypeId(int staticTypeId) {
this.staticTypeId = staticTypeId;
}
}

View File

@@ -1,25 +1,21 @@
package com.semmle.js.ast;
/**
* An expression statement such as <code>alert("Hi!");</code>.
*/
/** An expression statement such as <code>alert("Hi!");</code>. */
public class ExpressionStatement extends Statement {
private final Expression expression;
private final Expression expression;
public ExpressionStatement(SourceLocation loc, Expression expression) {
super("ExpressionStatement", loc);
this.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);
}
@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;
}
/** The expression wrapped by this expression statement. */
public Expression getExpression() {
return expression;
}
}

View File

@@ -3,51 +3,60 @@ 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 final ITypeExpression typeAnnotation;
private final int fieldParameterIndex;
private static final int notFieldParameter = -1;
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) {
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) {
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 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;
}
public ITypeExpression getTypeAnnotation() {
return typeAnnotation;
}
@Override
public <C, R> R accept(Visitor<C, R> v, C c) {
return v.visit(this, c);
}
@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 isConcrete() {
return !isAbstract();
}
@Override
public boolean isParameterField() {
return fieldParameterIndex != notFieldParameter;
}
@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;
}
/**
* 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;
}
}

View File

@@ -11,19 +11,20 @@ package com.semmle.js.ast;
* This also includes legacy for-each statements.
*/
public class ForInStatement extends EnhancedForStatement {
private final boolean each;
private final boolean each;
public ForInStatement(SourceLocation loc, Node left, Expression right, Statement body, Boolean each) {
super("ForInStatement", loc, left, right, body);
this.each = each == Boolean.TRUE;
}
public ForInStatement(
SourceLocation loc, Node left, Expression right, Statement body, Boolean each) {
super("ForInStatement", loc, left, right, body);
this.each = each == Boolean.TRUE;
}
public boolean isEach() {
return each;
}
public boolean isEach() {
return each;
}
@Override
public <Q, A> A accept(Visitor<Q, A> v, Q q) {
return v.visit(this, q);
}
@Override
public <Q, A> A accept(Visitor<Q, A> v, Q q) {
return v.visit(this, q);
}
}

View File

@@ -9,22 +9,22 @@ package com.semmle.js.ast;
* </pre>
*/
public class ForOfStatement extends EnhancedForStatement {
private boolean isAwait;
private boolean isAwait;
public ForOfStatement(SourceLocation loc, Node left, Expression right, Statement body) {
super("ForOfStatement", loc, left, right, body);
}
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 void setAwait(boolean isAwait) {
this.isAwait = isAwait;
}
public boolean isAwait() {
return isAwait;
}
public boolean isAwait() {
return isAwait;
}
@Override
public <Q, A> A accept(Visitor<Q, A> v, Q q) {
return v.visit(this, q);
}
@Override
public <Q, A> A accept(Visitor<Q, A> v, Q q) {
return v.visit(this, q);
}
}

View File

@@ -10,70 +10,59 @@ package com.semmle.js.ast;
* </pre>
*/
public class ForStatement extends Loop {
private final Node init;
private final Expression test, update;
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;
}
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);
}
@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;
}
/** 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;
}
/**
* 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;
}
/** 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;
}
/** 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;
}
/** 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;
}
/** 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;
}
@Override
public Node getContinueTarget() {
if (update != null) return update;
if (test != null) return test;
return body;
}
}

View File

@@ -1,11 +1,10 @@
package com.semmle.js.ast;
import java.util.Collections;
import java.util.List;
import com.semmle.ts.ast.DecoratorList;
import com.semmle.ts.ast.ITypeExpression;
import com.semmle.ts.ast.TypeParameter;
import java.util.Collections;
import java.util.List;
/**
* A function declaration such as
@@ -17,71 +16,173 @@ import com.semmle.ts.ast.TypeParameter;
* </pre>
*/
public class FunctionDeclaration extends Statement implements IFunction {
private final AFunction<? extends Node> fn;
private final boolean hasDeclareKeyword;
private int symbol = -1;
private final AFunction<? extends Node> fn;
private final boolean hasDeclareKeyword;
private int symbol = -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),
false);
}
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),
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) {
this(loc, new AFunction<>(id, params, body, generator, async, typeParameters, parameterTypes, Collections.emptyList(),
returnType, thisParameterType), hasDeclareKeyword);
}
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) {
this(
loc,
new AFunction<>(
id,
params,
body,
generator,
async,
typeParameters,
parameterTypes,
Collections.emptyList(),
returnType,
thisParameterType),
hasDeclareKeyword);
}
private FunctionDeclaration(SourceLocation loc, AFunction<Node> fn, boolean hasDeclareKeyword) {
super("FunctionDeclaration", loc);
this.fn = fn;
this.hasDeclareKeyword = 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);
}
@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);
}
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(); }
@Override
public Identifier getId() {
return fn.getId();
}
public boolean hasDeclareKeyword() {
return hasDeclareKeyword;
}
@Override
public List<IPattern> getParams() {
return fn.getParams();
}
@Override
public int getSymbol() {
return this.symbol;
}
@Override
public boolean hasDefault(int i) {
return fn.hasDefault(i);
}
@Override
public void setSymbol(int symbol) {
this.symbol = symbol;
}
@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;
}
}

View File

@@ -1,36 +1,68 @@
package com.semmle.js.ast;
import java.util.Collections;
import java.util.List;
import com.semmle.ts.ast.DecoratorList;
import com.semmle.ts.ast.ITypeExpression;
import com.semmle.ts.ast.TypeParameter;
import java.util.Collections;
import java.util.List;
/**
* A plain function expression.
*/
/** 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);
}
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);
}
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) {
super("FunctionExpression", loc, id, params, body, generator, async, typeParameters, parameterTypes, parameterDecorators,
returnType, thisParameterType);
}
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) {
super(
"FunctionExpression",
loc,
id,
params,
body,
generator,
async,
typeParameters,
parameterTypes,
parameterDecorators,
returnType,
thisParameterType);
}
public FunctionExpression(SourceLocation loc, AFunction<? extends Node> fn) {
super("FunctionExpression", loc, fn);
}
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);
}
@Override
public <Q, A> A accept(Visitor<Q, A> v, Q q) {
return v.visit(this, q);
}
}

View File

@@ -1,94 +1,66 @@
package com.semmle.js.ast;
import java.util.List;
import com.semmle.ts.ast.DecoratorList;
import com.semmle.ts.ast.INodeWithSymbol;
import com.semmle.ts.ast.ITypeExpression;
import com.semmle.ts.ast.TypeParameter;
import java.util.List;
/**
* A function declaration or expression.
*/
/** A function declaration or expression. */
public interface IFunction extends IStatementContainer, INodeWithSymbol {
/**
* The function name; may be null for function expressions.
*/
public Identifier getId();
/** 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, not including the rest parameter. */
public List<IPattern> getParams();
/**
* The parameters of the function, including the rest parameter.
*/
public List<IPattern> getAllParams();
/** 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);
/** 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 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 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();
/**
* 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();
/** Does this function have a rest parameter? */
public boolean hasRest();
/**
* Is this function a generator function?
*/
public boolean isGenerator();
/** 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();
/**
* 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();
/** Is this function an asynchronous function? */
public boolean isAsync();
/**
* The return type of the function, if any.
*/
public ITypeExpression getReturnType();
/** 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);
/** 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);
/** The type annotation for the i'th parameter; may be null. */
public ITypeExpression getParameterType(int i);
public List<TypeParameter> getTypeParameters();
public List<TypeParameter> getTypeParameters();
public ITypeExpression getThisParameterType();
public ITypeExpression getThisParameterType();
public List<DecoratorList> getParameterDecorators();
public List<DecoratorList> getParameterDecorators();
public boolean hasDeclareKeyword();
public boolean hasDeclareKeyword();
}

View File

@@ -1,16 +1,10 @@
package com.semmle.js.ast;
/**
* The common interface implemented by all AST node types.
*/
/** 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);
/** Accept a visitor object. */
public <C, R> R accept(Visitor<C, R> v, C c);
/**
* Return the node's type tag.
*/
public String getType();
/** Return the node's type tag. */
public String getType();
}

View File

@@ -1,8 +1,7 @@
package com.semmle.js.ast;
/**
* A marker interface encompassing variables ({@link Identifier}) and complex patterns
* used in destructuring assignments ({@link ArrayPattern}, {@link ObjectPattern}).
* A marker interface encompassing variables ({@link Identifier}) and complex patterns used in
* destructuring assignments ({@link ArrayPattern}, {@link ObjectPattern}).
*/
public interface IPattern extends INode {
}
public interface IPattern extends INode {}

View File

@@ -1,11 +1,7 @@
package com.semmle.js.ast;
/**
* A source code element potentially associated with a location.
*/
/** 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();
/** Get the source location of this element; may be null. */
public SourceLocation getLoc();
}

View File

@@ -1,7 +1,4 @@
package com.semmle.js.ast;
/**
* A statement container, that is, either a {@link Program} or a {@link IFunction}.
*/
public interface IStatementContainer extends INode {
}
/** A statement container, that is, either a {@link Program} or a {@link IFunction}. */
public interface IStatementContainer extends INode {}

View File

@@ -6,40 +6,37 @@ import com.semmle.ts.ast.ITypeExpression;
/**
* An identifier.
*
* 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>).
* <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;
private final String name;
private int symbol = -1;
public Identifier(SourceLocation loc, String name) {
super("Identifier", loc);
this.name = name;
}
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);
}
@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;
}
/** The name of this identifier. */
public String getName() {
return name;
}
@Override
public int getSymbol() {
return symbol;
}
@Override
public int getSymbol() {
return symbol;
}
@Override
public void setSymbol(int symbol) {
this.symbol = symbol;
}
@Override
public void setSymbol(int symbol) {
this.symbol = symbol;
}
}

View File

@@ -1,49 +1,40 @@
package com.semmle.js.ast;
/**
* An if statement.
*/
/** An if statement. */
public class IfStatement extends Statement {
private final Expression test;
private final Statement consequent, alternate;
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;
}
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);
}
@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 test expression of this if statement. */
public Expression getTest() {
return test;
}
/**
* The then-branch of this if statement.
*/
public Statement getConsequent() {
return consequent;
}
/** 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;
}
/** 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;
}
/** Does this if statement have an else branch? */
public boolean hasAlternate() {
return alternate != null;
}
}

View File

@@ -15,28 +15,28 @@ import java.util.List;
* </pre>
*/
public class ImportDeclaration extends Statement {
/** List of import specifiers detailing how declarations are imported; may be empty. */
private final List<ImportSpecifier> specifiers;
/** 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;
/** The module from which declarations are imported. */
private final Literal source;
public ImportDeclaration(SourceLocation loc, List<ImportSpecifier> specifiers, Literal source) {
super("ImportDeclaration", loc);
this.specifiers = specifiers;
this.source = source;
}
public ImportDeclaration(SourceLocation loc, List<ImportSpecifier> specifiers, Literal source) {
super("ImportDeclaration", loc);
this.specifiers = specifiers;
this.source = source;
}
public Literal getSource() {
return source;
}
public Literal getSource() {
return source;
}
public List<ImportSpecifier> getSpecifiers() {
return specifiers;
}
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 <C, R> R accept(Visitor<C, R> v, C c) {
return v.visit(this, c);
}
}

View File

@@ -1,19 +1,19 @@
package com.semmle.js.ast;
/**
* A default import specifier, such as <code>f</code> in
* <code>import f, { x, y } from 'foo';</code>.
* A default import specifier, such as <code>f</code> in <code>import f, { x, y } from 'foo';</code>
* .
*
* Default import specifiers do not have an explicit imported name
* (the imported name is, implicitly, <code>default</code>).
* <p>Default import specifiers do not have an explicit imported name (the imported name is,
* implicitly, <code>default</code>).
*/
public class ImportDefaultSpecifier extends ImportSpecifier {
public ImportDefaultSpecifier(SourceLocation loc, Identifier local) {
super("ImportDefaultSpecifier", loc, null, local);
}
public ImportDefaultSpecifier(SourceLocation loc, Identifier local) {
super("ImportDefaultSpecifier", loc, null, local);
}
@Override
public <C, R> R accept(Visitor<C, R> v, C c) {
return v.visit(this, c);
}
@Override
public <C, R> R accept(Visitor<C, R> v, C c) {
return v.visit(this, c);
}
}

View File

@@ -1,18 +1,18 @@
package com.semmle.js.ast;
/**
* A namespace import specifier such as <code>* as foo</code> in
* <code>import * as foo from 'foo';</code>.
* A namespace import specifier such as <code>* as foo</code> in <code>import * as foo from 'foo';
* </code>.
*
* Namespace import specifiers do not have an imported name.
* <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);
}
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);
}
@Override
public <C, R> R accept(Visitor<C, R> v, C c) {
return v.visit(this, c);
}
}

View File

@@ -1,36 +1,36 @@
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>.
* An import specifier such as <code>x</code> and <code>y as z</code> in <code>
* import { x, y as z } from 'foo';</code>.
*
* 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>.
* <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;
private final Identifier imported, local;
public ImportSpecifier(SourceLocation loc, Identifier imported, Identifier local) {
this("ImportSpecifier", loc, 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 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 getImported() {
return imported;
}
public Identifier getLocal() {
return local;
}
public Identifier getLocal() {
return local;
}
@Override
public <C, R> R accept(Visitor<C, R> v, C c) {
return v.visit(this, c);
}
@Override
public <C, R> R accept(Visitor<C, R> v, C c) {
return v.visit(this, c);
}
}

View File

@@ -1,87 +1,84 @@
package com.semmle.js.ast;
import java.util.List;
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}.
*/
/** 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;
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;
}
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 callee expression of this invocation. */
public Expression getCallee() {
return callee;
}
/**
* The type arguments of this invocation.
*/
public List<ITypeExpression> getTypeArguments() {
return typeArguments;
}
/** The type arguments of this invocation. */
public List<ITypeExpression> getTypeArguments() {
return typeArguments;
}
/**
* The argument expressions of this invocation.
*/
public List<Expression> getArguments() {
return arguments;
}
/** The argument expressions of this invocation. */
public List<Expression> getArguments() {
return arguments;
}
@Override
public boolean isOptional() {
return optional;
}
@Override
public boolean isOptional() {
return optional;
}
@Override
public boolean isOnOptionalChain() {
return onOptionalChain;
}
@Override
public boolean isOnOptionalChain() {
return onOptionalChain;
}
public int getResolvedSignatureId() {
return resolvedSignatureId;
}
public int getResolvedSignatureId() {
return resolvedSignatureId;
}
public void setResolvedSignatureId(int resolvedSignatureId) {
this.resolvedSignatureId = resolvedSignatureId;
}
public void setResolvedSignatureId(int resolvedSignatureId) {
this.resolvedSignatureId = resolvedSignatureId;
}
public int getOverloadIndex() {
return overloadIndex;
}
public int getOverloadIndex() {
return overloadIndex;
}
public void setOverloadIndex(int overloadIndex) {
this.overloadIndex = overloadIndex;
}
public void setOverloadIndex(int overloadIndex) {
this.overloadIndex = overloadIndex;
}
@Override
public int getSymbol() {
return symbol;
}
@Override
public int getSymbol() {
return symbol;
}
@Override
public void setSymbol(int symbol) {
this.symbol = symbol;
}
@Override
public void setSymbol(int symbol) {
this.symbol = symbol;
}
}

View File

@@ -1,27 +1,21 @@
package com.semmle.js.ast;
/**
* A jump statement, that is, either a {@link BreakStatement} or a {@link ContinueStatement}.
*/
/** A jump statement, that is, either a {@link BreakStatement} or a {@link ContinueStatement}. */
public abstract class JumpStatement extends Statement {
private final Identifier label;
private final Identifier label;
public JumpStatement(String type, SourceLocation loc, Identifier label) {
super(type, loc);
this.label = 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;
}
/** 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;
}
/** Get the target label of this jump; may be null. */
public Identifier getLabel() {
return label;
}
}

View File

@@ -1,34 +1,28 @@
package com.semmle.js.ast;
/**
* A labeled statement.
*/
/** A labeled statement. */
public class LabeledStatement extends Statement {
private final Identifier label;
private final Statement body;
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;
}
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);
}
@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 label of the labeled statement. */
public Identifier getLabel() {
return label;
}
/**
* The statement wrapped by this labeled statement.
*/
public Statement getBody() {
return body;
}
/** The statement wrapped by this labeled statement. */
public Statement getBody() {
return body;
}
}

View File

@@ -2,29 +2,27 @@ package com.semmle.js.ast;
import java.util.List;
/**
* An old-style let expression of the form <code>let (vardecls) expr</code>.
*/
/** 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;
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;
}
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);
}
@Override
public <C, R> R accept(Visitor<C, R> v, C c) {
return v.visit(this, c);
}
public List<VariableDeclarator> getHead() {
return head;
}
public List<VariableDeclarator> getHead() {
return head;
}
public Expression getBody() {
return body;
}
public Expression getBody() {
return body;
}
}

View File

@@ -2,29 +2,27 @@ package com.semmle.js.ast;
import java.util.List;
/**
* An old-style let statement of the form <code>let(vardecls) stmt</code>.
*/
/** 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;
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;
}
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);
}
@Override
public <C, R> R accept(Visitor<C, R> v, C c) {
return v.visit(this, c);
}
public List<VariableDeclarator> getHead() {
return head;
}
public List<VariableDeclarator> getHead() {
return head;
}
public Statement getBody() {
return body;
}
public Statement getBody() {
return body;
}
}

View File

@@ -5,92 +5,78 @@ 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.
*
* <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;
private final TokenType tokenType;
private final Object value;
private final String raw;
public Literal(SourceLocation loc, TokenType tokenType, Object value) {
super("Literal", loc);
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();
}
// 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();
}
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);
}
@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 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 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;
}
/** 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 regular expression literal? */
public boolean isRegExp() {
return tokenType == TokenType.regexp;
}
/**
* 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);
}
/** 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 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();
}
/** Is the value of this literal truthy? */
public boolean isTruthy() {
return !isFalsy();
}
}

View File

@@ -4,12 +4,12 @@ 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);
}
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);
}
@Override
public <Q, A> A accept(Visitor<Q, A> v, Q q) {
return v.visit(this, q);
}
}

View File

@@ -1,26 +1,24 @@
package com.semmle.js.ast;
/**
* A loop statement, that is, a {@link WhileStatement}, a {@link DoWhileStatement}, a {@link ForStatement},
* or a {@link EnhancedForStatement}.
* 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;
protected final Statement body;
public Loop(String type, SourceLocation loc, Statement body) {
super(type, loc);
this.body = 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 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();
/**
* The child node of this loop where execution resumes after a <code>continue</code> statement.
*/
public abstract Node getContinueTarget();
}

View File

@@ -6,126 +6,119 @@ import java.util.List;
/**
* A member definition in a {@linkplain ClassBody}.
*
* A member definition has a name and an optional initial value, whose type is
* given by the type parameter {@code V}.
* <p>A member definition has a name and an optional initial value, whose type is given by the type
* parameter {@code V}.
*/
public abstract class MemberDefinition<V extends Expression> extends Node {
/**
* A bitmask of flags defined in {@linkplain DeclarationFlags}.
*/
private final int flags;
/** A bitmask of flags defined in {@linkplain DeclarationFlags}. */
private final int flags;
/**
* The name of the member.
*
* If {@link #isComputed()} is false, this must be an {@link Identifier}, otherwise
* it can be an arbitrary expression.
*/
private final Expression key;
/**
* The name of the member.
*
* <p>If {@link #isComputed()} is false, this must be an {@link Identifier}, otherwise it can be
* an arbitrary expression.
*/
private final Expression key;
/** The initial value of the member. */
private final V value;
/** The initial value of the member. */
private final V value;
/** The decorators applied to this member, if any. */
private final List<Decorator> decorators;
/** The decorators applied to this member, if any. */
private final List<Decorator> decorators;
public MemberDefinition(String type, SourceLocation loc, int flags, Expression key, V value) {
super(type, loc);
this.flags = flags;
this.key = key;
this.value = value;
this.decorators = new ArrayList<Decorator>();
}
public MemberDefinition(String type, SourceLocation loc, int flags, Expression key, V value) {
super(type, loc);
this.flags = flags;
this.key = key;
this.value = value;
this.decorators = new ArrayList<Decorator>();
}
/** Returns the flags, as defined by {@linkplain DeclarationFlags}. */
public int getFlags() {
return flags;
}
/** Returns the flags, as defined by {@linkplain DeclarationFlags}. */
public int getFlags() {
return flags;
}
/** Returns true if this has the <tt>static</tt> modifier. */
public boolean isStatic() {
return DeclarationFlags.isStatic(flags);
}
/** Returns true if this has the <tt>static</tt> modifier. */
public boolean isStatic() {
return DeclarationFlags.isStatic(flags);
}
/** Returns true if the member name is computed. */
public boolean isComputed() {
return DeclarationFlags.isComputed(flags);
}
/** Returns true if the member name is computed. */
public boolean isComputed() {
return DeclarationFlags.isComputed(flags);
}
/** Returns true if this is an abstract member. */
public boolean isAbstract() {
return DeclarationFlags.isAbstract(flags);
}
/** Returns true if this is an abstract member. */
public boolean isAbstract() {
return DeclarationFlags.isAbstract(flags);
}
/**
* Returns true if has the <tt>public</tt> modifier (not true for implicitly
* public members).
*/
public boolean hasPublicKeyword() {
return DeclarationFlags.isPublic(flags);
}
/** Returns true if has the <tt>public</tt> modifier (not true for implicitly public members). */
public boolean hasPublicKeyword() {
return DeclarationFlags.isPublic(flags);
}
/** Returns true if this is a private member. */
public boolean hasPrivateKeyword() {
return DeclarationFlags.isPrivate(flags);
}
/** Returns true if this is a private member. */
public boolean hasPrivateKeyword() {
return DeclarationFlags.isPrivate(flags);
}
/** Returns true if this is a protected member. */
public boolean hasProtectedKeyword() {
return DeclarationFlags.isProtected(flags);
}
/** Returns true if this is a protected member. */
public boolean hasProtectedKeyword() {
return DeclarationFlags.isProtected(flags);
}
/** Returns true if this is a readonly member. */
public boolean hasReadonlyKeyword() {
return DeclarationFlags.isReadonly(flags);
}
/** Returns true if this is a readonly member. */
public boolean hasReadonlyKeyword() {
return DeclarationFlags.isReadonly(flags);
}
/**
* Returns the expression denoting the name of the member, or {@code null} if
* this is a call/construct signature.
*/
public Expression getKey() {
return key;
}
/**
* Returns the expression denoting the name of the member, or {@code null} if this is a
* call/construct signature.
*/
public Expression getKey() {
return key;
}
public V getValue() {
return value;
}
public V getValue() {
return value;
}
/** The name of the method, if it can be determined. */
public String getName() {
if (!isComputed() && key instanceof Identifier)
return ((Identifier)key).getName();
if (key instanceof Literal)
return ((Literal)key).getStringValue();
return null;
}
/** The name of the method, if it can be determined. */
public String getName() {
if (!isComputed() && key instanceof Identifier) return ((Identifier) key).getName();
if (key instanceof Literal) return ((Literal) key).getStringValue();
return null;
}
/** True if this is a constructor; does not hold for construct signatures. */
public boolean isConstructor() {
return false;
}
/** True if this is a constructor; does not hold for construct signatures. */
public boolean isConstructor() {
return false;
}
/** True if this is a non-abstract field or a method with a body. */
public abstract boolean isConcrete();
/** True if this is a non-abstract field or a method with a body. */
public abstract boolean isConcrete();
public boolean isCallSignature() {
return false;
}
public boolean isCallSignature() {
return false;
}
public boolean isIndexSignature() {
return false;
}
public boolean isIndexSignature() {
return false;
}
public void addDecorators(List<Decorator> decorators) {
this.decorators.addAll(decorators);
}
public void addDecorators(List<Decorator> decorators) {
this.decorators.addAll(decorators);
}
public List<Decorator> getDecorators() {
return this.decorators;
}
public List<Decorator> getDecorators() {
return this.decorators;
}
public boolean isParameterField() {
return false;
}
public boolean isParameterField() {
return false;
}
}

View File

@@ -3,69 +3,70 @@ 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;
/** 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;
}
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);
}
@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 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;
}
/**
* 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;
}
/** Is this a computed member expression? */
public boolean isComputed() {
return computed;
}
@Override
public boolean isOptional() {
return optional;
}
@Override
public boolean isOptional() {
return optional;
}
@Override
public boolean isOnOptionalChain() {
return onOptionalChain;
}
@Override
public boolean isOnOptionalChain() {
return onOptionalChain;
}
@Override
public int getSymbol() {
return symbol;
}
@Override
public int getSymbol() {
return symbol;
}
@Override
public void setSymbol(int symbol) {
this.symbol = symbol;
}
@Override
public void setSymbol(int symbol) {
this.symbol = symbol;
}
}

View File

@@ -3,30 +3,28 @@ 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> and
* <code>function.sent</code>.
* </p>
* <p>Currently the only recognised meta properties are <code>new.target</code> and <code>
* function.sent</code>.
*/
public class MetaProperty extends Expression {
private final Identifier meta, property;
private final Identifier meta, property;
public MetaProperty(SourceLocation loc, Identifier meta, Identifier property) {
super("MetaProperty", loc);
this.meta = meta;
this.property = 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 getMeta() {
return meta;
}
public Identifier getProperty() {
return property;
}
public Identifier getProperty() {
return property;
}
@Override
public <Q, A> A accept(Visitor<Q, A> v, Q q) {
return v.visit(this, q);
}
@Override
public <Q, A> A accept(Visitor<Q, A> v, Q q) {
return v.visit(this, q);
}
}

View File

@@ -4,62 +4,73 @@ 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
};
public enum Kind {
CONSTRUCTOR,
METHOD,
GET,
SET,
FUNCTION_CALL_SIGNATURE,
CONSTRUCTOR_CALL_SIGNATURE,
INDEX_SIGNATURE
};
private final Kind kind;
private final List<FieldDefinition> parameterFields;
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) {
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 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;
}
public Kind getKind() {
return kind;
}
@Override
public boolean isCallSignature() {
return kind == Kind.FUNCTION_CALL_SIGNATURE || kind == Kind.CONSTRUCTOR_CALL_SIGNATURE;
}
@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 isIndexSignature() {
return kind == Kind.INDEX_SIGNATURE;
}
@Override
public boolean isConstructor() {
return !isStatic() && !isComputed() && "constructor".equals(getName());
}
@Override
public boolean isConstructor() {
return !isStatic() && !isComputed() && "constructor".equals(getName());
}
@Override
public boolean isConcrete() {
return getValue().getBody() != null;
}
@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);
}
@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;
}
/**
* 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;
}
}

View File

@@ -1,19 +1,20 @@
package com.semmle.js.ast;
import com.semmle.ts.ast.ITypeExpression;
import java.util.List;
import com.semmle.ts.ast.ITypeExpression;
/**
* A <code>new</code> expression.
*/
/** A <code>new</code> expression. */
public class NewExpression extends InvokeExpression {
public NewExpression(SourceLocation loc, Expression callee, List<ITypeExpression> typeArguments, List<Expression> arguments) {
super("NewExpression", loc, callee, typeArguments, arguments, false, false);
}
public NewExpression(
SourceLocation loc,
Expression callee,
List<ITypeExpression> typeArguments,
List<Expression> arguments) {
super("NewExpression", loc, callee, typeArguments, arguments, false, false);
}
@Override
public <Q, A> A accept(Visitor<Q, A> v, Q q) {
return v.visit(this, q);
}
@Override
public <Q, A> A accept(Visitor<Q, A> v, Q q) {
return v.visit(this, q);
}
}

View File

@@ -1,17 +1,15 @@
package com.semmle.js.ast;
/**
* Common superclass of all AST node types.
*/
/** Common superclass of all AST node types. */
public abstract class Node extends SourceElement implements INode {
private final String type;
private final String type;
public Node(String type, SourceLocation loc) {
super(loc);
this.type = type;
}
public Node(String type, SourceLocation loc) {
super(loc);
this.type = type;
}
public final String getType() {
return type;
}
public final String getType() {
return type;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -2,26 +2,22 @@ package com.semmle.js.ast;
import java.util.List;
/**
* An object literal.
*/
/** An object literal. */
public class ObjectExpression extends Expression {
private final List<Property> properties;
private final List<Property> properties;
public ObjectExpression(SourceLocation loc, List<Property> properties) {
super("ObjectExpression", loc);
this.properties = 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);
}
@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;
}
/** The properties in this literal. */
public List<Property> getProperties() {
return properties;
}
}

View File

@@ -3,60 +3,52 @@ package com.semmle.js.ast;
import java.util.ArrayList;
import java.util.List;
/**
* An object pattern.
*/
/** An object pattern. */
public class ObjectPattern extends Expression implements DestructuringPattern {
private final List<Property> rawProperties, properties;
private final Expression restPattern;
private final List<Property> rawProperties, properties;
private final Expression restPattern;
public ObjectPattern(SourceLocation loc, List<Property> properties) {
super("ObjectPattern", loc);
this.rawProperties = properties;
this.properties = new ArrayList<Property>(properties.size());
Expression rest = null;
for (Property prop : properties) {
Expression val = prop.getValue();
if (val instanceof RestElement) {
rest = ((RestElement)val).getArgument();
} else {
this.properties.add(prop);
}
}
this.restPattern = rest;
}
public ObjectPattern(SourceLocation loc, List<Property> properties) {
super("ObjectPattern", loc);
this.rawProperties = properties;
this.properties = new ArrayList<Property>(properties.size());
Expression rest = null;
for (Property prop : properties) {
Expression val = prop.getValue();
if (val instanceof RestElement) {
rest = ((RestElement) val).getArgument();
} else {
this.properties.add(prop);
}
}
this.restPattern = rest;
}
@Override
public <Q, A> A accept(Visitor<Q, A> v, Q q) {
return v.visit(this, q);
}
@Override
public <Q, A> A accept(Visitor<Q, A> v, Q q) {
return v.visit(this, q);
}
/**
* The property patterns in this literal.
*/
public List<Property> getProperties() {
return properties;
}
/** The property patterns in this literal. */
public List<Property> getProperties() {
return properties;
}
/**
* Does this object pattern have a rest pattern?
*/
public boolean hasRest() {
return restPattern != null;
}
/** Does this object pattern have a rest pattern? */
public boolean hasRest() {
return restPattern != null;
}
/**
* The rest pattern of this literal, if any.
*/
public Expression getRest() {
return restPattern;
}
/** The rest pattern of this literal, if any. */
public Expression getRest() {
return restPattern;
}
/**
* The raw property patterns in this literal; the rest
* pattern (if any) is represented as a {@link RestElement}.
*/
public List<Property> getRawProperties() {
return rawProperties;
}
/**
* The raw property patterns in this literal; the rest pattern (if any) is represented as a {@link
* RestElement}.
*/
public List<Property> getRawProperties() {
return rawProperties;
}
}

View File

@@ -1,30 +1,26 @@
package com.semmle.js.ast;
/**
* A parenthesized expression.
*/
/** A parenthesized expression. */
public class ParenthesizedExpression extends Expression {
private final Expression expression;
private final Expression expression;
public ParenthesizedExpression(SourceLocation loc, Expression expression) {
super("ParenthesizedExpression", loc);
this.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);
}
@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;
}
/** The expression between parentheses. */
public Expression getExpression() {
return expression;
}
@Override
public Expression stripParens() {
return expression.stripParens();
}
@Override
public Expression stripParens() {
return expression.stripParens();
}
}

View File

@@ -1,81 +1,65 @@
package com.semmle.js.ast;
/**
* A source position identifying a single character.
*/
/** A source position identifying a single character. */
public class Position implements Comparable<Position> {
private final int line, column, offset;
private final int line, column, offset;
public Position(int line, int column, int offset) {
this.line = line;
this.column = column;
this.offset = 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 line number (1-based) of this position. */
public int getLine() {
return line;
}
/**
* The column number (1-based) of this position.
*/
public int getColumn() {
return column;
}
/** The column number (1-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;
}
/**
* 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 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 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 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;
}
@Override
public String toString() {
return line + ":" + column;
}
}

View File

@@ -1,44 +1,39 @@
package com.semmle.js.ast;
import com.semmle.ts.ast.INodeWithSymbol;
import java.util.List;
import com.semmle.ts.ast.INodeWithSymbol;
/**
* A top-level program entity forming the root of an AST.
*/
/** 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;
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;
}
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);
}
@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;
}
/** The statements in this program. */
public List<Statement> getBody() {
return body;
}
public String getSourceType() {
return sourceType;
}
public String getSourceType() {
return sourceType;
}
public int getSymbol() {
return this.symbolId;
}
public int getSymbol() {
return this.symbolId;
}
public void setSymbol(int symbolId) {
this.symbolId = symbolId;
}
public void setSymbol(int symbolId) {
this.symbolId = symbolId;
}
}

View File

@@ -1,137 +1,131 @@
package com.semmle.js.ast;
import com.semmle.util.data.StringUtil;
import java.util.ArrayList;
import java.util.List;
import com.semmle.util.data.StringUtil;
/**
* A property in an object literal or an object pattern.
*
* This includes both regular properties as well as accessor properties, method properties,
* <p>This includes both regular properties as well as accessor properties, method properties,
* properties with computed names, and spread/rest properties.
*/
public class Property extends Node {
public static enum Kind {
/** Either a normal property or a spread/rest property. */
INIT(false),
public static enum Kind {
/** Either a normal property or a spread/rest property. */
INIT(false),
/** Getter property. */
GET(true),
/** Getter property. */
GET(true),
/** Setter property. */
SET(true);
/** Setter property. */
SET(true);
public final boolean isAccessor;
public final boolean isAccessor;
private Kind(boolean isAccessor) {
this.isAccessor = isAccessor;
}
};
private Kind(boolean isAccessor) {
this.isAccessor = isAccessor;
}
};
private final Expression key;
private final Expression value, rawValue;
private final Expression defaultValue; // only applies to property patterns
private final Kind kind;
private final boolean computed, method;
private final List<Decorator> decorators;
private final Expression key;
private final Expression value, rawValue;
private final Expression defaultValue; // only applies to property patterns
private final Kind kind;
private final boolean computed, method;
private final List<Decorator> decorators;
public Property(SourceLocation loc, Expression key, Expression rawValue, String kind, Boolean computed, Boolean method) {
super("Property", loc);
this.key = key;
if (rawValue instanceof AssignmentPattern) {
AssignmentPattern ap = (AssignmentPattern) rawValue;
if (ap.getLeft() == key)
rawValue = ap = new AssignmentPattern(ap.getLoc(), ap.getOperator(), new NodeCopier().copy(key), ap.getRight());
this.value = ap.getLeft();
this.defaultValue = ap.getRight();
} else {
this.value = rawValue == key ? new NodeCopier().copy(rawValue) : rawValue;
this.defaultValue = null;
}
this.rawValue = rawValue;
this.kind = Kind.valueOf(StringUtil.uc(kind));
this.computed = computed == Boolean.TRUE;
this.method = method == Boolean.TRUE;
this.decorators = new ArrayList<Decorator>();
}
public Property(
SourceLocation loc,
Expression key,
Expression rawValue,
String kind,
Boolean computed,
Boolean method) {
super("Property", loc);
this.key = key;
if (rawValue instanceof AssignmentPattern) {
AssignmentPattern ap = (AssignmentPattern) rawValue;
if (ap.getLeft() == key)
rawValue =
ap =
new AssignmentPattern(
ap.getLoc(), ap.getOperator(), new NodeCopier().copy(key), ap.getRight());
this.value = ap.getLeft();
this.defaultValue = ap.getRight();
} else {
this.value = rawValue == key ? new NodeCopier().copy(rawValue) : rawValue;
this.defaultValue = null;
}
this.rawValue = rawValue;
this.kind = Kind.valueOf(StringUtil.uc(kind));
this.computed = computed == Boolean.TRUE;
this.method = method == Boolean.TRUE;
this.decorators = new ArrayList<Decorator>();
}
@Override
public <Q, A> A accept(Visitor<Q, A> v, Q q) {
return v.visit(this, q);
}
@Override
public <Q, A> A accept(Visitor<Q, A> v, Q q) {
return v.visit(this, q);
}
/**
* The key of this property; usually a {@link Literal} or an {@link Identifier}, but may
* be an arbitrary expression for properties with computed names. For spread/rest properties
* this method returns {@code null}.
*/
public Expression getKey() {
return key;
}
/**
* The key of this property; usually a {@link Literal} or an {@link Identifier}, but may be an
* arbitrary expression for properties with computed names. For spread/rest properties this method
* returns {@code null}.
*/
public Expression getKey() {
return key;
}
/**
* The value expression of this property.
*/
public Expression getValue() {
return value;
}
/** The value expression of this property. */
public Expression getValue() {
return value;
}
/**
* The default value of this property pattern.
*/
public Expression getDefaultValue() {
return defaultValue;
}
/** The default value of this property pattern. */
public Expression getDefaultValue() {
return defaultValue;
}
/**
* Is this a property pattern with a default value?
*/
public boolean hasDefaultValue() {
return defaultValue != null;
}
/** Is this a property pattern with a default value? */
public boolean hasDefaultValue() {
return defaultValue != null;
}
/**
* The kind of this property.
*/
public Kind getKind() {
return kind;
}
/** The kind of this property. */
public Kind getKind() {
return kind;
}
/**
* Is the name of this property computed?
*/
public boolean isComputed() {
return computed;
}
/** Is the name of this property computed? */
public boolean isComputed() {
return computed;
}
/**
* Is this property declared using method syntax?
*/
public boolean isMethod() {
return method;
}
/** Is this property declared using method syntax? */
public boolean isMethod() {
return method;
}
/**
* Is this property declared using shorthand syntax?
*/
public boolean isShorthand() {
return key != null && key.getLoc().equals(value.getLoc());
}
/** Is this property declared using shorthand syntax? */
public boolean isShorthand() {
return key != null && key.getLoc().equals(value.getLoc());
}
/**
* The raw value expression of this property; if this property is a property
* pattern with a default value, this method returns an {@link AssignmentPattern}.
*/
public Expression getRawValue() {
return rawValue;
}
/**
* The raw value expression of this property; if this property is a property pattern with a
* default value, this method returns an {@link AssignmentPattern}.
*/
public Expression getRawValue() {
return rawValue;
}
public void addDecorators(List<Decorator> decorators) {
this.decorators.addAll(decorators);
}
public void addDecorators(List<Decorator> decorators) {
this.decorators.addAll(decorators);
}
public List<Decorator> getDecorators() {
return this.decorators;
}
public List<Decorator> getDecorators() {
return this.decorators;
}
}

View File

@@ -3,27 +3,25 @@ package com.semmle.js.ast;
/**
* A rest element <code>...xs</code> in lvalue position.
*
* 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.
* <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;
private final Expression argument;
public RestElement(SourceLocation loc, Expression argument) {
super("RestElement", loc);
this.argument = 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);
}
@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;
}
/** The argument expression of this spread element. */
public Expression getArgument() {
return argument;
}
}

View File

@@ -1,32 +1,26 @@
package com.semmle.js.ast;
/**
* A return statement.
*/
/** A return statement. */
public class ReturnStatement extends Statement {
private final Expression argument;
private final Expression argument;
public ReturnStatement(SourceLocation loc, Expression argument) {
super("ReturnStatement", loc);
this.argument = 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);
}
@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;
}
/** 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;
}
/** The argument expression of this return statement; may be null. */
public Expression getArgument() {
return argument;
}
}

View File

@@ -2,26 +2,22 @@ package com.semmle.js.ast;
import java.util.List;
/**
* A comma expression containing two or more expressions evaluated in sequence.
*/
/** A comma expression containing two or more expressions evaluated in sequence. */
public class SequenceExpression extends Expression {
private final List<Expression> expressions;
private final List<Expression> expressions;
public SequenceExpression(SourceLocation loc, List<Expression> expressions) {
super("SequenceExpression", loc);
this.expressions = 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);
}
@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;
}
/** The expressions in this sequence. */
public List<Expression> getExpressions() {
return expressions;
}
}

View File

@@ -1,21 +1,19 @@
package com.semmle.js.ast;
/**
* Common superclass of all source elements.
*/
/** Common superclass of all source elements. */
public class SourceElement implements ISourceElement {
private final SourceLocation loc;
private final SourceLocation loc;
public SourceElement(SourceLocation loc) {
this.loc = loc;
}
public SourceElement(SourceLocation loc) {
this.loc = loc;
}
public boolean hasLoc() {
return loc != null;
}
public boolean hasLoc() {
return loc != null;
}
@Override
public final SourceLocation getLoc() {
return loc;
}
@Override
public final SourceLocation getLoc() {
return loc;
}
}

View File

@@ -1,100 +1,79 @@
package com.semmle.js.ast;
/**
* A source location representing a range of characters.
*/
/** A source location representing a range of characters. */
public class SourceLocation {
private String source;
private Position start, end;
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(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(Position start) {
this(null, start, null);
}
public SourceLocation(String source, Position start) {
this(source, start, null);
}
public SourceLocation(String source, Position start) {
this(source, start, null);
}
public SourceLocation(SourceLocation that) {
this(that.source, that.start, that.end);
}
public SourceLocation(SourceLocation that) {
this(that.source, that.start, that.end);
}
/**
* The source code contained in this location.
*/
public String getSource() {
return source;
}
/** 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;
}
/** 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;
}
/** 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;
}
/** 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;
}
/** 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;
}
/** 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 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;
}
@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;
}
}

View File

@@ -1,25 +1,21 @@
package com.semmle.js.ast;
/**
* A spread element <code>...xs</code> in rvalue position.
*/
/** A spread element <code>...xs</code> in rvalue position. */
public class SpreadElement extends Expression {
private final Expression argument;
private final Expression argument;
public SpreadElement(SourceLocation loc, Expression argument) {
super("SpreadElement", loc);
this.argument = 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);
}
@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;
}
/** The argument expression of this spread element. */
public Expression getArgument() {
return argument;
}
}

View File

@@ -1,10 +1,8 @@
package com.semmle.js.ast;
/**
* Common superclass of all statements.
*/
/** Common superclass of all statements. */
public abstract class Statement extends Node {
public Statement(String type, SourceLocation loc) {
super(type, loc);
}
public Statement(String type, SourceLocation loc) {
super(type, loc);
}
}

View File

@@ -1,16 +1,16 @@
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.
* 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);
}
public Super(SourceLocation loc) {
super("Super", loc);
}
@Override
public <Q, A> A accept(Visitor<Q, A> v, Q q) {
return v.visit(this, q);
}
@Override
public <Q, A> A accept(Visitor<Q, A> v, Q q) {
return v.visit(this, q);
}
}

View File

@@ -2,49 +2,39 @@ package com.semmle.js.ast;
import java.util.List;
/**
* A case in a switch statement; may be a default case.
*/
/** A case in a switch statement; may be a default case. */
public class SwitchCase extends Statement {
private final Expression test;
private final List<Statement> consequent;
private final Expression test;
private final List<Statement> consequent;
public SwitchCase(SourceLocation loc, Expression test, List<Statement> consequent) {
super("SwitchCase", loc);
this.test = test;
this.consequent = consequent;
}
public SwitchCase(SourceLocation loc, Expression test, List<Statement> consequent) {
super("SwitchCase", loc);
this.test = test;
this.consequent = consequent;
}
@Override
public <Q, A> A accept(Visitor<Q, A> v, Q q) {
return v.visit(this, q);
}
@Override
public <Q, A> A accept(Visitor<Q, A> v, Q q) {
return v.visit(this, q);
}
/**
* Does this case have a test expression?
*/
public boolean hasTest() {
return test != null;
}
/** Does this case have a test expression? */
public boolean hasTest() {
return test != null;
}
/**
* The test expression of this case; is null for default cases.
*/
public Expression getTest() {
return test;
}
/** The test expression of this case; is null for default cases. */
public Expression getTest() {
return test;
}
/**
* The statements belonging to this case.
*/
public List<Statement> getConsequent() {
return consequent;
}
/** The statements belonging to this case. */
public List<Statement> getConsequent() {
return consequent;
}
/**
* Is this a default case?
*/
public boolean isDefault() {
return !hasTest();
}
/** Is this a default case? */
public boolean isDefault() {
return !hasTest();
}
}

View File

@@ -2,35 +2,29 @@ package com.semmle.js.ast;
import java.util.List;
/**
* A switch statement.
*/
/** A switch statement. */
public class SwitchStatement extends Statement {
private final Expression discriminant;
private final List<SwitchCase> cases;
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;
}
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);
}
@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 expression whose value is examined. */
public Expression getDiscriminant() {
return discriminant;
}
/**
* The cases in this switch statement.
*/
public List<SwitchCase> getCases() {
return cases;
}
/** The cases in this switch statement. */
public List<SwitchCase> getCases() {
return cases;
}
}

View File

@@ -1,34 +1,28 @@
package com.semmle.js.ast;
/**
* A tagged template expression.
*/
/** A tagged template expression. */
public class TaggedTemplateExpression extends Expression {
private final Expression tag;
private final TemplateLiteral quasi;
public TaggedTemplateExpression(SourceLocation loc, Expression tag, TemplateLiteral quasi) {
super("TaggedTemplateExpression", loc);
this.tag = tag;
this.quasi = quasi;
}
private final Expression tag;
private final TemplateLiteral quasi;
@Override
public <Q, A> A accept(Visitor<Q, A> v, Q q) {
return v.visit(this, q);
}
public TaggedTemplateExpression(SourceLocation loc, Expression tag, TemplateLiteral quasi) {
super("TaggedTemplateExpression", loc);
this.tag = tag;
this.quasi = quasi;
}
/**
* The tagging expression.
*/
public Expression getTag() {
return tag;
}
@Override
public <Q, A> A accept(Visitor<Q, A> v, Q q) {
return v.visit(this, q);
}
/**
* The tagged template literal.
*/
public TemplateLiteral getQuasi() {
return quasi;
}
/** The tagging expression. */
public Expression getTag() {
return tag;
}
/** The tagged template literal. */
public TemplateLiteral getQuasi() {
return quasi;
}
}

View File

@@ -1,43 +1,35 @@
package com.semmle.js.ast;
/**
* An element in a template literal.
*/
/** An element in a template literal. */
public class TemplateElement extends Expression {
private final Object cooked;
private final String raw;
private final boolean tail;
private final Object cooked;
private final String raw;
private final boolean tail;
public TemplateElement(SourceLocation loc, Object cooked, String raw, Boolean tail) {
super("TemplateElement", loc);
this.cooked = cooked;
this.raw = raw;
this.tail = tail == Boolean.TRUE;
}
public TemplateElement(SourceLocation loc, Object cooked, String raw, Boolean tail) {
super("TemplateElement", loc);
this.cooked = cooked;
this.raw = raw;
this.tail = tail == Boolean.TRUE;
}
@Override
public <Q, A> A accept(Visitor<Q, A> v, Q q) {
return v.visit(this, q);
}
@Override
public <Q, A> A accept(Visitor<Q, A> v, Q q) {
return v.visit(this, q);
}
/**
* The "cooked" value of the template element.
*/
public Object getCooked() {
return cooked;
}
/** The "cooked" value of the template element. */
public Object getCooked() {
return cooked;
}
/**
* The raw value of the template element.
*/
public String getRaw() {
return raw;
}
/** The raw value of the template element. */
public String getRaw() {
return raw;
}
/**
* Is this the tail element?
*/
public boolean isTail() {
return tail;
}
/** Is this the tail element? */
public boolean isTail() {
return tail;
}
}

View File

@@ -6,77 +6,68 @@ 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
* <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.
* </p>
*/
public class TemplateLiteral extends Expression {
private final List<Expression> expressions;
private final List<TemplateElement> quasis;
private final List<Expression> children;
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);
}
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();
/*
* 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 (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);
}
for (; j < n; ++j) {
TemplateElement quasi = quasis.get(j);
if (!quasi.getRaw().isEmpty()) children.add(quasi);
}
return children;
}
return children;
}
@Override
public <Q, A> A accept(Visitor<Q, A> v, Q q) {
return v.visit(this, q);
}
@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 expressions in this template. */
public List<Expression> getExpressions() {
return expressions;
}
/**
* The template elements in this template.
*/
public List<TemplateElement> getQuasis() {
return quasis;
}
/** 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;
}
/** All expressions and template elements in this template, in lexical order. */
public List<Expression> getChildren() {
return children;
}
}

View File

@@ -1,15 +1,13 @@
package com.semmle.js.ast;
/**
* A <code>this</code> expression.
*/
/** A <code>this</code> expression. */
public class ThisExpression extends Expression {
public ThisExpression(SourceLocation loc) {
super("ThisExpression", loc);
}
public ThisExpression(SourceLocation loc) {
super("ThisExpression", loc);
}
@Override
public <Q, A> A accept(Visitor<Q, A> v, Q q) {
return v.visit(this, q);
}
@Override
public <Q, A> A accept(Visitor<Q, A> v, Q q) {
return v.visit(this, q);
}
}

View File

@@ -1,25 +1,21 @@
package com.semmle.js.ast;
/**
* A <code>throw</code> statement.
*/
/** A <code>throw</code> statement. */
public class ThrowStatement extends Statement {
private final Expression argument;
private final Expression argument;
public ThrowStatement(SourceLocation loc, Expression argument) {
super("ThrowStatement", loc);
this.argument = 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);
}
@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;
}
/** The thrown expression. */
public Expression getArgument() {
return argument;
}
}

View File

@@ -14,62 +14,69 @@ import static com.semmle.js.ast.Token.Type.TRUE;
/**
* A source code token.
*
* This is not part of the SpiderMonkey AST format.
* <p>This is not part of the SpiderMonkey AST format.
*/
public class Token extends SourceElement {
/**
* The supported token types.
*/
public static enum Type { EOF, NULL, TRUE, FALSE, NUM, STRING, REGEXP, NAME, KEYWORD, PUNCTUATOR };
/** The supported token types. */
public static enum Type {
EOF,
NULL,
TRUE,
FALSE,
NUM,
STRING,
REGEXP,
NAME,
KEYWORD,
PUNCTUATOR
};
private final Type type;
private final String value;
private final Type type;
private final String value;
public Token(SourceLocation loc, String typename, Object keyword) {
this(loc, getType(typename, keyword));
}
public Token(SourceLocation loc, String typename, Object keyword) {
this(loc, getType(typename, keyword));
}
public Token(SourceLocation loc, Type type) {
super(loc);
this.value = loc.getSource();
this.type = type;
}
public Token(SourceLocation loc, Type type) {
super(loc);
this.value = loc.getSource();
this.type = type;
}
private static Type getType(String typename, Object keyword) {
if ("eof".equals(typename)) {
return EOF;
} else if ("num".equals(typename)) {
return NUM;
} else if("name".equals(typename) || "jsxName".equals(typename)) {
return NAME;
} else if("string".equals(typename) || "template".equals(typename) || "jsxText".equals(typename)) {
return STRING;
} else if("regexp".equals(typename)) {
return REGEXP;
} else if ("true".equals(keyword)) {
return TRUE;
} else if ("false".equals(keyword)) {
return FALSE;
} else if ("null".equals(keyword)) {
return NULL;
} else if (keyword instanceof String) {
return KEYWORD;
} else {
return PUNCTUATOR;
}
}
private static Type getType(String typename, Object keyword) {
if ("eof".equals(typename)) {
return EOF;
} else if ("num".equals(typename)) {
return NUM;
} else if ("name".equals(typename) || "jsxName".equals(typename)) {
return NAME;
} else if ("string".equals(typename)
|| "template".equals(typename)
|| "jsxText".equals(typename)) {
return STRING;
} else if ("regexp".equals(typename)) {
return REGEXP;
} else if ("true".equals(keyword)) {
return TRUE;
} else if ("false".equals(keyword)) {
return FALSE;
} else if ("null".equals(keyword)) {
return NULL;
} else if (keyword instanceof String) {
return KEYWORD;
} else {
return PUNCTUATOR;
}
}
/**
* The type of this token.
*/
public Type getType() {
return type;
}
/** The type of this token. */
public Type getType() {
return type;
}
/**
* The source text of this token.
*/
public String getValue() {
return value;
}
/** The source text of this token. */
public String getValue() {
return value;
}
}

View File

@@ -3,81 +3,66 @@ package com.semmle.js.ast;
import java.util.ArrayList;
import java.util.List;
/**
* A try statement.
*/
/** A try statement. */
public class TryStatement extends Statement {
private final BlockStatement block;
private final CatchClause handler;
private final List<CatchClause> guardedHandlers, allHandlers;
private final BlockStatement finalizer;
private final BlockStatement block;
private final CatchClause handler;
private final List<CatchClause> guardedHandlers, allHandlers;
private final BlockStatement finalizer;
public TryStatement(SourceLocation loc, BlockStatement block,
CatchClause handler, List<CatchClause> guardedHandlers,
BlockStatement finalizer) {
super("TryStatement", loc);
this.block = block;
this.handler = handler;
this.guardedHandlers = guardedHandlers;
this.finalizer = finalizer;
this.allHandlers = new ArrayList<CatchClause>();
if (guardedHandlers != null)
this.allHandlers.addAll(guardedHandlers);
if (handler != null)
this.allHandlers.add(handler);
}
public TryStatement(
SourceLocation loc,
BlockStatement block,
CatchClause handler,
List<CatchClause> guardedHandlers,
BlockStatement finalizer) {
super("TryStatement", loc);
this.block = block;
this.handler = handler;
this.guardedHandlers = guardedHandlers;
this.finalizer = finalizer;
this.allHandlers = new ArrayList<CatchClause>();
if (guardedHandlers != null) this.allHandlers.addAll(guardedHandlers);
if (handler != null) this.allHandlers.add(handler);
}
@Override
public <Q, A> A accept(Visitor<Q, A> v, Q q) {
return v.visit(this, q);
}
@Override
public <Q, A> A accept(Visitor<Q, A> v, Q q) {
return v.visit(this, q);
}
/**
* The body of this try statement.
*/
public BlockStatement getBlock() {
return block;
}
/** The body of this try statement. */
public BlockStatement getBlock() {
return block;
}
/**
* The (single unguarded) catch clause of this try statement; may be null.
*/
public CatchClause getHandler() {
return handler;
}
/** The (single unguarded) catch clause of this try statement; may be null. */
public CatchClause getHandler() {
return handler;
}
/**
* The guarded catch clauses of this try statement.
*/
public List<CatchClause> getGuardedHandlers() {
return guardedHandlers;
}
/** The guarded catch clauses of this try statement. */
public List<CatchClause> getGuardedHandlers() {
return guardedHandlers;
}
/**
* The finally block of this try statement; may be null.
*/
public BlockStatement getFinalizer() {
return finalizer;
}
/** The finally block of this try statement; may be null. */
public BlockStatement getFinalizer() {
return finalizer;
}
/**
* All catch clauses (both guarded and unguarded) of this try statement in lexical order.
*/
public List<CatchClause> getAllHandlers() {
return allHandlers;
}
/** All catch clauses (both guarded and unguarded) of this try statement in lexical order. */
public List<CatchClause> getAllHandlers() {
return allHandlers;
}
/**
* Does this try statement have a finally block?
*/
public boolean hasFinalizer() {
return finalizer != null;
}
/** Does this try statement have a finally block? */
public boolean hasFinalizer() {
return finalizer != null;
}
/**
* Does this try statement have an unguarded catch block?
*/
public boolean hasHandler() {
return handler != null;
}
/** Does this try statement have an unguarded catch block? */
public boolean hasHandler() {
return handler != null;
}
}

View File

@@ -3,44 +3,37 @@ package com.semmle.js.ast;
/**
* A unary expression such as <code>!x</code> or <code>void(0)</code>.
*
* Note that increment and decrement expressions are represented by {@link UpdateExpression}.
* <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;
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;
}
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);
}
@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 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;
}
/** 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;
}
}

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