From 1c81c0f6d4ff642d76f1d5e2afce22daf12ed85e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20Laferri=C3=A8re?= Date: Mon, 2 Feb 2015 19:38:10 -0500 Subject: [PATCH] jwrapper: accept output files that do not look like Nit modules MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Alexis Laferrière --- contrib/jwrapper/src/code_generator.nit | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/contrib/jwrapper/src/code_generator.nit b/contrib/jwrapper/src/code_generator.nit index ed456f6..917074d 100644 --- a/contrib/jwrapper/src/code_generator.nit +++ b/contrib/jwrapper/src/code_generator.nit @@ -26,12 +26,20 @@ class CodeGenerator var file_out: OFStream var java_class: JavaClass var nb_params: Int - var module_name: String + var module_name: nullable String = null init (file_name: String, jclass: JavaClass, with_attributes, comment: Bool) do file_out = new OFStream.open(file_name) - module_name = file_name.substring(0, file_name.search(".nit").from) + + var nit_ext = ".nit" + if file_name.has_suffix(nit_ext) then + # Output file ends with .nit, we expect it to be a valid name + module_name = file_name.strip_extension(nit_ext) + + # Otherwise, it may be anything so do not declare a module + end + self.java_class = jclass self.with_attributes = with_attributes self.comment_unknown_types = comment @@ -71,7 +79,11 @@ class CodeGenerator end file_out.write(gen_licence) - file_out.write("module {module_name}\n") + + var module_name = module_name + if module_name != null then file_out.write "module {module_name}\n" + + file_out.write("\n") file_out.write(imports.join("")) file_out.write("\n") file_out.write(class_content.join("")) -- 1.7.9.5