@haxall/haxall
    Preparing search index...

    Class Type

    Type defines the contract of an Obj by the slots it supports. Types model the inheritance relationships and provide a mapping for all the slots both inherited and declared.

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    type$: Type

    Methods

    • The direct super class of this type (null for Obj). Return sys::Obj for all mixin types.

      Examples:

      Obj#.base        =>  null
      Int#.base => sys::Num
      OutStream#.base => sys::Obj

      Returns Type

    • Return a negative integer, zero, or a positive integer if this object is less than, equal to, or greater than the specified object:

      this < that   =>  <0
      this == that => 0
      this > that => >0

      This method may also be accessed via the < <= <=> >= and > shortcut operators. If not overridden the default implementation compares the toStr representations. Also see docLang.

      Examples:

      3.compare(8)  =>  -1
      8.compare(3) => 1
      8.compare(8) => 0
      3 <=> 8 => -1 // shortcut for 3.compare(8)

      Parameters

      Returns number

    • Return the raw fandoc for this type or null if not available.

      Returns string

    • Return an immutable empty list of this type. Since immutable lists can be used safely everywhere, this allows signficant memory savings instead of allocating new empty lists.

      Examples:

      Str#.emptyList  =>  Str[,]
      

      Returns List<JsObj>

    • Compare this object to the specified for equality. This method may be accessed via the == and != shortcut operators. If not overridden the default implementation compares for reference equality using the === operator. If this method is overridden, then hash() must also be overridden such that any two objects which return true for equals() must return the same value for hash(). This method must accept null and return false.

      Parameters

      Returns boolean

    • Get a facet by its type. If not found on this type then return null or throw UnknownFacetErr based on check flag. See Facets Doc for details.

      Parameters

      • type: Type
      • Optionalchecked: boolean

      Returns Facet

    • Get the list of facets defined on this type or return an empty list if no facets are defined. If looking up a facet by type, then use the facet method which will provide better performance. See Facets Doc for details.

      Returns List<Facet>

    • Convenience for (Field)slot(name, checked)

      Parameters

      • name: string
      • Optionalchecked: boolean

      Returns Field

    • List of all the defined fields (including inherited fields).

      Returns List<Field>

    • Does this type implement the specified type. If true, then this type is assignable to the specified type (although the converse is not necessarily true). This method provides the same semantics as the is operator, but between two types rather than an instance and a type. All types (including mixin types) fit sys::Obj.

      This method implicitly ignores the nullability of both this and t such that this method is always equivalent to:

      this.toNonNullable.fits(t.toNonNullable)
      

      Example:

      Float#.fits(Float#) =>  true
      Float#.fits(Num#) => true
      Float#.fits(Obj#) => true
      Float#.fits(Str#) => false
      Obj#.fits(Float#) => false

      Parameters

      Returns boolean

    • Return if this type has the specified facet defined.

      Parameters

      Returns boolean

    • Return a unique hashcode for this object. If a class overrides hash() then it must ensure if equals() returns true for any two objects then they have same hash code.

      Returns number

    • Return a recursive flattened list of all the types this type inherits from. The result list always includes this type itself. The result of this method represents the complete list of types implemented by this type - instances of this type are assignable to any type in this list. All types (including mixins) will include sys::Obj in this list.

      Examples:

      Obj#.inheritance  =>  [sys::Obj]
      Int#.inheritance => [sys::Int, sys::Num, sys::Obj]

      Returns List<Type>

    • Return if this Type is abstract and cannot be instantiated. This method will always return true if the type is a mixin.

      Returns boolean

    • Return if this Type is a class (as opposed to enum or mixin)

      Returns boolean

    • Return if this is a const class which means instances of this class are immutable.

      Returns boolean

    • Return if this Type is an Enum type.

      Returns boolean

    • Return if this Type is a Facet type.

      Returns boolean

    • Return if this Type is marked final which means it may not be subclassed.

      Returns boolean

    • A generic type contains slot signatures which may be parameterized - for example Map's key and value types are generic as K and V. Fantom supports three built-in generic types: List, Map, and Func. A parameterized type such as Str[] is not a generic type (all of its generic parameters have been filled in). User defined generic types are not supported in Fantom.

      Examples:

      Str#.isGeneric   => false
      List#.isGeneric => true
      Str[]#.isGeneric => false

      Returns boolean

    • Return if this Obj is immutable and safe to share between threads:

      • an instance of a const class
      • the result of toImmutable on List, Map, or Buf
      • a Func object may or may not be immutable - see sys::Func.
      • other instances are assumed mutable and return false

      Returns boolean

    • Return if this Type has internal protection scope.

      Returns boolean

    • Return if this Type is a mixin type and cannot be instantiated.

      Returns boolean

    • Is this a nullable type. Nullable types can store the null value, but non-nullables are never null. Null types are indicated with a trailing "?".

      Returns boolean

    • Return if this Type has public protection scope.

      Returns boolean

    • Return if this Type was generated by the compiler.

      Returns boolean

    • Is this a value type. Fantom supports three implicit value types: Bool, Int, and Float.

      Returns boolean

    • Create a new instance of this Type using the following rules:

      1. Call public constructor make with specified arguments
      2. If no public constructor called make or invalid number of of required arguments, then return value of defVal slot (must be static field or static method with zero params)
      3. If no public defVal field, then throw Err

      Parameters

      Returns JsObj

    • Convenience for (Method)slot(name, checked)

      Parameters

      • name: string
      • Optionalchecked: boolean

      Returns Method

    • List of all the defined methods (including inherited methods).

      Returns List<Method>

    • Return the mixins directly implemented by this type.

      Examples:

      Obj#.mixins        =>  [,]
      Buf#.mixins => [sys::InStream, sys::OutStream]
      OutStream#.mixins => [,]

      Returns List<Type>

    • Simple name of the type such as "Str". For parameterized types derived from List, Map, or Func, this method always returns "List", "Map", or "Func" respectively.

      Examples:

      Str#.name         => "Str"
      acme::Foo#.name => "Foo"
      acme::Foo[]#.name => "List"

      Returns string

    • If this is a generic type, then dynamically create a new parameterized type with the specified name to type map. If this type is not generic then throw UnsupportedErr. Throw ArgErr if params fails to specify the required parameters:

      List => V required
      Map => K, V required
      Func => R required, A-H optional

      Examples:

      List#.parameterize(["V":Bool#]) => Bool[]
      Map#.parameterize(["K":Str#, "V":Obj#]) => Str:Obj

      Parameters

      Returns Type

    • If this is a parameterized type, then return the map of names to types. If this is not a parameterized type return an empty map.

      Examples:

      Str#.params => [:]
      Str[]#.params => ["V":Str, "L":Str[]]
      Int:Slot#.params => ["K":Int, "V":Slot, "M":Int:Slot]
      |Int x, Float y->Bool|#.params => ["A":Int, "B":Float, "R":Bool]

      Returns Map<string, Type>

    • Parent pod which defines this type. For parameterized types derived from List, Map, or Func, this method always returns the sys pod.

      Examples:

      Str#.pod         => sys
      acme::Foo#.pod => acme
      acme::Foo[]#.pod => sys

      Returns Pod

    • Qualified name formatted as "pod::name". For parameterized types derived from List, Map, or Func, this method always returns "sys::List", "sys::Map", or "sys::Func" respectively. If this is a nullable type, the qname does not include the "?".

      Examples:

      Str#.qname         => "sys::Str"
      Str?#.qname => "sys::Str"
      acme::Foo#.qname => "acme::Foo"
      acme::Foo[]#.qname => "sys::List"

      Returns string

    • Return the formal signature of this type. In the case of non-parameterized types the signature is the same as qname. For parameterized types derived from List, Map, or Func the signature uses the following special syntax:

      List => V[]
      Map => [K:V]
      Func => |A,B...->R|

      If this is a nullable type, the signature ends with "?" such as "sys::Int?".

      Examples:

      Str#.signature => "sys::Str"
      Str?#.signature => "sys::Str?"
      Int[]#.signature => "sys::Int[]"
      Int:Str#.signature => "[sys::Int:sys::Str]"
      Str:Buf[]#.signature => [sys::Str:sys::Buf[]]
      |Float x->Bool|#.signature => "|sys::Float->sys::Bool|"
      |Float x, Int y|#.signature => |sys::Float,sys::Int->sys::Void|

      Returns string

    • Lookup a slot by name. If the slot doesn't exist and checked is false then return null, otherwise throw UnknownSlotErr. Slots are any field or method in this type's scope including those defined directly by this type and those inherited from super class or mixins.

      Parameters

      • name: string
      • Optionalchecked: boolean

      Returns Slot

    • List of all the defined slots, both fields and methods (including inherited slots).

      Returns List<Slot>

    • Get an immutable representation of this instance or throw NotImmutableErr if this object cannot be represented as an immutable:

      • if type is const, return this
      • if already an immutable List, Map, Buf, or Func return this
      • if a List, then attempt to perform a deep clone by calling toImmutable on all items
      • if a Map, then attempt to perform a deep clone by calling toImmutable on all values (keys are already immutable)
      • some Funcs can be made immutable - see sys::Func
      • if a Buf create immutable copy, see sys::Buf
      • any other object throws NotImmutableErr

      Returns Readonly<this>

    • Convenience for List#.parameterize(["V":this])

      Examples:

      Int#.toListOf => Int[]
      Str[]#.toListOf => Str[][]

      Returns Type

    • Return signature. This method is used to enable toLocale to be used with duck typing across most built-in types. Note: we may change the specification of this method in the future to allow localized type names.

      Returns string

    • Return this type as a non-nullable type. If this type is already non-nullable then return this.

      Returns Type

    • Return this type as a nullable type. If this type is already nullable then return this.

      Returns Type

    • Always return signature().

      Returns string

    • Trap a dynamic call for handling. Dynamic calls are invoked with the -> shortcut operator:

      a->x        a.trap("x", null)
      a->x() a.trap("x", null)
      a->x = b a.trap("x", [b])
      a->x(b) a.trap("x", [b])
      a->x(b, c) a.trap("x", [b, c])

      The default implementation provided by Obj attempts to use reflection. If name maps to a method, it is invoked with the specified arguments. If name maps to a field and args.size is zero, get the field. If name maps to a field and args.size is one, set the field and return args[0]. Otherwise throw UnknownSlotErr.

      Parameters

      Returns JsObj

    • Get the Type instance which represents this object's class. Also seeType.of or Pod.of.

      Returns Type

    • This method called whenever an it-block is applied to an object. The default implementation calls the function with this, and then returns this.

      Parameters

      • f: (arg0: this) => void

      Returns this

    • Write x.toStr to standard output followed by newline. If x is null then print "null". If no argument is provided then print an empty line.

      Parameters

      Returns void

    • Find a Type by its qualified name "pod::Type". If the type doesn't exist and checked is false then return null, otherwise throw UnknownTypeErr.

      Parameters

      • qname: string
      • Optionalchecked: boolean

      Returns Type

    • Get the class Type of the given instance. Also see Obj.typeof which provides the same functionality.

      Parameters

      Returns Type