public final class TypeDeclarationsIRFactory extends Object
IRFactory) as well as those created from TypeScript-style inline type
declarations.
This is an alternative to the AST found in the root property of JSTypeExpression, which is a crufty AST that reuses language tokens.
| Constructor and Description |
|---|
TypeDeclarationsIRFactory() |
| Modifier and Type | Method and 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 |
convert(JSTypeExpression typeExpr) |
static Node.TypeDeclarationNode |
convertTypeNodeAST(Node n)
The root of a JSTypeExpression is very different from an AST node, even
though we use the same Java class to represent them.
|
static Node.TypeDeclarationNode |
functionType(Node returnType,
LinkedHashMap<String,Node.TypeDeclarationNode> parameters,
String restName,
Node.TypeDeclarationNode restType)
Represents a function type.
|
static Node.TypeDeclarationNode |
namedType(Iterable<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(String typeName)
Splits a '.' separated qualified name into a tree of type segments.
|
static Node.TypeDeclarationNode |
nullable(Node.TypeDeclarationNode type)
We assume that types are non-nullable by default.
|
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,
Iterable<Node.TypeDeclarationNode> typeParameters)
Represents a parameterized, or generic, type.
|
static Node.TypeDeclarationNode |
recordType(LinkedHashMap<String,Node.TypeDeclarationNode> properties)
Represents a structural type.
|
static Node.TypeDeclarationNode |
restParams(Node type)
Represents a function parameter type which may be repeated.
|
static Node.TypeDeclarationNode |
stringType() |
static Node.TypeDeclarationNode |
undefinedType() |
static Node.TypeDeclarationNode |
unionType(Iterable<Node.TypeDeclarationNode> options)
Represents a union type, which can be one of the given types.
|
static Node.TypeDeclarationNode |
unionType(Node.TypeDeclarationNode... options) |
static Node.TypeDeclarationNode |
voidType() |
public static Node.TypeDeclarationNode stringType()
public static Node.TypeDeclarationNode numberType()
public static Node.TypeDeclarationNode booleanType()
public static Node.TypeDeclarationNode nullable(Node.TypeDeclarationNode type)
public static Node.TypeDeclarationNode anyType()
{?}public static Node.TypeDeclarationNode voidType()
public static Node.TypeDeclarationNode undefinedType()
public static Node.TypeDeclarationNode namedType(String typeName)
typeName - a qualified name such as "goog.ui.Window"namedType(Iterable)public static Node.TypeDeclarationNode namedType(Iterable<String> segments)
Example:
NAMED_TYPE
NAME goog
STRING ui
STRING Window
public static Node.TypeDeclarationNode recordType(LinkedHashMap<String,Node.TypeDeclarationNode> properties)
{myNum: number, myObject}
Example:
RECORD_TYPE
STRING_KEY myNum
NUMBER_TYPE
STRING_KEY myObject
properties - a map from property name to property typepublic static Node.TypeDeclarationNode functionType(Node returnType, LinkedHashMap<String,Node.TypeDeclarationNode> parameters, String restName, Node.TypeDeclarationNode restType)
{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
STRING_TYPE
STRING_KEY p2
BOOLEAN_TYPE
returnType - the type returned by the function, possibly UNKNOWN_TYPEparameters - the types of the parameters.public static Node.TypeDeclarationNode parameterizedType(Node.TypeDeclarationNode baseType, Iterable<Node.TypeDeclarationNode> typeParameters)
{Object.<string, number>}
Example:
PARAMETERIZED_TYPE
NAMED_TYPE
NAME Object
STRING_TYPE
NUMBER_TYPE
baseType - typeParameters - public static Node.TypeDeclarationNode arrayType(Node elementType)
parameterized type of Array
with elementType as the sole type parameter.
Example
ARRAY_TYPE elementType
public static Node.TypeDeclarationNode unionType(Iterable<Node.TypeDeclarationNode> options)
{(number|boolean)}
Example:
UNION_TYPE NUMBER_TYPE BOOLEAN_TYPE
options - the types which are acceptedpublic static Node.TypeDeclarationNode unionType(Node.TypeDeclarationNode... options)
public static Node.TypeDeclarationNode restParams(Node type)
{function(string, ...number): number}
FUNCTION_TYPE
NUMBER_TYPE
STRING_KEY p1
STRING_TYPE
REST_PARAMETER_TYPE
STRING_KEY p2
NUMBER_TYPE
type - an array type that is seen inside the function bodypublic static Node.TypeDeclarationNode optionalParameter(Node.TypeDeclarationNode parameterType)
function(?string=, number=)
In TypeScript syntax, it is
(firstName: string, lastName?: string)=>stringparameterType - the type of the parameter@Nullable public static Node.TypeDeclarationNode convert(@Nullable JSTypeExpression typeExpr)
@Nullable public static Node.TypeDeclarationNode convertTypeNodeAST(Node n)
Copyright © 2009-2015 Google. All Rights Reserved.