Class: JavaClass
- Inherits:
-
Object
- Object
- JavaClass
- Defined in:
- lib/javaclass.rb
Overview
for parsing Java .java files
Direct Known Subclasses
Instance Attribute Summary collapse
-
#file_path ⇒ Object
Returns the value of attribute file_path.
Class Method Summary collapse
Instance Method Summary collapse
- #class_name ⇒ Object (also: #name)
-
#initialize(file_path) ⇒ JavaClass
constructor
A new instance of JavaClass.
- #package_name ⇒ Object (also: #package)
- #source_code ⇒ Object (also: #source)
- #source_code_without_comments ⇒ Object (also: #source_without_comments, #source_sans_comments)
- #super_class ⇒ Object (also: #superclass, #parent)
Constructor Details
#initialize(file_path) ⇒ JavaClass
Returns a new instance of JavaClass.
6 7 8 |
# File 'lib/javaclass.rb', line 6 def initialize file_path @file_path = file_path end |
Instance Attribute Details
#file_path ⇒ Object
Returns the value of attribute file_path.
4 5 6 |
# File 'lib/javaclass.rb', line 4 def file_path @file_path end |
Class Method Details
Instance Method Details
#class_name ⇒ Object Also known as: name
10 11 12 13 14 15 16 17 18 |
# File 'lib/javaclass.rb', line 10 def class_name match = /public .*class (\w+)/.match(source_sans_comments) if match match.captures.first else match = /class (\w+)/.match(source_sans_comments) match.captures.first if match end end |
#package_name ⇒ Object Also known as: package
21 22 23 |
# File 'lib/javaclass.rb', line 21 def package_name /package (.*);/.match(source_sans_comments).captures.first end |
#source_code ⇒ Object Also known as: source
33 34 35 |
# File 'lib/javaclass.rb', line 33 def source_code File.read file_path end |
#source_code_without_comments ⇒ Object Also known as: source_without_comments, source_sans_comments
38 39 40 41 42 |
# File 'lib/javaclass.rb', line 38 def source_code_without_comments # regular expression to find all comments, from: http://ostermiller.org/findcomment.html regular_expression = Regexp.new('(/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/)|(//.*)') source.gsub(regular_expression, '') end |
#super_class ⇒ Object Also known as: superclass, parent
26 27 28 29 |
# File 'lib/javaclass.rb', line 26 def super_class match = /public .*class \w+ extends (\w+)/.match(source_sans_comments) if match then match.captures.first else nil end end |