contrib/jwrapper: add an option to not generate methods
authorAlexis Laferrière <alexis.laf@xymus.net>
Mon, 3 Aug 2015 18:20:38 +0000 (14:20 -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/code_generator.nit
contrib/jwrapper/src/jwrapper.nit

index a69414e..e81a2bb 100644 (file)
@@ -78,26 +78,29 @@ class CodeGenerator
 
                        generate_class_header(jclass)
 
-                       for id, signatures in jclass.local_intro_methods do
-                               for signature in signatures do
-                                       assert not signature.is_static
-                                       generate_method(jclass, id, id, signature.return_type, signature.params)
-                                       file_out.write "\n"
+                       if not sys.opt_no_properties.value then
+
+                               for id, signatures in jclass.local_intro_methods do
+                                       for signature in signatures do
+                                               assert not signature.is_static
+                                               generate_method(jclass, id, id, signature.return_type, signature.params)
+                                               file_out.write "\n"
+                                       end
                                end
-                       end
 
-                       # Constructors
-                       for constructor in jclass.constructors do
-                               var complex = jclass.constructors.length != 1 and constructor.params.not_empty
-                               var base_name = if complex then "from" else ""
-                               var name = jclass.nit_name_for(base_name, constructor.params, complex, false, local_only=true)
+                               # Constructors
+                               for constructor in jclass.constructors do
+                                       var complex = jclass.constructors.length != 1 and constructor.params.not_empty
+                                       var base_name = if complex then "from" else ""
+                                       var name = jclass.nit_name_for(base_name, constructor.params, complex, false, local_only=true)
 
-                               generate_constructor(jclass, constructor, name)
-                       end
+                                       generate_constructor(jclass, constructor, name)
+                               end
 
-                       # Attributes
-                       for id, attribute in jclass.attributes do if not attribute.is_static then
-                               generate_getter_setter(jclass, id, attribute)
+                               # Attributes
+                               for id, attribute in jclass.attributes do if not attribute.is_static then
+                                       generate_getter_setter(jclass, id, attribute)
+                               end
                        end
 
                        # JNI services
@@ -106,19 +109,22 @@ class CodeGenerator
                        # Close the class
                        file_out.write "end\n\n"
 
-                       # Static functions as top-level methods
-                       var static_functions_prefix = jclass.class_type.extern_name.to_snake_case
-                       for id, signatures in jclass.methods do
-                               for signature in signatures do if signature.is_static then
-                                       var nit_id = static_functions_prefix + "_" + id
-                                       generate_method(jclass, id, nit_id, signature.return_type, signature.params, is_static=true)
-                                       file_out.write "\n"
+                       if not sys.opt_no_properties.value then
+
+                               # Static functions as top-level methods
+                               var static_functions_prefix = jclass.class_type.extern_name.to_snake_case
+                               for id, signatures in jclass.methods do
+                                       for signature in signatures do if signature.is_static then
+                                               var nit_id = static_functions_prefix + "_" + id
+                                               generate_method(jclass, id, nit_id, signature.return_type, signature.params, is_static=true)
+                                               file_out.write "\n"
+                                       end
                                end
-                       end
 
-                       # Static attributes as top-level getters and setters
-                       for id, attribute in jclass.attributes do if attribute.is_static then
-                               generate_getter_setter(jclass, id, attribute)
+                               # Static attributes as top-level getters and setters
+                               for id, attribute in jclass.attributes do if attribute.is_static then
+                                       generate_getter_setter(jclass, id, attribute)
+                               end
                        end
 
                        # Primitive arrays
@@ -425,6 +431,9 @@ redef class Sys
        #
        # Used by `JavaClass::nit_name_for` with static properties.
        private var top_level_used_names = new HashSet[String]
+
+       # Option to _not_ generate properties (static or from classes)
+       var opt_no_properties = new OptionBool("Do not wrap properties, only classes and basic services", "-n", "--no-properties")
 end
 
 redef class String
index 22810fa..847f121 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_load_models, 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_no_properties, opt_verbose, opt_help)
 opts.parse args
 
 if opts.errors.not_empty or opts.rest.is_empty or opt_help.value then