Class: Rsense::Server::Command::RsenseMethod

Inherits:
Java::org.cx4a.rsense.typing.runtime::DefaultMethod
  • Object
show all
Defined in:
lib/rsense/server/command/rsense_method.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cbase, name, bodyNode, argsNode, visibility, location) ⇒ RsenseMethod

Returns a new instance of RsenseMethod.



9
10
11
# File 'lib/rsense/server/command/rsense_method.rb', line 9

def initialize(cbase, name, bodyNode, argsNode, visibility, location)
  super(cbase, name, bodyNode, argsNode, visibility, location)
end

Instance Attribute Details

#args_nodeObject

Returns the value of attribute args_node.



7
8
9
# File 'lib/rsense/server/command/rsense_method.rb', line 7

def args_node
  @args_node
end

#body_nodeObject

Returns the value of attribute body_node.



7
8
9
# File 'lib/rsense/server/command/rsense_method.rb', line 7

def body_node
  @body_node
end

#cbaseObject

Returns the value of attribute cbase.



7
8
9
# File 'lib/rsense/server/command/rsense_method.rb', line 7

def cbase
  @cbase
end

#locationObject

Returns the value of attribute location.



7
8
9
# File 'lib/rsense/server/command/rsense_method.rb', line 7

def location
  @location
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/rsense/server/command/rsense_method.rb', line 7

def name
  @name
end

#nodeObject

Returns the value of attribute node.



7
8
9
# File 'lib/rsense/server/command/rsense_method.rb', line 7

def node
  @node
end

#parentObject

Returns the value of attribute parent.



7
8
9
# File 'lib/rsense/server/command/rsense_method.rb', line 7

def parent
  @parent
end

#visibilityObject

Returns the value of attribute visibility.



7
8
9
# File 'lib/rsense/server/command/rsense_method.rb', line 7

def visibility
  @visibility
end

Class Method Details

.generate_method_body(name) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rsense/server/command/rsense_method.rb', line 23

def self.generate_method_body(name)
  %Q{
      def #{name}(*args)
        if block_given?
          yield args
        else
          args
        end
      end
    }
end

.generate_node(name, parent) ⇒ Object



35
36
37
38
39
40
# File 'lib/rsense/server/command/rsense_method.rb', line 35

def self.generate_node(name, parent)
  code = self.generate_method_body(name)
  root = JRubyParser.parse(code)
  node = root.find_node(:defn)
  self.insert_into_parent(node, parent)
end

.insert_into_parent(node, parent) ⇒ Object



42
43
44
45
46
47
48
49
50
51
# File 'lib/rsense/server/command/rsense_method.rb', line 42

def self.insert_into_parent(node, parent)
  parent = parent
  parent.insert_node(node)
  inserted_node = parent.find_all.select {|n| n == node}.first
  if inserted_node
    inserted_node
  else
    node
  end
end

.make_method(cbase, name, visibility, parent) ⇒ Object



13
14
15
16
17
# File 'lib/rsense/server/command/rsense_method.rb', line 13

def self.make_method(cbase, name, visibility, parent)
  node = self.make_node(name, parent)
  loc = Java::org.cx4a.rsense.util::SourceLocation.of(node)
  [cbase, name, node.body_node, node.args_node, visibility, loc]
end

.make_node(name, parent) ⇒ Object



19
20
21
# File 'lib/rsense/server/command/rsense_method.rb', line 19

def self.make_node(name, parent)
  self.generate_node(name, parent)
end