Type.hx 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * Copyright (c) 2005, The haXe Project Contributors
  3. * All rights reserved.
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. *
  7. * - Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * - Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY
  14. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  15. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  16. * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR
  17. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  18. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  19. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  20. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  21. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  22. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  23. * DAMAGE.
  24. */
  25. /**
  26. The diffent possible runtime types of a value.
  27. See [Type] for the haXe Reflection API.
  28. **/
  29. enum ValueType {
  30. TNull;
  31. TInt;
  32. TFloat;
  33. TBool;
  34. TObject;
  35. TFunction;
  36. TClass( c : Class<Dynamic> );
  37. TEnum( e : Enum<Dynamic> );
  38. TUnknown;
  39. }
  40. /**
  41. The haXe Reflection API enables you to retreive informations about any value,
  42. Classes and Enums at runtime.
  43. **/
  44. extern class Type {
  45. /**
  46. Returns the class of a value or [null] if this value is not a Class instance.
  47. **/
  48. public static function getClass<T>( o : T ) : Class<T>;
  49. /**
  50. Returns the enum of a value or [null] if this value is not an Enum instance.
  51. **/
  52. public static function getEnum( o : Dynamic ) : Enum<Dynamic>;
  53. /**
  54. Returns the super-class of a class, or null if no super class.
  55. **/
  56. public static function getSuperClass( c : Class<Dynamic> ) : Class<Dynamic>;
  57. /**
  58. Returns the complete name of a class.
  59. **/
  60. public static function getClassName( c : Class<Dynamic> ) : String;
  61. /**
  62. Returns the complete name of an enum.
  63. **/
  64. public static function getEnumName( e : Enum<Dynamic> ) : String;
  65. /**
  66. Evaluates a class from a name. The class must have been compiled
  67. to be accessible.
  68. **/
  69. public static function resolveClass( name : String ) : Class<Dynamic>;
  70. /**
  71. Evaluates an enum from a name. The enum must have been compiled
  72. to be accessible.
  73. **/
  74. public static function resolveEnum( name : String ) : Enum<Dynamic>;
  75. /**
  76. Creates an instance of the given class with the list of constructor arguments.
  77. **/
  78. public static function createInstance<T>( cl : Class<T>, args : Array<Dynamic> ) : T;
  79. /**
  80. Similar to [Reflect.createInstance] excepts that the constructor is not called.
  81. This enables you to create an instance without any side-effect.
  82. **/
  83. public static function createEmptyInstance<T>( cl : Class<T> ) : T;
  84. /**
  85. Create an instance of an enum by using a constructor name and parameters.
  86. **/
  87. public static function createEnum<T>( e : Enum<T>, constr : String, ?params : Array<Dynamic> ) : T;
  88. /**
  89. Create an instance of an enum by using a constructor index and parameters.
  90. **/
  91. public static function createEnumIndex<T>( e : Enum<T>, index : Int, ?params : Array<Dynamic> ) : T;
  92. /**
  93. Returns the list of instance fields.
  94. **/
  95. public static function getInstanceFields( c : Class<Dynamic> ) : Array<String>;
  96. /**
  97. Returns the list of a class static fields.
  98. **/
  99. public static function getClassFields( c : Class<Dynamic> ) : Array<String>;
  100. /**
  101. Returns all the available constructor names for an enum.
  102. **/
  103. public static function getEnumConstructs( e : Enum<Dynamic> ) : Array<String>;
  104. /**
  105. Returns the runtime type of a value.
  106. **/
  107. public static function typeof( v : Dynamic ) : ValueType;
  108. /**
  109. Recursively compare two enums constructors and parameters.
  110. **/
  111. public static function enumEq<T>( a : T, b : T ) : Bool;
  112. /**
  113. Returns the constructor of an enum
  114. **/
  115. public static function enumConstructor( e : Dynamic ) : String;
  116. /**
  117. Returns the parameters of an enum
  118. **/
  119. public static function enumParameters( e : Dynamic ) : Array<Dynamic>;
  120. /**
  121. Returns the index of the constructor of an enum
  122. **/
  123. public static function enumIndex( e : Dynamic ) : Int;
  124. /**
  125. Returns the list of all enum values that don't take any parameter.
  126. **/
  127. public static function allEnums<T>( e : Enum<T> ) : Array<T>;
  128. }