Class: Solargraph::Parser::Rubyvm::NodeProcessors::DefNode

Inherits:
NodeProcessor::Base show all
Defined in:
lib/solargraph/parser/rubyvm/node_processors/def_node.rb

Direct Known Subclasses

DefsNode

Instance Attribute Summary

Attributes inherited from NodeProcessor::Base

#locals, #node, #pins, #region

Instance Method Summary collapse

Methods inherited from NodeProcessor::Base

#initialize

Constructor Details

This class inherits a constructor from Solargraph::Parser::NodeProcessor::Base

Instance Method Details

#processObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/solargraph/parser/rubyvm/node_processors/def_node.rb', line 8

def process
  anon_splat = node_has_anon_splat?

  methpin = Solargraph::Pin::Method.new(
    location: get_node_location(node),
    closure: region.closure,
    name: node.children[0].to_s,
    comments: comments_for(node),
    scope: region.scope || (region.closure.is_a?(Pin::Singleton) ? :class : :instance),
    visibility: region.visibility,
    node: node,
    anon_splat: anon_splat
  )
  if methpin.name == 'initialize' && methpin.scope == :instance
    pins.push Solargraph::Pin::Method.new(
      location: methpin.location,
      closure: methpin.closure,
      name: 'new',
      comments: methpin.comments,
      scope: :class,
      parameters: methpin.parameters,
      anon_splat: anon_splat
      )
    # @todo Smelly instance variable access.
    pins.last.instance_variable_set(:@return_type, ComplexType::SELF)
    pins.push methpin
    # @todo Smelly instance variable access.
    methpin.instance_variable_set(:@visibility, :private)
    methpin.instance_variable_set(:@return_type, ComplexType::VOID)
  elsif region.visibility == :module_function
    pins.push Solargraph::Pin::Method.new(
      location: methpin.location,
      closure: methpin.closure,
      name: methpin.name,
      comments: methpin.comments,
      scope: :class,
      visibility: :public,
      parameters: methpin.parameters,
      node: methpin.node,
      anon_splat: anon_splat
      )
    pins.push Solargraph::Pin::Method.new(
      location: methpin.location,
      closure: methpin.closure,
      name: methpin.name,
      comments: methpin.comments,
      scope: :instance,
      visibility: :private,
      parameters: methpin.parameters,
      node: methpin.node,
      anon_splat: anon_splat
      )
  else
    pins.push methpin
  end
  process_children region.update(closure: methpin, scope: methpin.scope)
end