Ver Fonte

try with Integer

Simon Krajewski há 9 meses atrás
pai
commit
697ae85683

+ 1 - 0
src/codegen/javaModern.ml

@@ -677,6 +677,7 @@ module SignatureConverter = struct
 		| TObject ( (["java";"lang"], "Object"), [] ) -> mk_type_path ([], "Dynamic") [] p
 		| TObject ( (["java";"lang"], "String"), [] ) -> mk_type_path (["std"], "String") [] p
 		| TObject ( (["java";"lang"], "Enum"), [_] ) -> mk_type_path ([], "EnumValue") [] p
+		| TObject ( (["java";"lang"], "Integer"), [] ) -> mk_type_path (["jvm";"lang"], "Integer") [] p
 		| TObject ( path, [] ) ->
 			mk_type_path path [] p
 		| TObject ( path, args ) -> mk_type_path path (List.map (convert_arg ctx p) args) p

+ 0 - 83
std/java/lang/Integer.hx

@@ -1,83 +0,0 @@
-/*
- * Copyright (C)2005-2019 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-package java.lang;
-
-private typedef String = std.String; // TODO: #11830
-
-@:native("") // make sure the generator won't see this
-@:transitive
-@:forwardStatics
-@:forward abstract Integer(IntegerClass) from IntegerClass to IntegerClass {
-	@:to extern inline public function toInt():Int
-		return this.intValue();
-
-	@:from extern inline public static function fromInt(b:Int):Integer
-		return IntegerClass.valueOf(b);
-}
-
-@:native("java.lang.Integer") extern class IntegerClass extends Number implements Comparable<Integer> {
-	@:overload function new(param1:Int):Void;
-	@:overload @:throws("java.lang.NumberFormatException") function new(param1:String):Void;
-	@:overload function compareTo(param1:Integer):Int;
-	@:overload function compareTo(param1:Dynamic):Int;
-	@:overload function equals(param1:Dynamic):Bool;
-	@:overload function hashCode():Int;
-	@:overload function toString():String;
-	static final MAX_VALUE:Int;
-	static final MIN_VALUE:Int;
-	static final SIZE:Int;
-	static final TYPE:Class<Integer>;
-	@:overload static function bitCount(param1:Int):Int;
-	@:overload static function compare(param1:Int, param2:Int):Int;
-	@:overload @:throws("java.lang.NumberFormatException") static function decode(param1:String):Integer;
-	@:overload static function getInteger(param1:String):Integer;
-	@:overload static function getInteger(param1:String, param2:Integer):Integer;
-	@:overload static function getInteger(param1:String, param2:Int):Integer;
-	@:overload static function highestOneBit(param1:Int):Int;
-	@:overload static function lowestOneBit(param1:Int):Int;
-	@:overload static function numberOfLeadingZeros(param1:Int):Int;
-	@:overload static function numberOfTrailingZeros(param1:Int):Int;
-	@:overload @:throws("java.lang.NumberFormatException") static function parseInt(param1:String, param2:Int):Int;
-	@:overload @:throws("java.lang.NumberFormatException") static function parseInt(param1:String):Int;
-	@:overload static function reverse(param1:Int):Int;
-	@:overload static function reverseBytes(param1:Int):Int;
-	@:overload static function rotateLeft(param1:Int, param2:Int):Int;
-	@:overload static function rotateRight(param1:Int, param2:Int):Int;
-	@:overload static function signum(param1:Int):Int;
-	@:overload static function toBinaryString(param1:Int):String;
-	@:overload static function toHexString(param1:Int):String;
-	@:overload static function toOctalString(param1:Int):String;
-	@:native("toString") @:overload static function _toString(param1:Int, param2:Int):String;
-	@:native("toString") @:overload static function _toString(param1:Int):String;
-	@:overload static function valueOf(param1:Int):Integer;
-	@:overload @:throws("java.lang.NumberFormatException") static function valueOf(param1:String, param2:Int):Integer;
-	@:overload @:throws("java.lang.NumberFormatException") static function valueOf(param1:String):Integer;
-
-	function doubleValue():Float;
-	function floatValue():Single;
-	function intValue():Int;
-	function longValue():haxe.Int64;
-}
-
-@:realPath("java.lang.Integer_IntegerCache") @:javaNative @:native("java.lang.Integer$IntegerCache") @:javaCanonical("java.lang",
-	"Integer.IntegerCache") extern class Integer_IntegerCache {}

+ 18 - 18
std/jvm/Jvm.hx

@@ -156,7 +156,7 @@ class Jvm {
 				callArgs[i] = args[i];
 				continue;
 			}
-			if (arg == (cast java.lang.Double.DoubleClass) && argType == cast java.lang.Integer.IntegerClass) {
+			if (arg == (cast java.lang.Double.DoubleClass) && argType == cast java.lang.Integer) {
 				callArgs[i] = numberToDouble(args[i]);
 			} else {
 				return None;
@@ -275,7 +275,7 @@ class Jvm {
 		}
 		// TODO: other basic types
 		return if (c == cast Int) {
-			cast java.lang.Integer.IntegerClass;
+			cast java.lang.Integer;
 		} else if (c == cast Float) {
 			cast java.lang.Double.DoubleClass;
 		} else if (c == cast Bool) {
@@ -437,7 +437,7 @@ class Jvm {
 		} else if (instanceof(obj, java.lang.Double.DoubleClass)) {
 			var n:java.lang.Number = cast obj;
 			if (n.doubleValue() == n.intValue()) {
-				return java.lang.Integer.IntegerClass.valueOf(n.intValue()).toString();
+				return java.lang.Integer.valueOf(n.intValue()).toString();
 			}
 			return obj.toString();
 		} else {
@@ -461,7 +461,7 @@ class Jvm {
 		if (instanceof(a, java.lang.Long.LongClass) || instanceof(b, java.lang.Long.LongClass)) {
 			return toLong(a) + toLong(b);
 		}
-		if (instanceof(a, java.lang.Integer.IntegerClass) || instanceof(b, java.lang.Integer.IntegerClass)) {
+		if (instanceof(a, java.lang.Integer) || instanceof(b, java.lang.Integer)) {
 			return toInt(a) + toInt(b);
 		}
 		throw "Invalid operation";
@@ -474,7 +474,7 @@ class Jvm {
 		if (instanceof(a, java.lang.Long.LongClass) || instanceof(b, java.lang.Long.LongClass)) {
 			return toLong(a) - toLong(b);
 		}
-		if (instanceof(a, java.lang.Integer.IntegerClass) || instanceof(b, java.lang.Integer.IntegerClass)) {
+		if (instanceof(a, java.lang.Integer) || instanceof(b, java.lang.Integer)) {
 			return toInt(a) - toInt(b);
 		}
 		throw "Invalid operation";
@@ -487,7 +487,7 @@ class Jvm {
 		if (instanceof(a, java.lang.Long.LongClass) || instanceof(b, java.lang.Long.LongClass)) {
 			return toLong(a) * toLong(b);
 		}
-		if (instanceof(a, java.lang.Integer.IntegerClass) || instanceof(b, java.lang.Integer.IntegerClass)) {
+		if (instanceof(a, java.lang.Integer) || instanceof(b, java.lang.Integer)) {
 			return toInt(a) * toInt(b);
 		}
 		throw "Invalid operation";
@@ -500,7 +500,7 @@ class Jvm {
 		if (instanceof(a, java.lang.Long.LongClass) || instanceof(b, java.lang.Long.LongClass)) {
 			return toLong(a) / toLong(b);
 		}
-		if (instanceof(a, java.lang.Integer.IntegerClass) || instanceof(b, java.lang.Integer.IntegerClass)) {
+		if (instanceof(a, java.lang.Integer) || instanceof(b, java.lang.Integer)) {
 			return toInt(a) / toInt(b);
 		}
 		throw "Invalid operation";
@@ -513,7 +513,7 @@ class Jvm {
 		if (instanceof(a, java.lang.Long.LongClass) || instanceof(b, java.lang.Long.LongClass)) {
 			return toLong(a) % toLong(b);
 		}
-		if (instanceof(a, java.lang.Integer.IntegerClass) || instanceof(b, java.lang.Integer.IntegerClass)) {
+		if (instanceof(a, java.lang.Integer) || instanceof(b, java.lang.Integer)) {
 			return toInt(a) % toInt(b);
 		}
 		throw "Invalid operation";
@@ -523,7 +523,7 @@ class Jvm {
 		if (instanceof(a, java.lang.Long.LongClass) || instanceof(b, java.lang.Long.LongClass)) {
 			return toLong(a) & toLong(b);
 		}
-		if (instanceof(a, java.lang.Integer.IntegerClass) || instanceof(b, java.lang.Integer.IntegerClass)) {
+		if (instanceof(a, java.lang.Integer) || instanceof(b, java.lang.Integer)) {
 			return toInt(a) & toInt(b);
 		}
 		throw "Invalid operation";
@@ -533,7 +533,7 @@ class Jvm {
 		if (instanceof(a, java.lang.Long.LongClass) || instanceof(b, java.lang.Long.LongClass)) {
 			return toLong(a) | toLong(b);
 		}
-		if (instanceof(a, java.lang.Integer.IntegerClass) || instanceof(b, java.lang.Integer.IntegerClass)) {
+		if (instanceof(a, java.lang.Integer) || instanceof(b, java.lang.Integer)) {
 			return toInt(a) | toInt(b);
 		}
 		throw "Invalid operation";
@@ -543,7 +543,7 @@ class Jvm {
 		if (instanceof(a, java.lang.Long.LongClass) || instanceof(b, java.lang.Long.LongClass)) {
 			return toLong(a) ^ toLong(b);
 		}
-		if (instanceof(a, java.lang.Integer.IntegerClass) || instanceof(b, java.lang.Integer.IntegerClass)) {
+		if (instanceof(a, java.lang.Integer) || instanceof(b, java.lang.Integer)) {
 			return toInt(a) ^ toInt(b);
 		}
 		throw "Invalid operation";
@@ -553,7 +553,7 @@ class Jvm {
 		if (instanceof(a, java.lang.Long.LongClass) || instanceof(b, java.lang.Long.LongClass)) {
 			return toLong(a) << toInt(b);
 		}
-		if (instanceof(a, java.lang.Integer.IntegerClass) || instanceof(b, java.lang.Integer.IntegerClass)) {
+		if (instanceof(a, java.lang.Integer) || instanceof(b, java.lang.Integer)) {
 			return toInt(a) << toInt(b);
 		}
 		throw "Invalid operation";
@@ -563,7 +563,7 @@ class Jvm {
 		if (instanceof(a, java.lang.Long.LongClass) || instanceof(b, java.lang.Long.LongClass)) {
 			return toLong(a) >> toInt(b);
 		}
-		if (instanceof(a, java.lang.Integer.IntegerClass) || instanceof(b, java.lang.Integer.IntegerClass)) {
+		if (instanceof(a, java.lang.Integer) || instanceof(b, java.lang.Integer)) {
 			return toInt(a) >> toInt(b);
 		}
 		throw "Invalid operation";
@@ -573,7 +573,7 @@ class Jvm {
 		if (instanceof(a, java.lang.Long.LongClass) || instanceof(b, java.lang.Long.LongClass)) {
 			return toLong(a) >>> toInt(b);
 		}
-		if (instanceof(a, java.lang.Integer.IntegerClass) || instanceof(b, java.lang.Integer.IntegerClass)) {
+		if (instanceof(a, java.lang.Integer) || instanceof(b, java.lang.Integer)) {
 			return toInt(a) >>> toInt(b);
 		}
 		throw "Invalid operation";
@@ -586,7 +586,7 @@ class Jvm {
 		if (instanceof(a, java.lang.Long.LongClass)) {
 			return toLong(a) + 1.;
 		}
-		if (instanceof(a, java.lang.Integer.IntegerClass)) {
+		if (instanceof(a, java.lang.Integer)) {
 			return toInt(a) + 1;
 		}
 		throw "Invalid operation";
@@ -599,7 +599,7 @@ class Jvm {
 		if (instanceof(a, java.lang.Long.LongClass)) {
 			return toLong(a) - 1.;
 		}
-		if (instanceof(a, java.lang.Integer.IntegerClass)) {
+		if (instanceof(a, java.lang.Integer)) {
 			return toInt(a) - 1;
 		}
 		throw "Invalid operation";
@@ -612,7 +612,7 @@ class Jvm {
 		if (instanceof(a, java.lang.Long.LongClass)) {
 			return -toLong(a);
 		}
-		if (instanceof(a, java.lang.Integer.IntegerClass)) {
+		if (instanceof(a, java.lang.Integer)) {
 			return -toInt(a);
 		}
 		throw "Invalid operation";
@@ -622,7 +622,7 @@ class Jvm {
 		if (instanceof(a, java.lang.Long.LongClass)) {
 			return ~toLong(a);
 		}
-		if (instanceof(a, java.lang.Integer.IntegerClass)) {
+		if (instanceof(a, java.lang.Integer)) {
 			return ~toInt(a);
 		}
 		throw "Invalid operation";

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

@@ -46,7 +46,7 @@ class Std {
 		if (clt == cast java.lang.Double.DoubleClass) {
 			// Haxe semantics: any number is assignable to Float
 			clt = cast java.lang.Number;
-		} else if (clt == cast java.lang.Integer.IntegerClass) {
+		} else if (clt == cast java.lang.Integer) {
 			if (!Jvm.instanceof(v, java.lang.Number)) {
 				return false;
 			}

+ 36 - 0
std/jvm/lang/Integer.hx

@@ -0,0 +1,36 @@
+/*
+ * Copyright (C)2005-2019 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+package jvm.lang;
+
+import java.lang.Integer as NativeInteger;
+
+@:transitive
+@:forwardStatics
+@:forward
+abstract Integer(NativeInteger) from NativeInteger to NativeInteger {
+	@:to extern inline public function toInt():Int
+		return this.intValue();
+
+	@:from extern inline public static function fromInt(b:Int):Integer
+		return NativeInteger.valueOf(b);
+}

+ 3 - 3
tests/unit/src/unit/TestJava.hx

@@ -50,10 +50,10 @@ class TestJava extends Test {
 		eq(cl.boolTest2(true), 1);
 		eq(cl.boolTest2(false), 0);
 
-		var i:java.lang.Integer = null;
+		var i:jvm.lang.Integer = null;
 		eq(cl.intTest1(i), 100);
-		eq(cl.intTest1(cast(-1, java.lang.Integer)), -1);
-		eq(cl.intTest1(cast(1000, java.lang.Integer)), 1000);
+		eq(cl.intTest1(cast(-1, jvm.lang.Integer)), -1);
+		eq(cl.intTest1(cast(1000, jvm.lang.Integer)), 1000);
 		i = -1;
 		eq(cl.intTest1(i), -1);
 		i = null;