From a8ca268de583f9a0dc3f4f7aa969a766c4355b90 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20Laferri=C3=A8re?= Date: Mon, 26 Jan 2015 11:21:44 -0500 Subject: [PATCH] contrib/jwrapper: refactor some duplicated code MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Alexis Laferrière --- contrib/jwrapper/src/javap_visitor.nit | 136 ++++++-------------------------- 1 file changed, 24 insertions(+), 112 deletions(-) diff --git a/contrib/jwrapper/src/javap_visitor.nit b/contrib/jwrapper/src/javap_visitor.nit index 9ee4190..64415a4 100644 --- a/contrib/jwrapper/src/javap_visitor.nit +++ b/contrib/jwrapper/src/javap_visitor.nit @@ -61,6 +61,22 @@ class JavaVisitor 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 declaration_type == "variable" then + if declaration_element == "type" then + variable_type.identifier.add(token.text) + end + else if declaration_type == "method" then + if declaration_element == "return_type" then + method_return_type.identifier.add(token.text) + else if declaration_element == "parameter_list" then + method_params[param_index].identifier.add(token.text) + end + end + end end redef class Node @@ -162,139 +178,35 @@ redef class N_39d_91d_93d_39d end redef class N_39dchar_39d - redef fun accept_visitor(v) - do - if v.declaration_type == "variable" then - if v.declaration_element == "type" then - v.variable_type.identifier.add(self.text) - end - else if v.declaration_type == "method" then - if v.declaration_element == "return_type" then - v.method_return_type.identifier.add(self.text) - else if v.declaration_element == "parameter_list" then - v.method_params[v.param_index].identifier.add(self.text) - end - end - end + redef fun accept_visitor(v) do v.add_identifier self end redef class N_39dboolean_39d - redef fun accept_visitor(v) - do - if v.declaration_type == "variable" then - if v.declaration_element == "type" then - v.variable_type.identifier.add(self.text) - end - else if v.declaration_type == "method" then - if v.declaration_element == "return_type" then - v.method_return_type.identifier.add(self.text) - else if v.declaration_element == "parameter_list" then - v.method_params[v.param_index].identifier.add(self.text) - end - end - end + redef fun accept_visitor(v) do v.add_identifier self end redef class N_39dfloat_39d - redef fun accept_visitor(v) - do - if v.declaration_type == "variable" then - if v.declaration_element == "type" then - v.variable_type.identifier.add(self.text) - end - else if v.declaration_type == "method" then - if v.declaration_element == "return_type" then - v.method_return_type.identifier.add(self.text) - else if v.declaration_element == "parameter_list" then - v.method_params[v.param_index].identifier.add(self.text) - end - end - end + redef fun accept_visitor(v) do v.add_identifier self end redef class N_39ddouble_39d - redef fun accept_visitor(v) - do - if v.declaration_type == "variable" then - if v.declaration_element == "type" then - v.variable_type.identifier.add(self.text) - end - else if v.declaration_type == "method" then - if v.declaration_element == "return_type" then - v.method_return_type.identifier.add(self.text) - else if v.declaration_element == "parameter_list" then - v.method_params[v.param_index].identifier.add(self.text) - end - end - end + redef fun accept_visitor(v) do v.add_identifier self end redef class N_39dbyte_39d - redef fun accept_visitor(v) - do - if v.declaration_type == "variable" then - if v.declaration_element == "type" then - v.variable_type.identifier.add(self.text) - end - else if v.declaration_type == "method" then - if v.declaration_element == "return_type" then - v.method_return_type.identifier.add(self.text) - else if v.declaration_element == "parameter_list" then - v.method_params[v.param_index].identifier.add(self.text) - end - end - end + redef fun accept_visitor(v) do v.add_identifier self end redef class N_39dshort_39d - redef fun accept_visitor(v) - do - if v.declaration_type == "variable" then - if v.declaration_element == "type" then - v.variable_type.identifier.add(self.text) - end - else if v.declaration_type == "method" then - if v.declaration_element == "return_type" then - v.method_return_type.identifier.add(self.text) - else if v.declaration_element == "parameter_list" then - v.method_params[v.param_index].identifier.add(self.text) - end - end - end + redef fun accept_visitor(v) do v.add_identifier self end redef class N_39dint_39d - redef fun accept_visitor(v) - do - if v.declaration_type == "variable" then - if v.declaration_element == "type" then - v.variable_type.identifier.add(self.text) - end - else if v.declaration_type == "method" then - if v.declaration_element == "return_type" then - v.method_return_type.identifier.add(self.text) - else if v.declaration_element == "parameter_list" then - v.method_params[v.param_index].identifier.add(self.text) - end - end - end + redef fun accept_visitor(v) do v.add_identifier self end redef class N_39dlong_39d - redef fun accept_visitor(v) - do - if v.declaration_type == "variable" then - if v.declaration_element == "type" then - v.variable_type.identifier.add(self.text) - end - else if v.declaration_type == "method" then - if v.declaration_element == "return_type" then - v.method_return_type.identifier.add(self.text) - else if v.declaration_element == "parameter_list" then - v.method_params[v.param_index].identifier.add(self.text) - end - end - end + redef fun accept_visitor(v) do v.add_identifier self end # # -- 1.7.9.5