From: Alexis Laferrière Date: Wed, 29 Jul 2015 12:52:40 +0000 (-0400) Subject: contrib/jwrapper: use declared upper bounds to set extern parameters types X-Git-Tag: v0.7.7~2^2~10 X-Git-Url: http://nitlanguage.org contrib/jwrapper: use declared upper bounds to set extern parameters types Signed-off-by: Alexis Laferrière --- diff --git a/contrib/jwrapper/src/javap_visitor.nit b/contrib/jwrapper/src/javap_visitor.nit index 899930d..fe81c88 100644 --- a/contrib/jwrapper/src/javap_visitor.nit +++ b/contrib/jwrapper/src/javap_visitor.nit @@ -175,7 +175,6 @@ redef class Nbase_type private fun to_java_type: JavaType do # By default, everything is bound by object - # TODO use a more precise bound var jtype = new JavaType jtype.identifier.add_all(["java", "lang", "object"]) return jtype @@ -215,6 +214,20 @@ redef class Nbase_type_extends redef fun to_java_type do return n_generic_identifier.to_java_type end +redef class Nbase_type_super + redef fun to_java_type + do + var bounds = n_type_bound.to_a + + # Java use more than one lower bound, + # it can't be translated statically to Nit, + # so we use the only the first one. + # This may cause problems on complex generic types, + # but these cases can be handled manually. + return bounds.first + end +end + redef class Ngeneric_identifier private fun to_java_type: JavaType is abstract end @@ -311,3 +324,21 @@ redef class Nodes return false end end + +redef class Ntype_bound + # Get the types composing this bound + private fun to_a: Array[JavaType] is abstract +end + +redef class Ntype_bound_head + redef fun to_a do return [n_full_class_name.to_java_type] +end + +redef class Ntype_bound_tail + redef fun to_a + do + var a = n_type_bound.to_a + a.add n_full_class_name.to_java_type + return a + end +end