contrib/jwrapper: intro reading models from file
authorAlexis Laferrière <alexis.laf@xymus.net>
Mon, 3 Aug 2015 16:29:25 +0000 (12:29 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Wed, 5 Aug 2015 01:41:51 +0000 (21:41 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

contrib/jwrapper/src/jwrapper.nit
contrib/jwrapper/src/model.nit

index 99536d6..22810fa 100644 (file)
@@ -44,7 +44,7 @@ var opt_output = new OptionString("Output file", "-o")
 var opt_regex = new OptionString("Regex pattern to filter classes in Jar archives", "-r")
 var opt_help = new OptionBool("Show this help message", "-h", "--help")
 
-opts.add_option(opt_output, opt_unknown, opt_extern_class_prefix, opt_libs, opt_regex, opt_cast_objects, opt_arrays, opt_verbose, opt_help)
+opts.add_option(opt_output, opt_unknown, opt_extern_class_prefix, opt_libs, opt_regex, opt_cast_objects, opt_arrays, opt_load_models, opt_verbose, opt_help)
 opts.parse args
 
 if opts.errors.not_empty or opts.rest.is_empty or opt_help.value then
index 95b54c5..d2706d2 100644 (file)
@@ -252,9 +252,41 @@ end
 # Model of all the Java class analyzed in one run
 class JavaModel
 
-       # All analyzed classes
+       # Classes analyzed in this pass
        var classes = new HashMap[String, JavaClass]
 
+       # All classes, from this pass and from other passes
+       var all_classes: HashMap[String, JavaClass] is noserialize, lazy do
+               var classes = new HashMap[String, JavaClass]
+               classes.recover_with self.classes
+
+               for model_path in sys.opt_load_models.value do
+                       if not model_path.file_exists then
+                               print_error "Error: model file '{model_path}' does not exist"
+                               continue
+                       end
+
+                       var file = model_path.to_path.open_ro
+                       var d = new BinaryDeserializer(file)
+                       var model = d.deserialize
+                       file.close
+
+                       if d.errors.not_empty then
+                               print_error "Error: failed to deserialize model file '{model_path}' with: {d.errors.join(", ")}"
+                               continue
+                       end
+
+                       if not model isa JavaModel then
+                               print_error "Error: model file contained a '{if model == null then "null" else model.class_name}'"
+                               continue
+                       end
+
+                       classes.recover_with model.classes
+               end
+
+               return classes
+       end
+
        # Add a class in `classes`
        fun add_class(jclass: JavaClass)
        do
@@ -377,8 +409,7 @@ class JavaModel
 
                # Methods intro
                for java_class in linearized do
-                       var in_hierarchy = class_hierarchy[java_class]
-                       var greaters = in_hierarchy.greaters
+                       var greaters = java_class.in_hierarchy.greaters
 
                        for mid, signatures in java_class.methods do
                                for signature in signatures do
@@ -527,6 +558,9 @@ redef class Sys
 
        # Generate the primitive array version of each class up to the given depth
        var opt_arrays = new OptionInt("Depth of the primitive array for each wrapped class (default: 1)", 1, "-a")
+
+       # Generate the primitive array version of each class up to the given depth
+       var opt_load_models = new OptionArray("Saved models to search for super-classes", "-m")
 end
 
 redef abstract class Text