# 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.
import jtype_converter
intrude import model
+# Visitor of the AST generated from javap output
class JavaVisitor
super Visitor
var converter: JavaTypeConverter
- var java_class = new JavaClass
+ # Model of all the analyzed classes
+ var model: JavaModel
+
+ var java_class: JavaClass is noinit
+
var declaration_type: nullable String = null
var declaration_element: nullable String = null
- var class_type: JavaType
+ var class_type: JavaType is noinit
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
if v.declaration_element == "id" then
v.method_id = self.text
else if v.declaration_element == "return_type" then
- if self.text == "void" then
+ if self.text == "void" then
v.method_return_type.is_void = true
else if v.is_generic_param then
v.method_return_type.generic_params[v.gen_params_index].identifier.add(self.text)
end
# Primitive array node
-redef class N_39d_91d_93d_39d
+redef class Nbrackets
redef fun accept_visitor(v)
do
if v.declaration_type == "variable" then
redef class Nclass_declaration
redef fun accept_visitor(v)
do
+ v.java_class = new JavaClass
+ v.model.classes.add v.java_class
+ v.class_type = new JavaType(v.converter)
+
v.declaration_type = "class_header"
v.declaration_element = "id"
super
# #
# Method declaration
-redef class Nmethod_declaration
+redef class Nproperty_declaration_method
redef fun accept_visitor(v)
do
v.declaration_type = "method"
+ v.declaration_element = null
super
v.declaration_type = null
if v.method_return_type.has_unresolved_types then v.method_return_type.resolve_types(v.generic_map)
- v.java_class.add_method(v.method_id, v.method_return_type, v.method_params)
+
+ var method = new JavaMethod(v.method_return_type, v.method_params.clone)
+ v.java_class.methods[v.method_id].add method
v.method_params.clear
v.method_id = ""
end
# Constructor declaration
-redef class Nconstructor_declaration
+redef class Nproperty_declaration_constructor
redef fun accept_visitor(v)
do
v.declaration_type = "constructor"
end
# Variable property declaration
-redef class Nvariable_declaration
+redef class Nproperty_declaration_attribute
redef fun accept_visitor(v)
do
v.declaration_type = "variable"
end
# Static property declaration
-redef class Nstatic_declaration
+redef class Nproperty_declaration_static
redef fun accept_visitor(v)
do
v.declaration_type = "static"
end
# Identifier of a variable
-redef class Nvariable_id
+redef class Nattribute_id
redef fun accept_visitor(v)
do
v.declaration_element = "id"