Class TypeDeclarationsIR


  • public class TypeDeclarationsIR
    extends java.lang.Object
    An AST construction helper class for Node
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static Node anyType()
      Equivalent to the UNKNOWN type in Closure, expressed with {?}
      static Node arrayType​(Node elementType)
      Represents an array type.
      static Node booleanType()  
      static Node functionType​(Node returnType, java.util.LinkedHashMap<java.lang.String,​Node> requiredParams, java.util.LinkedHashMap<java.lang.String,​Node> optionalParams, java.lang.String restName, Node restType)
      Represents a function type.
      static Node 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 namedType​(java.lang.String typeName)
      Splits a '.' separated qualified name into a tree of type segments.
      static Node numberType()  
      static Node optionalParameter​(Node parameterType)
      Represents a function parameter that is optional.
      static Node parameterizedType​(Node baseType, java.lang.Iterable<Node> typeParameters)
      Represents a parameterized, or generic, type.
      static Node recordType​(java.util.LinkedHashMap<java.lang.String,​Node> properties)
      Represents a structural type.
      static Node stringType()  
      static Node undefinedType()  
      static Node unionType​(Node... options)  
      static Node unionType​(java.lang.Iterable<Node> options)
      Represents a union type, which can be one of the given types.
      static Node voidType()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • TypeDeclarationsIR

        public TypeDeclarationsIR()
    • Method Detail

      • stringType

        public static Node stringType()
        Returns:
        a new node representing the string built-in type.
      • numberType

        public static Node numberType()
        Returns:
        a new node representing the number built-in type.
      • booleanType

        public static Node booleanType()
        Returns:
        a new node representing the boolean built-in type.
      • anyType

        public static Node anyType()
        Equivalent to the UNKNOWN type in Closure, expressed with {?}
        Returns:
        a new node representing any type, without type checking.
      • voidType

        public static Node voidType()
        Returns:
        a new node representing the Void type as defined by TypeScript.
      • undefinedType

        public static Node undefinedType()
        Returns:
        a new node representing the Undefined type as defined by TypeScript.
      • namedType

        public static Node 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 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 recordType​(java.util.LinkedHashMap<java.lang.String,​Node> 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 functionType​(Node returnType,
                                        java.util.LinkedHashMap<java.lang.String,​Node> requiredParams,
                                        java.util.LinkedHashMap<java.lang.String,​Node> optionalParams,
                                        java.lang.String restName,
                                        Node 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_TYPE
        requiredParams - 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 parameterizedType​(Node baseType,
                                             java.lang.Iterable<Node> 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 arrayType​(Node elementType)
        Represents an array type. In Closure, this is represented by a parameterized type of Array with elementType as the sole type parameter.

        Example

         ARRAY_TYPE
           elementType
         
      • unionType

        public static Node unionType​(java.lang.Iterable<Node> 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 unionType​(Node... options)
      • optionalParameter

        public static Node optionalParameter​(Node parameterType)
        Represents a function parameter that is optional. In closure syntax, this is function(?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