contrib/jwrapper: use declared upper bounds to set extern parameters types
authorAlexis Laferrière <alexis.laf@xymus.net>
Wed, 29 Jul 2015 12:52:40 +0000 (08:52 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Wed, 29 Jul 2015 19:08:58 +0000 (15:08 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

contrib/jwrapper/src/javap_visitor.nit

index 899930d..fe81c88 100644 (file)
@@ -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