public class TypeDeclarationsIR extends Object
Constructor and Description |
---|
TypeDeclarationsIR() |
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 |
functionType(Node returnType,
LinkedHashMap<String,Node.TypeDeclarationNode> requiredParams,
LinkedHashMap<String,Node.TypeDeclarationNode> optionalParams,
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 |
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 |
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 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> requiredParams, LinkedHashMap<String,Node.TypeDeclarationNode> optionalParams, 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 [declared_type_expr: STRING_TYPE] STRING_KEY p2 [declared_type_expr: BOOLEAN_TYPE]
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.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 optionalParameter(Node.TypeDeclarationNode parameterType)
function(?string=, number=)
In TypeScript syntax, it is
(firstName: string, lastName?: string)=>string
parameterType
- the type of the parameterCopyright © 2009–2023 Google. All rights reserved.