javaparse 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,24 @@
1
+ module JavaParse
2
+
3
+ module LineCounter
4
+
5
+ JAVA_COMMENTS_RE = /^\s*\/\/|^\s*\/\*|^\s*\*/
6
+
7
+ def count_lines
8
+ @loc, @bloc, @cloc, @all_lines = 0, 0, 0, 0
9
+ @content.each_line { |line|
10
+ @all_lines += 1
11
+ if line.strip.empty?
12
+ @bloc += 1
13
+ elsif JAVA_COMMENTS_RE.match(line)
14
+ @cloc += 1
15
+ else
16
+ @loc += 1
17
+ end
18
+ }
19
+ [@loc, @cloc, @bloc, @all_lines]
20
+ end
21
+
22
+ end
23
+
24
+ end
@@ -0,0 +1,54 @@
1
+ module JavaParse
2
+
3
+ class MethodMatch
4
+
5
+ attr_reader :signature, :method_text
6
+
7
+ def initialize(signature, method_text)
8
+ @signature = signature
9
+ @method_text = method_text
10
+ end
11
+
12
+ def inner_lines_count
13
+ @method_text.lines.inject(-2){|sum| sum + 1}
14
+ end
15
+
16
+ end
17
+
18
+ module MethodGraber
19
+
20
+ def grab_methods(clazz_body)
21
+ methods = []
22
+ method_matches = match_method_bodies(clazz_body.content)
23
+ method_matches.each { |match|
24
+ methods << JavaMethod.new(unit_name, match.signature, match.inner_lines_count )
25
+ }
26
+ methods
27
+ end
28
+
29
+ def match_method_bodies(text)
30
+ method_matches = []
31
+ while match = match_method_signature(text)
32
+ rtext = text[match.begin(0)..-1]
33
+ method_text = ""
34
+ open_brackets_counter = 0
35
+ rtext.each_char.with_index { |c, i|
36
+ open_brackets_counter = open_brackets_counter + 1 if '{' == c
37
+ open_brackets_counter = open_brackets_counter - 1 if '}' == c
38
+ method_text << c
39
+ break if ('}' == c && open_brackets_counter == 0)
40
+ }
41
+ method_matches << MethodMatch.new(match[0], method_text)
42
+ end_of_method_index = match.begin(0) + method_text.length
43
+ text = text[end_of_method_index..-1]
44
+ end
45
+ method_matches
46
+ end
47
+
48
+ def match_method_signature(text)
49
+ text.match(/(?:public|private|protected).*\(.*\)\s*({$)/)
50
+ end
51
+
52
+ end
53
+
54
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: javaparse
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -21,6 +21,8 @@ files:
21
21
  - lib/javaparse/java_section.rb
22
22
  - lib/javaparse/java_unit.rb
23
23
  - lib/javaparse/java_files.rb
24
+ - lib/javaparse/line_counter.rb
25
+ - lib/javaparse/method_graber.rb
24
26
  homepage:
25
27
  licenses: []
26
28
  post_install_message: