Class: CoderCompanion::Java::MethodDefinition

Inherits:
Treetop::Runtime::SyntaxNode
  • Object
show all
Defined in:
lib/codercompanion/java/java.rb

Instance Method Summary collapse

Instance Method Details

#buildObject



229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# File 'lib/codercompanion/java/java.rb', line 229

def build
    class_method = false
    params = []
    privacy = ''
    method_text = ''
    return_type = ''
    qualifiers = []
    elements.each do |e|
        if e.respond_to? :qualifiers
            qualifiers = e.elements[0].text_value
            privacy = CoderCompanion::Java.extract_privacy(qualifiers)
            if (CoderCompanion::Java.has_static_qualifier(qualifiers) )
                class_method = true
            end
        end
        return_type = e.text_value if e.respond_to? :return_type
        method_text = e.text_value if e.respond_to? :method_defined
        if e.respond_to? :method_defined
            e.elements[0].elements.each do |f|
                s_params = CoderCompanion::Java.remove_generics(f.text_value) if f.respond_to? :params
                if s_params
                    s_params = s_params.gsub(/@[^\s]+\s+/, '') #Remove annotation for parameters
                    s_params = s_params.gsub(/\sfinal\s/, '') #Remove final keyword
                    s_params = s_params.gsub(/\.\.\./, '') #Remove the ellipsis at the end '...'
                    pre_params = s_params.split(/\s*\,\s*/) 
                    pre_params.each do |p|
                        val_arr = p.split(/\s+/)
                        params.push({:type => val_arr[0], :value => val_arr[1]})
                    end
                end
            end
        end
    end
    return [{:type => 'method_definition', :value => method_text.gsub(/[\s]+/, ' '), :params => params, :return_type => return_type, :privacy => privacy, :class_method => class_method}]
end