X-Git-Url: http://nitlanguage.org diff --git a/contrib/jwrapper/src/jwrapper.nit b/contrib/jwrapper/src/jwrapper.nit index aeba9c3..bf25f1e 100644 --- a/contrib/jwrapper/src/jwrapper.nit +++ b/contrib/jwrapper/src/jwrapper.nit @@ -41,9 +41,10 @@ var opts = new OptionContext var opt_unknown = new OptionEnum(["comment", "stub", "ignore"], "How to deal with unknown types", 0, "-u") var opt_verbose = new OptionCount("Verbosity", "-v") 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_verbose, opt_help) +opts.add_option(opt_output, opt_unknown, opt_extern_class_prefix, opt_libs, opt_regex, opt_cast_objects, opt_arrays, opt_save_model, 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 @@ -65,6 +66,17 @@ if not "javap".program_is_in_path then exit 1 end +var regex = null +var regex_code = opt_regex.value +if regex_code != null then + regex = regex_code.to_re + var error = regex.compile + if error != null then + print_error "Regex Error: {error}" + exit 1 + end +end + # List of bytecode Java classes and javap output files var class_files = new Array[String] var javap_files = new Array[String] @@ -78,9 +90,11 @@ for input in opts.rest do else if ext == "javap" then javap_files.add input else if ext == "jar" then - var out_dir = "tmp" clock.lapse + var out_dir = "tmp" + if not out_dir.file_exists then out_dir.mkdir + if opt_verbose.value > 0 then print "# Extracting {input}" # Extract all files @@ -97,6 +111,10 @@ for input in opts.rest do javap.wait for path in output.split("\n") do if path.file_extension == "class" then + + # Filter out the classes that do not answer to the Regex + if regex != null and not path.has(regex) then continue + class_files.add out_dir / path end end @@ -176,15 +194,39 @@ var visitor = new JavaVisitor(model) visitor.enter_visit root_node sys.perfs["core model"].add clock.lapse +# Resolve types +model.resolve_types +sys.perfs["core resolve"].add clock.lapse + +# Build class hierarchy +model.build_class_hierarchy +sys.perfs["core hierarchy"].add clock.lapse + if opt_verbose.value > 0 then print "# Generating Nit code" +# Generate the Nit module var use_comment = opt_unknown.value == 0 var use_stub = opt_unknown.value == 1 var generator = new CodeGenerator(out_file, model, use_comment, use_stub) generator.generate sys.perfs["code generator"].add clock.lapse +# Write the model to a file, for use by subsequent passes +generator.write_model_to_file +sys.perfs["writing model"].add clock.lapse + if opt_verbose.value > 1 then print "# Performance Analysis:" print sys.perfs + + print "# {model.unknown_types.length} unknown types:" + var c = 0 + for id, ntype in model.unknown_types do + print "* {id}" + c += 1 + if c > 100 then + print "* ..." + break + end + end end