Reflect.hx 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*
  2. * Copyright (C)2005-2012 Haxe Foundation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  20. * DEALINGS IN THE SOFTWARE.
  21. */
  22. import java.internal.Function;
  23. import java.Boot;
  24. @:keep @:coreApi class Reflect {
  25. @:functionCode('
  26. if (o instanceof haxe.lang.IHxObject)
  27. return ((haxe.lang.IHxObject) o).__hx_getField(field, false, true, false) != haxe.lang.Runtime.undefined;
  28. return haxe.lang.Runtime.slowHasField(o, field);
  29. ')
  30. public static function hasField( o : Dynamic, field : String ) : Bool
  31. {
  32. return false;
  33. }
  34. @:functionCode('
  35. if (o instanceof haxe.lang.IHxObject)
  36. return ((haxe.lang.IHxObject) o).__hx_getField(field, false, false, false);
  37. return haxe.lang.Runtime.slowGetField(o, field, false);
  38. ')
  39. public static function field( o : Dynamic, field : String ) : Dynamic
  40. {
  41. return null;
  42. }
  43. @:functionCode('
  44. if (o instanceof haxe.lang.IHxObject)
  45. ((haxe.lang.IHxObject) o).__hx_setField(field, value, false);
  46. else
  47. haxe.lang.Runtime.slowSetField(o, field, value);
  48. ')
  49. public static function setField( o : Dynamic, field : String, value : Dynamic ) : Void
  50. {
  51. }
  52. @:functionCode('
  53. if (o instanceof haxe.lang.IHxObject)
  54. return ((haxe.lang.IHxObject) o).__hx_getField(field, false, false, true);
  55. if (haxe.lang.Runtime.slowHasField(o, "get_" + field))
  56. return haxe.lang.Runtime.slowCallField(o, "get_" + field, null);
  57. return haxe.lang.Runtime.slowGetField(o, field, false);
  58. ')
  59. public static function getProperty( o : Dynamic, field : String ) : Dynamic
  60. {
  61. return null;
  62. }
  63. @:functionCode('
  64. if (o instanceof haxe.lang.IHxObject)
  65. ((haxe.lang.IHxObject) o).__hx_setField(field, value, true);
  66. else if (haxe.lang.Runtime.slowHasField(o, "set_" + field))
  67. haxe.lang.Runtime.slowCallField(o, "set_" + field, new Array( new java.lang.Object[]{value} ));
  68. else
  69. haxe.lang.Runtime.slowSetField(o, field, value);
  70. ')
  71. public static function setProperty( o : Dynamic, field : String, value : Dynamic ) : Void
  72. {
  73. }
  74. @:functionCode('
  75. return ((haxe.lang.Function) func).__hx_invokeDynamic(args);
  76. ')
  77. public static function callMethod( o : Dynamic, func : haxe.Constraints.Function, args : Array<Dynamic> ) : Dynamic
  78. {
  79. return null;
  80. }
  81. @:functionCode('
  82. if (o instanceof haxe.lang.IHxObject)
  83. {
  84. Array<String> ret = new Array<String>();
  85. ((haxe.lang.IHxObject) o).__hx_getFields(ret);
  86. return ret;
  87. } else if (o instanceof java.lang.Class) {
  88. return Type.getClassFields( (java.lang.Class) o);
  89. } else {
  90. return new Array<String>();
  91. }
  92. ')
  93. public static function fields( o : Dynamic ) : Array<String>
  94. {
  95. return null;
  96. }
  97. @:functionCode('
  98. return f instanceof haxe.lang.Function;
  99. ')
  100. public static function isFunction( f : Dynamic ) : Bool
  101. {
  102. return false;
  103. }
  104. @:functionCode('
  105. return haxe.lang.Runtime.compare(a, b);
  106. ')
  107. public static function compare<T>( a : T, b : T ) : Int
  108. {
  109. return 0;
  110. }
  111. @:functionCode('
  112. if (f1 == f2)
  113. return true;
  114. if (f1 instanceof haxe.lang.Closure && f2 instanceof haxe.lang.Closure)
  115. {
  116. haxe.lang.Closure f1c = (haxe.lang.Closure) f1;
  117. haxe.lang.Closure f2c = (haxe.lang.Closure) f2;
  118. return haxe.lang.Runtime.refEq(f1c.obj, f2c.obj) && f1c.field.equals(f2c.field);
  119. }
  120. return false;
  121. ')
  122. public static function compareMethods( f1 : Dynamic, f2 : Dynamic ) : Bool
  123. {
  124. return false;
  125. }
  126. @:functionCode('
  127. return v != null && !(v instanceof haxe.lang.Enum || v instanceof haxe.lang.Function || v instanceof java.lang.Enum || v instanceof java.lang.Number || v instanceof java.lang.Boolean);
  128. ')
  129. public static function isObject( v : Dynamic ) : Bool
  130. {
  131. return false;
  132. }
  133. @:functionCode('
  134. return v != null && (v instanceof haxe.lang.Enum || v instanceof java.lang.Enum);
  135. ')
  136. public static function isEnumValue( v : Dynamic ) : Bool {
  137. return switch(Type.typeof(v)) {
  138. case TEnum(_): true;
  139. case _: false;
  140. }
  141. }
  142. @:functionCode('
  143. return (o instanceof haxe.lang.DynamicObject && ((haxe.lang.DynamicObject) o).__hx_deleteField(field));
  144. ')
  145. public static function deleteField( o : Dynamic, field : String ) : Bool
  146. {
  147. return false;
  148. }
  149. public static function copy<T>( o : T ) : T
  150. {
  151. var o2 : Dynamic = {};
  152. for( f in Reflect.fields(o) )
  153. Reflect.setField(o2,f,Reflect.field(o,f));
  154. return cast o2;
  155. }
  156. @:overload(function( f : Array<Dynamic> -> Void ) : Dynamic {})
  157. public static function makeVarArgs( f : Array<Dynamic> -> Dynamic ) : Dynamic
  158. {
  159. return new VarArgsFunction(f);
  160. }
  161. }