Ver Fonte

[java/cs] Replace `nativeType` with `getNativeType` for clarification

Cauê Waneck há 10 anos atrás
pai
commit
06e715e71d
6 ficheiros alterados com 35 adições e 16 exclusões
  1. 10 0
      std/cs/Lib.hx
  2. 1 1
      std/cs/_std/Std.hx
  3. 1 1
      std/cs/_std/Type.hx
  4. 7 7
      std/cs/internal/Runtime.hx
  5. 15 6
      std/java/Lib.hx
  6. 1 1
      std/java/_std/Type.hx

+ 10 - 0
std/cs/Lib.hx

@@ -121,12 +121,22 @@ class Lib
 
 	/**
 		Gets the native System.Type from the supplied object. Will throw an exception in case of null being passed.
+		[deprecated] - use `getNativeType` instead
 	**/
+	@:deprecated('The function `nativeType` is deprecated and will be removed in later versions. Please use `getNativeType` instead')
 	public static function nativeType(obj:Dynamic):Type
 	{
 		return untyped obj.GetType();
 	}
 
+	/**
+		Gets the native System.Type from the supplied object. Will throw an exception in case of null being passed.
+	**/
+	public static function getNativeType(obj:Dynamic):Type
+	{
+		return untyped obj.GetType();
+	}
+
 #if erase_generics
 	inline private static function mkDynamic<T>(native:NativeArray<T>):NativeArray<Dynamic>
 	{

+ 1 - 1
std/cs/_std/Std.hx

@@ -47,7 +47,7 @@ import cs.internal.Exceptions;
 				return true;
 		}
 
-		return clt.IsAssignableFrom(cs.Lib.nativeType(v));
+		return clt.IsAssignableFrom(cs.Lib.getNativeType(v));
 	}
 
 	public static function string( s : Dynamic ) : String {

+ 1 - 1
std/cs/_std/Type.hx

@@ -337,7 +337,7 @@ using StringTools;
 	{
 		if (Std.is(e, cs.system.Enum))
 		{
-			var values = cs.system.Enum.GetValues(Lib.nativeType(e));
+			var values = cs.system.Enum.GetValues(Lib.getNativeType(e));
 			return cs.system.Array.IndexOf(values, e);
 		} else {
 			return cast(e, HxEnum).index;

+ 7 - 7
std/cs/internal/Runtime.hx

@@ -202,14 +202,14 @@ import cs.system.Object;
 
 			if (cv2 == null)
 			{
-				throw new cs.system.ArgumentException("Cannot compare " + nativeType(v1).ToString() + " and " + nativeType(v2).ToString());
+				throw new cs.system.ArgumentException("Cannot compare " + getNativeType(v1).ToString() + " and " + getNativeType(v2).ToString());
 			}
 
 			switch(cv1.GetTypeCode())
 			{
 				case cs.system.TypeCode.String:
 					if (cv2.GetTypeCode() != cs.system.TypeCode.String)
-						throw new cs.system.ArgumentException("Cannot compare " + nativeType(v1).ToString() + " and " + nativeType(v2).ToString());
+						throw new cs.system.ArgumentException("Cannot compare " + getNativeType(v1).ToString() + " and " + getNativeType(v2).ToString());
 					var s1 = Lib.as(v1,String);
 					var s2 = Lib.as(v2,String);
 					return String.Compare(s1,s2, cs.system.StringComparison.Ordinal);
@@ -229,7 +229,7 @@ import cs.system.Object;
 
 		if (c1 == null || c2 == null)
 		{
-			throw new cs.system.ArgumentException("Cannot compare " + nativeType(v1).ToString() + " and " + nativeType(v2).ToString());
+			throw new cs.system.ArgumentException("Cannot compare " + getNativeType(v1).ToString() + " and " + getNativeType(v2).ToString());
 		}
 
 		return c1.CompareTo(c2);
@@ -252,7 +252,7 @@ import cs.system.Object;
 			var cv2 = Lib.as(v2, IConvertible);
 			if (cv2 == null)
 			{
-				throw new cs.system.ArgumentException("Cannot dynamically add " + cs.Lib.nativeType(v1).ToString() + " and " + cs.Lib.nativeType(v2).ToString());
+				throw new cs.system.ArgumentException("Cannot dynamically add " + cs.Lib.getNativeType(v1).ToString() + " and " + cs.Lib.getNativeType(v2).ToString());
 			}
 			return cv1.ToDouble(null) + cv2.ToDouble(null);
 		}
@@ -418,7 +418,7 @@ import cs.system.Object;
 		{
 			oargs[i] = args[i];
 			if (args[i] != null)
-				ts[i] = Lib.nativeType(args[i]);
+				ts[i] = Lib.getNativeType(args[i]);
 		}
 
 		var last = 0;
@@ -498,7 +498,7 @@ import cs.system.Object;
 				if (arg == null) {
 					if (param.IsValueType)
 						oargs[i] = Activator.CreateInstance(param);
-				} else if (!cs.Lib.nativeType(arg).IsAssignableFrom(param)) {
+				} else if (!cs.Lib.getNativeType(arg).IsAssignableFrom(param)) {
 					oargs[i] = cast(arg, IConvertible).ToType(param, null);
 				}
 			}
@@ -530,7 +530,7 @@ import cs.system.Object;
 
 	public static function unbox(dyn:Dynamic):Dynamic
 	{
-		if (dyn != null && untyped (Lib.nativeType(dyn) + "").StartsWith("haxe.lang.Null"))
+		if (dyn != null && untyped (Lib.getNativeType(dyn) + "").StartsWith("haxe.lang.Null"))
 		{
 			return dyn.toDynamic();
 		} else {

+ 15 - 6
std/java/Lib.hx

@@ -46,15 +46,24 @@ package java;
 	}
 
 	/**
-		Gets the native java.lang.Class from the supplied object. Will throw an exception in case of null being passed.
+		Gets the native `java.lang.Class` from the supplied object. Will throw an exception in case of null being passed.
+		[deprecated] - use `getNativeType` instead
 	**/
-	@:functionCode('
-		return (java.lang.Class<T>) obj.getClass();
-	')
-	public static function nativeType<T>(obj:T):java.lang.Class<T>
+	@:deprecated('The function `nativeType` is deprecated and will be removed in later versions. Please use `getNativeType` instead')
+	inline public static function nativeType<T>(obj:T):java.lang.Class<T>
 	{
-		return null;
+		return untyped obj.getClass();
 	}
+
+	/**
+		Gets the native `java.lang.Class` from the supplied object. Will throw an exception in case of null being passed.
+		[deprecated] - use `getNativeType` instead
+	**/
+	inline public static function getNativeType<T>(obj:T):java.lang.Class<T>
+	{
+		return untyped obj.getClass();
+	}
+
 	/**
 		Returns a Class<> equivalent to the native java.lang.Class type.
 	**/

+ 1 - 1
std/java/_std/Type.hx

@@ -43,7 +43,7 @@ using StringTools;
 		if (o == null || Std.is(o, DynamicObject) || Std.is(o, java.lang.Class)) {
 			return null;
 		}
-		return cast java.Lib.nativeType(o);
+		return cast java.Lib.getNativeType(o);
 	}
 
 	public static function getEnum( o : EnumValue ) : Enum<Dynamic>