Package com.google.javascript.rhino
Class TypeDeclarationsIR
- java.lang.Object
-
- com.google.javascript.rhino.TypeDeclarationsIR
-
public class TypeDeclarationsIR extends java.lang.Object
An AST construction helper class for TypeDeclarationNode- Author:
- [email protected] (Alex Eagle), [email protected] (Michael Zhou)
-
-
Constructor Summary
Constructors Constructor Description TypeDeclarationsIR()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Node.TypeDeclarationNode
anyType()
Equivalent to the UNKNOWN type in Closure, expressed with{?}
static Node.TypeDeclarationNode
arrayType(Node elementType)
Represents an array type.static Node.TypeDeclarationNode
booleanType()
static Node.TypeDeclarationNode
functionType(Node returnType, java.util.LinkedHashMap<java.lang.String,Node.TypeDeclarationNode> requiredParams, java.util.LinkedHashMap<java.lang.String,Node.TypeDeclarationNode> optionalParams, java.lang.String restName, Node.TypeDeclarationNode restType)
Represents a function type.static Node.TypeDeclarationNode
namedType(java.lang.Iterable<java.lang.String> segments)
Produces a tree structure similar to the Rhino AST of a qualified name expression, under a top-level NAMED_TYPE node.static Node.TypeDeclarationNode
namedType(java.lang.String typeName)
Splits a '.' separated qualified name into a tree of type segments.static Node.TypeDeclarationNode
numberType()
static Node.TypeDeclarationNode
optionalParameter(Node.TypeDeclarationNode parameterType)
Represents a function parameter that is optional.static Node.TypeDeclarationNode
parameterizedType(Node.TypeDeclarationNode baseType, java.lang.Iterable<Node.TypeDeclarationNode> typeParameters)
Represents a parameterized, or generic, type.static Node.TypeDeclarationNode
recordType(java.util.LinkedHashMap<java.lang.String,Node.TypeDeclarationNode> properties)
Represents a structural type.static Node.TypeDeclarationNode
stringType()
static Node.TypeDeclarationNode
undefinedType()
static Node.TypeDeclarationNode
unionType(Node.TypeDeclarationNode... options)
static Node.TypeDeclarationNode
unionType(java.lang.Iterable<Node.TypeDeclarationNode> options)
Represents a union type, which can be one of the given types.static Node.TypeDeclarationNode
voidType()
-
-
-
Method Detail
-
stringType
public static Node.TypeDeclarationNode stringType()
- Returns:
- a new node representing the string built-in type.
-
numberType
public static Node.TypeDeclarationNode numberType()
- Returns:
- a new node representing the number built-in type.
-
booleanType
public static Node.TypeDeclarationNode booleanType()
- Returns:
- a new node representing the boolean built-in type.
-
anyType
public static Node.TypeDeclarationNode anyType()
Equivalent to the UNKNOWN type in Closure, expressed with{?}
- Returns:
- a new node representing any type, without type checking.
-
voidType
public static Node.TypeDeclarationNode voidType()
- Returns:
- a new node representing the Void type as defined by TypeScript.
-
undefinedType
public static Node.TypeDeclarationNode undefinedType()
- Returns:
- a new node representing the Undefined type as defined by TypeScript.
-
namedType
public static Node.TypeDeclarationNode namedType(java.lang.String typeName)
Splits a '.' separated qualified name into a tree of type segments.- Parameters:
typeName
- a qualified name such as "goog.ui.Window"- Returns:
- a new node representing the type
- See Also:
namedType(Iterable)
-
namedType
public static Node.TypeDeclarationNode namedType(java.lang.Iterable<java.lang.String> segments)
Produces a tree structure similar to the Rhino AST of a qualified name expression, under a top-level NAMED_TYPE node.Example:
NAMED_TYPE NAME goog STRING ui STRING Window
-
recordType
public static Node.TypeDeclarationNode recordType(java.util.LinkedHashMap<java.lang.String,Node.TypeDeclarationNode> properties)
Represents a structural type. Closure calls this a Record Type and accepts the syntax{myNum: number, myObject}
Example:
RECORD_TYPE STRING_KEY myNum NUMBER_TYPE STRING_KEY myObject
- Parameters:
properties
- a map from property name to property type- Returns:
- a new node representing the record type
-
functionType
public static Node.TypeDeclarationNode functionType(Node returnType, java.util.LinkedHashMap<java.lang.String,Node.TypeDeclarationNode> requiredParams, java.util.LinkedHashMap<java.lang.String,Node.TypeDeclarationNode> optionalParams, java.lang.String restName, Node.TypeDeclarationNode restType)
Represents a function type. Closure has syntax like{function(string, boolean):number}
Closure doesn't include parameter names. If the parameter types are unnamed, arbitrary names can be substituted, eg. p1, p2, etc.Example:
FUNCTION_TYPE NUMBER_TYPE STRING_KEY p1 [declared_type_expr: STRING_TYPE] STRING_KEY p2 [declared_type_expr: BOOLEAN_TYPE]
- Parameters:
returnType
- the type returned by the function, possibly ANY_TYPErequiredParams
- the names and types of the required parameters.optionalParams
- the names and types of the optional parameters.restName
- the name of the rest parameter, if any.restType
- the type of the rest parameter, if any.
-
parameterizedType
public static Node.TypeDeclarationNode parameterizedType(Node.TypeDeclarationNode baseType, java.lang.Iterable<Node.TypeDeclarationNode> typeParameters)
Represents a parameterized, or generic, type. Closure calls this a Type Application and accepts syntax like{Object.<string, number>}
Example:
PARAMETERIZED_TYPE NAMED_TYPE NAME Object STRING_TYPE NUMBER_TYPE
- Parameters:
baseType
-typeParameters
-
-
arrayType
public static Node.TypeDeclarationNode arrayType(Node elementType)
Represents an array type. In Closure, this is represented by aparameterized type
ofArray
withelementType
as the sole type parameter.Example
ARRAY_TYPE elementType
-
unionType
public static Node.TypeDeclarationNode unionType(java.lang.Iterable<Node.TypeDeclarationNode> options)
Represents a union type, which can be one of the given types. Closure accepts syntax like{(number|boolean)}
Example:
UNION_TYPE NUMBER_TYPE BOOLEAN_TYPE
- Parameters:
options
- the types which are accepted- Returns:
- a new node representing the union type
-
unionType
public static Node.TypeDeclarationNode unionType(Node.TypeDeclarationNode... options)
-
optionalParameter
public static Node.TypeDeclarationNode optionalParameter(Node.TypeDeclarationNode parameterType)
Represents a function parameter that is optional. In closure syntax, this isfunction(?string=, number=)
In TypeScript syntax, it is(firstName: string, lastName?: string)=>string
- Parameters:
parameterType
- the type of the parameter- Returns:
- a new node representing the function parameter type
-
-