Browse Source

Null-safe Type.getClass (#11115)

RblSb 2 years ago
parent
commit
ee92125b21

+ 1 - 1
std/Type.hx

@@ -37,7 +37,7 @@ extern class Type {
 
 		In general, type parameter information cannot be obtained at runtime.
 	**/
-	static function getClass<T>(o:T):Class<T>;
+	static function getClass<T>(o:T):Null<Class<T>>;
 
 	/**
 		Returns the enum of enum instance `o`.

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

@@ -32,7 +32,7 @@ enum ValueType {
 }
 
 @:coreApi class Type {
-	public static function getClass<T>(o:T):Class<T>
+	public static function getClass<T>(o:T):Null<Class<T>>
 		untyped {
 			if (o == null || !Reflect.isObject(o))
 				return null;

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

@@ -43,7 +43,7 @@ enum ValueType {
 }
 
 @:coreApi class Type {
-	public static function getClass<T>(o:T):Class<T> {
+	public static function getClass<T>(o:T):Null<Class<T>> {
 		if (Object.ReferenceEquals(o, null) || Std.isOfType(o, DynamicObject) || Std.isOfType(o, cs.system.Type))
 			return null;
 

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

@@ -32,7 +32,7 @@ enum ValueType {
 }
 
 @:coreApi class Type {
-	public static function getClass<T>(o:T):Class<T>
+	public static function getClass<T>(o:T):Null<Class<T>>
 		untyped {
 			var cname = __global__["flash.utils.getQualifiedClassName"](o);
 			if (cname == "null" || cname == "Object" || cname == "int" || cname == "Number" || cname == "Boolean")

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

@@ -82,7 +82,7 @@ class Type {
 		allTypes.set(b, t);
 	}
 
-	public static function getClass<T>(o:T):Class<T> {
+	public static function getClass<T>(o:T):Null<Class<T>> {
 		var t = hl.Type.getDynamic(o);
 		if (t.kind == HVirtual) {
 			o = hl.Api.getVirtualValue(o);

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

@@ -37,7 +37,7 @@ enum ValueType {
 }
 
 @:coreApi class Type {
-	public static function getClass<T>(o:T):Class<T> {
+	public static function getClass<T>(o:T):Null<Class<T>> {
 		if (o == null || Std.isOfType(o, DynamicObject) || Std.isOfType(o, java.lang.Class)) {
 			return null;
 		}

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

@@ -32,7 +32,7 @@ enum ValueType {
 }
 
 @:coreApi class Type {
-	public static inline function getClass<T>(o:T):Class<T> {
+	public static inline function getClass<T>(o:T):Null<Class<T>> {
 		return @:privateAccess js.Boot.getClass(o);
 	}
 

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

@@ -32,7 +32,7 @@ class Type {
 		return c.isAnnotationPresent(cast EnumValueReflectionInformation);
 	}
 
-	public static function getClass<T>(o:T):Class<T> {
+	public static function getClass<T>(o:T):Null<Class<T>> {
 		if (o == null) {
 			return null;
 		}

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

@@ -36,7 +36,7 @@ enum ValueType {
 }
 
 @:coreApi class Type {
-	public static function getClass<T>(o:T):Class<T>
+	public static function getClass<T>(o:T):Null<Class<T>>
 		untyped {
 			if (o == null)
 				return null;

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

@@ -34,7 +34,7 @@ enum ValueType {
 
 @:coreApi class Type {
 
-	public static function getClass<T>( o : T ) : Class<T> untyped {
+	public static function getClass<T>( o : T ) : Null<Class<T>> untyped {
 		if( __dollar__typeof(o) != __dollar__tobject )
 			return null;
 		var p = __dollar__objgetproto(o);

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

@@ -39,7 +39,7 @@ enum ValueType {
 }
 
 @:coreApi class Type {
-	public static function getClass<T>(o:T):Class<T> {
+	public static function getClass<T>(o:T):Null<Class<T>> {
 		if (Global.is_object(o) && !Boot.isClass(o) && !Boot.isEnumValue(o)) {
 			var cls = Boot.getClass(Global.get_class(cast o));
 			return (Boot.isAnon(o) ? null : cast cls);

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

@@ -40,7 +40,7 @@ enum ValueType {
 
 @:access(python.Boot)
 @:coreApi class Type {
-	public static function getClass<T>(o:T):Class<T> {
+	public static function getClass<T>(o:T):Null<Class<T>> {
 		if (o == null)
 			return null;