logo

abstract class

sys::Slot

sys::Obj
  sys::Slot
   1  //
   2  // Copyright (c) 2006, Brian Frank and Andy Frank
   3  // Licensed under the Academic Free License version 3.0
   4  //
   5  // History:
   6  //   4 Jan 06  Brian Frank  Creation
   7  //
   8  
   9  **
  10  ** Slot represents a member field or method on a Type.
  11  **
  12  abstract class Slot
  13  {
  14  
  15  //////////////////////////////////////////////////////////////////////////
  16  // Management
  17  //////////////////////////////////////////////////////////////////////////
  18  
  19    **
  20    ** Find a Slot by it's qualified name "pod::Type.slot".  If the slot
  21    ** doesn't exist and checked is false then return null, otherwise
  22    ** throw UnknownSlotErr.
  23    **
  24    static Slot find(Str qname, Bool checked := true)
  25  
  26    **
  27    ** Convenience for '(Method)find(qname, checked)'
  28    **
  29    static Method findMethod(Str qname, Bool checked := true)
  30  
  31    **
  32    ** Convenience for '(Field)find(qname, checked)'
  33    **
  34    static Field findField(Str qname, Bool checked := true)
  35  
  36    **
  37    ** Convenience for 'findMethod(qname, checked).func'
  38    **
  39    static Func findFunc(Str qname, Bool checked := true)
  40  
  41  //////////////////////////////////////////////////////////////////////////
  42  // Constructor
  43  //////////////////////////////////////////////////////////////////////////
  44  
  45    **
  46    ** Internal constructor.
  47    **
  48    internal new make()
  49  
  50  //////////////////////////////////////////////////////////////////////////
  51  // Naming
  52  //////////////////////////////////////////////////////////////////////////
  53  
  54    **
  55    ** Parent type which defines this slot.
  56    **
  57    Type parent()
  58  
  59    **
  60    ** Simple name of the slot such as "size".
  61    **
  62    Str name()
  63  
  64    **
  65    ** Qualified name such as "sys:Str.size".
  66    **
  67    Str qname()
  68  
  69    **
  70    ** Return true if this is an instance of Field.
  71    **
  72    Bool isField()
  73  
  74    **
  75    ** Return true if this is an instance of Method.
  76    **
  77    Bool isMethod()
  78  
  79  //////////////////////////////////////////////////////////////////////////
  80  // Flags
  81  //////////////////////////////////////////////////////////////////////////
  82  
  83    **
  84    ** Return if slot is abstract (no implementation provided).
  85    **
  86    Bool isAbstract()
  87  
  88    **
  89    ** Return if slot is constant and thread safe.  A constant field
  90    ** is explicitly marked with the const modifier and guaranteed
  91    ** to always reference the same immutable object for the life of
  92    ** the VM.  A const method is guaranteed to not capture any
  93    ** state from its thread, and is safe to execute on other threads.
  94    ** The compiler marks methods as const based on the following
  95    ** analysis:
  96    **   - static methods are always automatically const
  97    **   - instance methods are never const
  98    **   - closures which don't capture any variables from their
  99    **     scope are automatically const
 100    **   - partional apply methods which only capture const variables
 101    **     from their scope are automatically const
 102    **
 103    Bool isConst()
 104  
 105    **
 106    ** Return if slot is constructor method.
 107    **
 108    Bool isCtor()
 109  
 110    **
 111    ** Return if slot has internal protection scope.
 112    **
 113    Bool isInternal()
 114  
 115    **
 116    ** Return if slot is native.
 117    **
 118    Bool isNative()
 119  
 120    **
 121    ** Return if slot is an override (of parent's virtual method).
 122    **
 123    Bool isOverride()
 124  
 125    **
 126    ** Return if slot has private protection scope.
 127    **
 128    Bool isPrivate()
 129  
 130    **
 131    ** Return if slot has protected protection scope.
 132    **
 133    Bool isProtected()
 134  
 135    **
 136    ** Return if slot has public protection scope.
 137    **
 138    Bool isPublic()
 139  
 140    **
 141    ** Return if slot is static (class based, rather than instance).
 142    **
 143    Bool isStatic()
 144  
 145    **
 146    ** Return if this slot was generated by the compiler.
 147    **
 148    Bool isSynthetic()
 149  
 150    **
 151    ** Return if slot is virtual (may be overridden in subclasses).
 152    **
 153    Bool isVirtual()
 154  
 155  //////////////////////////////////////////////////////////////////////////
 156  // Facets
 157  //////////////////////////////////////////////////////////////////////////
 158  
 159    **
 160    ** Return all the facets defined for this slot or an empty map
 161    ** if no facets are defined.  If looking up a facet by name, then
 162    ** use the `facet` method which will provide better performance.
 163    ** See the [Facets Doc]`docLang::Facets` for details.
 164    **
 165    Str:Obj facets()
 166  
 167    **
 168    ** Get a facet by name, or return the 'def' is the facet is not defined.
 169    ** See the [Facets Doc]`docLang::Facets` for details.
 170    **
 171    Obj facet(Str name, Obj def := null)
 172  
 173  //////////////////////////////////////////////////////////////////////////
 174  // Documentation
 175  //////////////////////////////////////////////////////////////////////////
 176  
 177    **
 178    ** Return the raw fandoc for this slot or null if not available.
 179    **
 180    Str doc()
 181  
 182  //////////////////////////////////////////////////////////////////////////
 183  // Conversion
 184  //////////////////////////////////////////////////////////////////////////
 185  
 186    **
 187    ** Always return qname().
 188    **
 189    override Str toStr()
 190  
 191    **
 192    ** Return a string representation of the Fan code signature.
 193    **
 194    virtual Str signature()
 195  
 196  }