Module: JavaParse::MethodGraber
- Included in:
- JavaUnit
- Defined in:
- lib/javaparse/method_graber.rb
Instance Method Summary collapse
- #grab_methods(clazz_body) ⇒ Object
- #match_method_bodies(text) ⇒ Object
- #match_method_signature(text) ⇒ Object
Instance Method Details
#grab_methods(clazz_body) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/javaparse/method_graber.rb', line 20 def grab_methods(clazz_body) methods = [] method_matches = match_method_bodies(clazz_body.content) method_matches.each { |match| methods << JavaMethod.new(unit_name, match.signature, match.inner_lines_count ) } methods end |
#match_method_bodies(text) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/javaparse/method_graber.rb', line 29 def match_method_bodies(text) method_matches = [] while match = match_method_signature(text) rtext = text[match.begin(0)..-1] method_text = "" open_brackets_counter = 0 rtext.each_char.with_index { |c, i| open_brackets_counter = open_brackets_counter + 1 if '{' == c open_brackets_counter = open_brackets_counter - 1 if '}' == c method_text << c break if ('}' == c && open_brackets_counter == 0) } method_matches << MethodMatch.new(match[0], method_text) end_of_method_index = match.begin(0) + method_text.length text = text[end_of_method_index..-1] end method_matches end |
#match_method_signature(text) ⇒ Object
48 49 50 |
# File 'lib/javaparse/method_graber.rb', line 48 def match_method_signature(text) text.match(/(?:public|private|protected).*\(.*\).*({$)/) end |