javaparse 0.0.2 → 0.0.3

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
+ class JavaSection
4
+
5
+ def initialize(section_text)
6
+ @content = section_text
7
+ end
8
+
9
+ def javadoc
10
+ @javadoc ||= parse_javadoc
11
+ end
12
+
13
+ private
14
+
15
+ def parse_javadoc
16
+ javadoc_match = /\/\*\*(.+)\*\//m.match(@content)
17
+ @javadoc = javadoc_match[1][1...-1].each_line.map {
18
+ |l| l.gsub("*", '').gsub(/\*|^ +| +$/, '')
19
+ }.join if javadoc_match
20
+ end
21
+
22
+ end
23
+
24
+ end
@@ -0,0 +1,57 @@
1
+ module JavaParse
2
+
3
+ class JavaUnit
4
+
5
+ attr_reader :body, :head
6
+
7
+ def initialize(java_file_path)
8
+ @file_path = java_file_path
9
+ @unit_name = File.basename(java_file_path, ".java")
10
+ @content = File.open(java_file_path) { |file| file.read }
11
+ validate_unit
12
+ @head, @body = partition_unit
13
+ end
14
+
15
+ def method_blocks
16
+ return @body.split("}")[0...-1] if (clazz? or enum?)
17
+ return @body.split(";")[0...-1] if (interface?)
18
+ end
19
+
20
+ def clazz?
21
+ unit_declaration_line.include? 'class'
22
+ end
23
+
24
+ def interface?
25
+ unit_declaration_line.include? 'interface'
26
+ end
27
+
28
+ def enum?
29
+ unit_declaration_line.include? 'enum'
30
+ end
31
+
32
+ private
33
+
34
+ def validate_unit
35
+ raise RuntimeError, "Mismatch between filename and declared name for #{@file_path}" unless unit_declaration_line
36
+ end
37
+
38
+ def unit_declaration_line
39
+ declaration_line_match = /^.*(?<=class|enum|interface)\s*#{@unit_name}.*$/.match(@content)
40
+ declaration_line_match[0] unless declaration_line_match.nil?
41
+ end
42
+
43
+ def partition_unit
44
+ head, match, body = @content.partition(unit_declaration_line)
45
+ head = removing_above_package(head)
46
+ [head.strip!, body.strip!.chomp!("}")]
47
+ end
48
+
49
+ def removing_above_package(text)
50
+ text.each_line.drop_while {|line|
51
+ not line.strip.start_with?("package")
52
+ }.join
53
+ end
54
+
55
+ end
56
+
57
+ 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.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -18,6 +18,8 @@ extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
20
  - lib/javaparse.rb
21
+ - lib/javaparse/java_section.rb
22
+ - lib/javaparse/java_unit.rb
21
23
  homepage:
22
24
  licenses: []
23
25
  post_install_message: