contrib/jwrapper: update constructors of `CodeGenerator` and `JavapVisitor`
authorAlexis Laferrière <alexis.laf@xymus.net>
Sun, 19 Jul 2015 16:08:09 +0000 (12:08 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Mon, 20 Jul 2015 21:34:09 +0000 (17:34 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

contrib/jwrapper/src/code_generator.nit
contrib/jwrapper/src/javap_visitor.nit

index 2a9d16e..4497ed9 100644 (file)
@@ -1,6 +1,7 @@
 # This file is part of NIT (http://www.nitlanguage.org).
 #
 # Copyright 2014 Frédéric Vachon <fredvac@gmail.com>
+# Copyright 2015 Alexis Laferrière <alexis.laf@xymus.net>
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -21,30 +22,27 @@ intrude import model
 
 class CodeGenerator
 
-       var with_attributes: Bool
-       var comment_unknown_types: Bool
-       var file_out: FileWriter
-       var java_class: JavaClass
-       var nb_params: Int
-       var module_name: nullable String = null
+       # Path to the output file
+       var file_name: String
 
-       init (file_name: String, jclass: JavaClass, with_attributes, comment: Bool)
-       do
-               file_out = new FileWriter.open(file_name)
+       # Model of Java class being wrapped
+       var java_class: JavaClass
 
-               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)
+       # Comment out methods with unknown (unwrapped) types
+       var comment_unknown_types: Bool
 
-                       # Otherwise, it may be anything so do not declare a module
-               end
+       # Output file
+       var file_out: Writer = new FileWriter.open(file_name) is lazy, writable
 
-               self.java_class = jclass
-               self.with_attributes = with_attributes
-               self.comment_unknown_types = comment
+       # Name of the Nit module to generate
+       var module_name: nullable String is lazy do
+               if file_name.file_extension == "nit" then
+                       # Output file ends with .nit, we expect it to be a valid name
+                       return file_name.basename(".nit")
+               else return null
        end
 
+       # Generate the Nit module into `file_out`
        fun generate
        do
                var jclass = self.java_class
index acd4fdd..165dfea 100644 (file)
@@ -1,6 +1,7 @@
 # This file is part of NIT (http://www.nitlanguage.org).
 #
 # Copyright 2014 Frédéric Vachon <fredvac@gmail.com>
+# Copyright 2015 Alexis Laferrière <alexis.laf@xymus.net>
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -31,10 +32,10 @@ class JavaVisitor
        var java_class = new JavaClass
        var declaration_type: nullable String =  null
        var declaration_element: nullable String = null
-       var class_type: JavaType
+       var class_type = new JavaType(self.converter) is lazy
 
        var variable_id = ""
-       var variable_type: JavaType
+       var variable_type = new JavaType(self.converter) is lazy
 
        var is_generic_param = false
        var is_generic_id = false
@@ -47,21 +48,12 @@ class JavaVisitor
        var is_primitive_array = false
 
        var method_id = ""
-       var method_return_type: JavaType
+       var method_return_type = new JavaType(self.converter) is lazy
        var method_params = new Array[JavaType]
        var param_index = 0
 
        redef fun visit(n) do n.accept_visitor(self)
 
-       init(converter: JavaTypeConverter)
-       do
-               self.converter = converter
-               self.class_type = new JavaType(self.converter)
-               self.method_return_type = new JavaType(self.converter)
-               self.variable_type = new JavaType(self.converter)
-               super
-       end
-
        # Add the identifier from `token` to the current context
        fun add_identifier(token: NToken)
        do