Class: Jtor::JavaParser

Inherits:
Object
  • Object
show all
Includes:
Expressions
Defined in:
lib/jtor/java_parser.rb

Constant Summary

Constants included from Expressions

Expressions::ASSINGMENT_OPERATORS, Expressions::BINARY_OPERATORS, Expressions::UNARY_OPERATORS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Expressions

#translate_arguments, #translate_constructor_call_args, #translate_expression, #translate_expressions

Constructor Details

#initialize(f) ⇒ JavaParser

Returns a new instance of JavaParser.



15
16
17
18
19
# File 'lib/jtor/java_parser.rb', line 15

def initialize(f)
  @indentator = '  '
  @level = 0
  @f = f
end

Instance Attribute Details

#indentatorObject

Returns the value of attribute indentator.



13
14
15
# File 'lib/jtor/java_parser.rb', line 13

def indentator
  @indentator
end

Instance Method Details

#translate(file) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/jtor/java_parser.rb', line 21

def translate(file)
  parser = ::JavaParser.parse(FileInputStream.new(file))
  # In Java, other classes on the same package are automatically accessible,
  # we do that manually here.
  fputs("jtor_import '#{parser.package.name}.*'")
  fputs('module Java')
  indented do
    fputs("module #{module_name(parser.package.name)}")
    indented do
      parser.imports.each do |import|
        fputs("jtor_import '#{translate_expression(import.name)}'")
      end
      parser.types.each { |type| translate_class_or_interface(type) }
    end
    fputs('end')
  end
  fputs('end')
end