浏览代码

[java] Transform java.lang.Enum into EnumValue so it can be used correctly. Closes #2259

Cauê Waneck 11 年之前
父节点
当前提交
e04c6260bc
共有 5 个文件被更改,包括 38 次插入0 次删除
  1. 1 0
      genjava.ml
  2. 8 0
      std/cs/Lib.hx
  3. 8 0
      std/java/Lib.hx
  4. 19 0
      tests/unit/TestJava.hx
  5. 2 0
      tests/unit/native_java/src/haxe/test/MyClass.java

+ 1 - 0
genjava.ml

@@ -2458,6 +2458,7 @@ and convert_signature ctx p jsig =
 	(** other std types *)
 	(** other std types *)
 	| TObject ( (["java";"lang"], "Object"), [] ) -> mk_type_path ctx ([], "Dynamic") []
 	| TObject ( (["java";"lang"], "Object"), [] ) -> mk_type_path ctx ([], "Dynamic") []
 	| TObject ( (["java";"lang"], "String"), [] ) -> mk_type_path ctx ([], "String") []
 	| TObject ( (["java";"lang"], "String"), [] ) -> mk_type_path ctx ([], "String") []
+	| TObject ( (["java";"lang"], "Enum"), [_] ) -> mk_type_path ctx ([], "EnumValue") []
 	(** other types *)
 	(** other types *)
 	| TObject ( path, [] ) ->
 	| TObject ( path, [] ) ->
 		(match lookup_jclass ctx.jcom path with
 		(match lookup_jclass ctx.jcom path with

+ 8 - 0
std/cs/Lib.hx

@@ -103,6 +103,14 @@ class Lib
 		return untyped cl;
 		return untyped cl;
 	}
 	}
 
 
+	/**
+		Returns a System.Type equivalent to the Haxe Enum<> type.
+	**/
+	public static inline function toNativeEnum(cl:Enum<Dynamic>):Type
+	{
+		return untyped cl;
+	}
+
 	/**
 	/**
 		Gets the native System.Type from the supplied object. Will throw an exception in case of null being passed.
 		Gets the native System.Type from the supplied object. Will throw an exception in case of null being passed.
 	**/
 	**/

+ 8 - 0
std/java/Lib.hx

@@ -71,6 +71,14 @@ package java;
 		return untyped cl;
 		return untyped cl;
 	}
 	}
 
 
+	/**
+		Returns a java.lang.Class equivalent to the Haxe Enum<> type.
+	**/
+	public static inline function toNativeEnum<T>(cl:Enum<T>):java.lang.Class<T>
+	{
+		return untyped cl;
+	}
+
 	/**
 	/**
 		Returns a Haxe Array of a native Array.
 		Returns a Haxe Array of a native Array.
 		It won't copy the contents of the native array, so unless any operation triggers an array resize,
 		It won't copy the contents of the native array, so unless any operation triggers an array resize,

+ 19 - 0
tests/unit/TestJava.hx

@@ -5,6 +5,7 @@ import haxe.test.Base.Base_InnerClass;
 import haxe.test.Base.Base_24__InnerClass3__;
 import haxe.test.Base.Base_24__InnerClass3__;
 import haxe.test.Base.Base_24__InnerClass3___24InnerClass4__;
 import haxe.test.Base.Base_24__InnerClass3___24InnerClass4__;
 import haxe.test.TEnum;
 import haxe.test.TEnum;
+import java.util.EnumSet;
 
 
 #if java
 #if java
 class TestJava extends Test
 class TestJava extends Test
@@ -29,6 +30,18 @@ class TestJava extends Test
 		t(haxe.uppercasepackage.Lowercase.lowercaseFound);
 		t(haxe.uppercasepackage.Lowercase.lowercaseFound);
 	}
 	}
 
 
+	function testEnumSet()
+	{
+		var es1:EnumSet<TEnum> = EnumSet.noneOf(java.Lib.toNativeEnum(TEnum));
+		f(es1.contains(TA));
+		es1.add(TA);
+		t(es1.contains(TA));
+		var es2 = EnumSet.of(HA,HB);
+		t(es2.contains(HA));
+		t(es2.contains(HB));
+		f(es2.contains(HC));
+	}
+
 	function testHaxeKeywords()
 	function testHaxeKeywords()
 	{
 	{
 		eq(Base._inline, 42);
 		eq(Base._inline, 42);
@@ -267,4 +280,10 @@ private class HxClass extends NativeClass
   }
   }
 }
 }
 
 
+enum HaxeEnum {
+	HA;
+	HB;
+	HC;
+}
+
 #end
 #end

+ 2 - 0
tests/unit/native_java/src/haxe/test/MyClass.java

@@ -41,4 +41,6 @@ public class MyClass
 	{
 	{
 		
 		
 	}
 	}
+
+	/* public void testEnumSet */
 }
 }