Class: JavaParse::JavaUnit
- Inherits:
-
Object
- Object
- JavaParse::JavaUnit
- Includes:
- LineCounter, MethodGraber
- Defined in:
- lib/javaparse/java_unit.rb
Constant Summary
Constants included from LineCounter
Instance Attribute Summary collapse
-
#all_lines ⇒ Object
readonly
Returns the value of attribute all_lines.
-
#bloc ⇒ Object
readonly
Returns the value of attribute bloc.
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#cloc ⇒ Object
readonly
Returns the value of attribute cloc.
-
#file_name ⇒ Object
readonly
Returns the value of attribute file_name.
-
#head ⇒ Object
readonly
Returns the value of attribute head.
-
#loc ⇒ Object
readonly
Returns the value of attribute loc.
-
#methods ⇒ Object
readonly
Returns the value of attribute methods.
-
#unit_name ⇒ Object
readonly
Returns the value of attribute unit_name.
Instance Method Summary collapse
- #clazz? ⇒ Boolean
- #enum? ⇒ Boolean
- #extract_methods ⇒ Object
-
#initialize(java_file_path) ⇒ JavaUnit
constructor
A new instance of JavaUnit.
- #interface? ⇒ Boolean
- #method_blocks ⇒ Object
Methods included from LineCounter
Methods included from MethodGraber
#grab_methods, #match_method_bodies, #match_method_signature
Constructor Details
#initialize(java_file_path) ⇒ JavaUnit
Returns a new instance of JavaUnit.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/javaparse/java_unit.rb', line 9 def initialize(java_file_path) @file_path = java_file_path @file_name = File.basename(java_file_path) @unit_name = File.basename(java_file_path, ".java") @content = File.open(@file_path) { |file| file.read } validate_unit @head, @body = partition_unit extract_methods count_lines end |
Instance Attribute Details
#all_lines ⇒ Object (readonly)
Returns the value of attribute all_lines.
7 8 9 |
# File 'lib/javaparse/java_unit.rb', line 7 def all_lines @all_lines end |
#bloc ⇒ Object (readonly)
Returns the value of attribute bloc.
7 8 9 |
# File 'lib/javaparse/java_unit.rb', line 7 def bloc @bloc end |
#body ⇒ Object (readonly)
Returns the value of attribute body.
7 8 9 |
# File 'lib/javaparse/java_unit.rb', line 7 def body @body end |
#cloc ⇒ Object (readonly)
Returns the value of attribute cloc.
7 8 9 |
# File 'lib/javaparse/java_unit.rb', line 7 def cloc @cloc end |
#file_name ⇒ Object (readonly)
Returns the value of attribute file_name.
7 8 9 |
# File 'lib/javaparse/java_unit.rb', line 7 def file_name @file_name end |
#head ⇒ Object (readonly)
Returns the value of attribute head.
7 8 9 |
# File 'lib/javaparse/java_unit.rb', line 7 def head @head end |
#loc ⇒ Object (readonly)
Returns the value of attribute loc.
7 8 9 |
# File 'lib/javaparse/java_unit.rb', line 7 def loc @loc end |
#methods ⇒ Object (readonly)
Returns the value of attribute methods.
7 8 9 |
# File 'lib/javaparse/java_unit.rb', line 7 def methods @methods end |
#unit_name ⇒ Object (readonly)
Returns the value of attribute unit_name.
7 8 9 |
# File 'lib/javaparse/java_unit.rb', line 7 def unit_name @unit_name end |
Instance Method Details
#clazz? ⇒ Boolean
29 30 31 |
# File 'lib/javaparse/java_unit.rb', line 29 def clazz? unit_declaration_line.include? 'class' end |
#enum? ⇒ Boolean
37 38 39 |
# File 'lib/javaparse/java_unit.rb', line 37 def enum? unit_declaration_line.include? 'enum' end |
#extract_methods ⇒ Object
20 21 22 |
# File 'lib/javaparse/java_unit.rb', line 20 def extract_methods @methods = grab_methods(@body) end |
#interface? ⇒ Boolean
33 34 35 |
# File 'lib/javaparse/java_unit.rb', line 33 def interface? unit_declaration_line.include? 'interface' end |
#method_blocks ⇒ Object
24 25 26 27 |
# File 'lib/javaparse/java_unit.rb', line 24 def method_blocks return @body.split("}")[0...-1].map{ |block| JavaSection.new(block) } if (clazz? or enum?) return @body.split(";")[0...-1].map{ |block| JavaSection.new(block) } if (interface?) end |