Sha256: c940689a2ed49c8a2edd8a8f30ed303539ab302057f76ec20d04d67c3fa96e32

Contents?: true

Size: 1.55 KB

Versions: 15

Compression:

Stored size: 1.55 KB

Contents

require "jruby-parser"

module Rsense
  module Server
    module Command
      class RsenseMethod < Java::org.cx4a.rsense.typing.runtime::DefaultMethod
        attr_accessor :cbase, :name, :body_node, :args_node, :visibility, :location, :node, :parent

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

        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

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

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

        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

        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

      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
rsense-server-0.5.18 lib/rsense/server/command/rsense_method.rb
rsense-server-0.5.17 lib/rsense/server/command/rsense_method.rb
rsense-server-0.5.16 lib/rsense/server/command/rsense_method.rb
rsense-server-0.5.15 lib/rsense/server/command/rsense_method.rb
rsense-server-0.5.14 lib/rsense/server/command/rsense_method.rb
rsense-server-0.5.13 lib/rsense/server/command/rsense_method.rb
rsense-server-0.5.12 lib/rsense/server/command/rsense_method.rb
rsense-server-0.5.11 lib/rsense/server/command/rsense_method.rb
rsense-server-0.5.10 lib/rsense/server/command/rsense_method.rb
rsense-server-0.5.9 lib/rsense/server/command/rsense_method.rb
rsense-server-0.5.8 lib/rsense/server/command/rsense_method.rb
rsense-server-0.5.7 lib/rsense/server/command/rsense_method.rb
rsense-server-0.5.6 lib/rsense/server/command/rsense_method.rb
rsense-server-0.5.5 lib/rsense/server/command/rsense_method.rb
rsense-server-0.5.4 lib/rsense/server/command/rsense_method.rb