# 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.
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
# 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.
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
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