Browse Source

[jvm] rewrite Iterator to java.util.Iterator

Simon Krajewski 5 years ago
parent
commit
9405cf413e
2 changed files with 8 additions and 1 deletions
  1. 1 0
      src/generators/genjvm.ml
  2. 7 1
      src/generators/genshared.ml

+ 1 - 0
src/generators/genjvm.ml

@@ -2938,6 +2938,7 @@ let generate com =
 	gctx.anon_identification <- anon_identification;
 	gctx.preprocessor <- new preprocessor com.basic (jsignature_of_type gctx);
 	gctx.typedef_interfaces <- new typedef_interfaces anon_identification;
+	gctx.typedef_interfaces#add_interface_rewrite (["haxe";"root"],"Iterator") (["java";"util"],"Iterator") true;
 	let class_paths = ExtList.List.filter_map (fun java_lib ->
 		if java_lib#has_flag NativeLibraries.FlagIsStd then None
 		else begin

+ 7 - 1
src/generators/genshared.ml

@@ -465,6 +465,10 @@ class ['a] typedef_interfaces (anon_identification : 'a tanon_identification) =
 
 	val lut = Hashtbl.create 0
 	val interfaces = Hashtbl.create 0
+	val interface_rewrites = Hashtbl.create 0
+
+	method add_interface_rewrite (path_from : path) (path_to : path) (is_extern : bool) =
+		Hashtbl.replace interface_rewrites path_from (path_to,is_extern)
 
 	method get_interface_class (path : path) =
 		try Some (Hashtbl.find interfaces path)
@@ -500,10 +504,12 @@ class ['a] typedef_interfaces (anon_identification : 'a tanon_identification) =
 					acc
 			) pfm.pfm_fields PMap.empty in
 			if PMap.is_empty fields then raise (Unify_error [Unify_custom "no fields"]);
-			let c = mk_class null_module path_inner null_pos null_pos in
+			let path,is_extern = try Hashtbl.find interface_rewrites pfm.pfm_path with Not_found -> path_inner,false in
+			let c = mk_class null_module path null_pos null_pos in
 			c.cl_interface <- true;
 			c.cl_fields <- fields;
 			c.cl_ordered_fields <- PMap.fold (fun cf acc -> cf :: acc) fields [];
+			if is_extern then c.cl_extern <- true;
 			Hashtbl.replace interfaces pfm.pfm_path c;
 			c