Class: JavaParse::JavaUnit

Inherits:
Object
  • Object
show all
Includes:
LineCounter, MethodGraber
Defined in:
lib/javaparse/java_unit.rb

Constant Summary

Constants included from LineCounter

LineCounter::JAVA_COMMENTS_RE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from LineCounter

#count_lines

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
  @methods = grab_methods(@body)
  count_lines
end

Instance Attribute Details

#all_linesObject (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

#blocObject (readonly)

Returns the value of attribute bloc.



7
8
9
# File 'lib/javaparse/java_unit.rb', line 7

def bloc
  @bloc
end

#bodyObject (readonly)

Returns the value of attribute body.



7
8
9
# File 'lib/javaparse/java_unit.rb', line 7

def body
  @body
end

#clocObject (readonly)

Returns the value of attribute cloc.



7
8
9
# File 'lib/javaparse/java_unit.rb', line 7

def cloc
  @cloc
end

#file_nameObject (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

#headObject (readonly)

Returns the value of attribute head.



7
8
9
# File 'lib/javaparse/java_unit.rb', line 7

def head
  @head
end

#locObject (readonly)

Returns the value of attribute loc.



7
8
9
# File 'lib/javaparse/java_unit.rb', line 7

def loc
  @loc
end

#methodsObject (readonly)

Returns the value of attribute methods.



7
8
9
# File 'lib/javaparse/java_unit.rb', line 7

def methods
  @methods
end

#unit_nameObject (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

Returns:

  • (Boolean)


25
26
27
# File 'lib/javaparse/java_unit.rb', line 25

def clazz?
    unit_declaration_line.include? 'class'
end

#enum?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/javaparse/java_unit.rb', line 33

def enum?
    unit_declaration_line.include? 'enum'
end

#interface?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/javaparse/java_unit.rb', line 29

def interface?
    unit_declaration_line.include? 'interface'
end

#method_blocksObject



20
21
22
23
# File 'lib/javaparse/java_unit.rb', line 20

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