Bladeren bron

[java/cs] Rename `NativeArray.array` to `make`

Added small documentation to the `NativeArray` classes
Cauê Waneck 10 jaren geleden
bovenliggende
commit
a62209fd1e
5 gewijzigde bestanden met toevoegingen van 45 en 11 verwijderingen
  1. 1 1
      gencs.ml
  2. 2 2
      genjava.ml
  3. 24 2
      std/cs/NativeArray.hx
  4. 17 5
      std/java/NativeArray.hx
  5. 1 1
      tests/unit/src/unit/issues/Issue3979.hx

+ 1 - 1
gencs.ml

@@ -1331,7 +1331,7 @@ let configure gen =
 						expr_s w e
 				| TArrayDecl el
 				| TCall ({ eexpr = TLocal { v_name = "__array__" } }, el)
-				| TCall ({ eexpr = TField(_, FStatic({ cl_path = (["cs"],"NativeArray") }, { cf_name = "array" })) }, el) ->
+				| TCall ({ eexpr = TField(_, FStatic({ cl_path = (["cs"],"NativeArray") }, { cf_name = "make" })) }, el) ->
 					let _, el = extract_tparams [] el in
 					print w "new %s" (t_s e.etype);
 					write w "{";

+ 2 - 2
genjava.ml

@@ -1268,7 +1268,7 @@ let configure gen =
 				| TMeta (_,e) ->
 					expr_s w e
 				| TCall ({ eexpr = TLocal { v_name = "__array__" } }, el)
-				| TCall ({ eexpr = TField(_, FStatic({ cl_path = (["java"],"NativeArray") }, { cf_name = "array" })) }, el)
+				| TCall ({ eexpr = TField(_, FStatic({ cl_path = (["java"],"NativeArray") }, { cf_name = "make" })) }, el)
 				| TArrayDecl el when t_has_type_param e.etype ->
 					let _, el = extract_tparams [] el in
 					print w "( (%s) (new %s " (t_s e.epos e.etype) (t_s e.epos (replace_type_param e.etype));
@@ -1280,7 +1280,7 @@ let configure gen =
 					) 0 el);
 					write w "}) )"
 				| TCall ({ eexpr = TLocal { v_name = "__array__" } }, el)
-				| TCall ({ eexpr = TField(_, FStatic({ cl_path = (["java"],"NativeArray") }, { cf_name = "array" })) }, el)
+				| TCall ({ eexpr = TField(_, FStatic({ cl_path = (["java"],"NativeArray") }, { cf_name = "make" })) }, el)
 				| TArrayDecl el ->
 					let _, el = extract_tparams [] el in
 					print w "new %s" (param_t_s e.epos (transform_nativearray_t e.etype));

+ 24 - 2
std/cs/NativeArray.hx

@@ -21,21 +21,43 @@
  */
 package cs;
 
+/**
+	Represents a C# fixed-size Array (`T[]`)
+**/
 extern class NativeArray<T> extends cs.system.Array implements ArrayAccess<T>
 {
-	public static function array<T>(elements:haxe.Rest<T>):NativeArray<T>;
+	/**
+		Creates a new array with the specified elements.
+
+		Usage:
+		```haxe
+		var elements = NativeArray.make(1,2,3,4,5,6);
+		```
+	 **/
+	public static function make<T>(elements:haxe.Rest<T>):NativeArray<T>;
+
+	/**
+		Allocates a new array with size `len`
+	 **/
 	public function new(len:Int):Void;
+
+	/**
+		Alias to array's `Length` property. Returns the size of the array
+	 **/
 	public var length(get,never):Int;
 
 	@:extern inline private function get_length():Int return this.Length;
 
 	static function Reverse(arr:cs.system.Array):Void;
 
+	/**
+		Returns an iterator so it's possible to use `for` with C#'s `NativeArray`
+	 **/
 	@:extern inline public function iterator():NativeArrayIterator<T>
 		return new NativeArrayIterator(this);
 }
 
-@:nativeGen private class NativeArrayIterator<T>
+@:dce private class NativeArrayIterator<T>
 {
 	public var arr(default,null):NativeArray<T>;
 	public var idx(default,null):UInt;

+ 17 - 5
std/java/NativeArray.hx

@@ -22,15 +22,27 @@
 package java;
 
 /**
- * ...
- * @author waneck
- */
-
+	Represents a java fixed-size Array (`T[]`)
+**/
 @:nativeGen extern class NativeArray<T> implements ArrayAccess<T>
 {
-	public static function array<T>(elements:haxe.Rest<T>):NativeArray<T>;
+	/**
+		Creates a new array with the specified elements.
+
+		Usage:
+		```haxe
+		var elements = NativeArray.make(1,2,3,4,5,6);
+		```
+	 **/
+	public static function make<T>(elements:haxe.Rest<T>):NativeArray<T>;
 
+	/**
+		The length of the array
+	 **/
 	public var length(default, null):Int;
 
+	/**
+		Allocates a new array with size `len`
+	 **/
 	public function new(len:Int):Void;
 }

+ 1 - 1
tests/unit/src/unit/issues/Issue3979.hx

@@ -11,7 +11,7 @@ class Issue3979 extends Test
 	{
 #if (java || cs)
 		var v = 0;
-		var nv = NativeArray.array(1,2,3,4,5,6);
+		var nv = NativeArray.make(1,2,3,4,5,6);
 		eq(nv.length,6);
 		for (val in nv)
 		{