Class: Solargraph::Source::Chain
- Inherits:
-
Object
- Object
- Solargraph::Source::Chain
show all
- Defined in:
- lib/solargraph/source/chain.rb,
lib/solargraph/source/chain/or.rb,
lib/solargraph/source/chain/call.rb,
lib/solargraph/source/chain/head.rb,
lib/solargraph/source/chain/link.rb,
lib/solargraph/source/chain/literal.rb,
lib/solargraph/source/chain/z_super.rb,
lib/solargraph/source/chain/constant.rb,
lib/solargraph/source/chain/variable.rb,
lib/solargraph/source/chain/block_variable.rb,
lib/solargraph/source/chain/class_variable.rb,
lib/solargraph/source/chain/global_variable.rb,
lib/solargraph/source/chain/instance_variable.rb
Overview
A chain of constants, variables, and method calls for inferring types of values.
Defined Under Namespace
Classes: BlockVariable, Call, ClassVariable, Constant, GlobalVariable, Head, InstanceVariable, Link, Literal, Or, Variable, ZSuper
Constant Summary
collapse
- UNDEFINED_CALL =
Chain::Call.new('<undefined>')
- UNDEFINED_CONSTANT =
Chain::Constant.new('<undefined>')
- @@inference_stack =
[]
- @@inference_depth =
0
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(links, node = nil, splat = false) ⇒ Chain
Returns a new instance of Chain.
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/solargraph/source/chain.rb', line 37
def initialize links, node = nil, splat = false
@links = links.clone
@links.push UNDEFINED_CALL if @links.empty?
head = true
@links.map! do |link|
result = (head ? link.clone_head : link.clone_body)
head = false
result
end
@node = node
@splat = splat
end
|
Instance Attribute Details
32
33
34
|
# File 'lib/solargraph/source/chain.rb', line 32
def links
@links
end
|
#node ⇒ Object
Returns the value of attribute node.
34
35
36
|
# File 'lib/solargraph/source/chain.rb', line 34
def node
@node
end
|
Instance Method Details
51
52
53
|
# File 'lib/solargraph/source/chain.rb', line 51
def base
@base ||= Chain.new(links[0..-2])
end
|
#constant? ⇒ Boolean
99
100
101
|
# File 'lib/solargraph/source/chain.rb', line 99
def constant?
links.last.is_a?(Chain::Constant)
end
|
#define(api_map, name_pin, locals) ⇒ Array<Pin::Base>
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/solargraph/source/chain.rb', line 59
def define api_map, name_pin, locals
return [] if undefined?
working_pin = name_pin
links[0..-2].each do |link|
pins = link.resolve(api_map, working_pin, locals)
type = infer_first_defined(pins, working_pin, api_map)
return [] if type.undefined?
working_pin = Pin::ProxyType.anonymous(type)
end
links.last.last_context = working_pin
links.last.resolve(api_map, working_pin, locals)
end
|
#defined? ⇒ Boolean
94
95
96
|
# File 'lib/solargraph/source/chain.rb', line 94
def defined?
!undefined?
end
|
#infer(api_map, name_pin, locals) ⇒ ComplexType
80
81
82
83
|
# File 'lib/solargraph/source/chain.rb', line 80
def infer api_map, name_pin, locals
pins = define(api_map, name_pin, locals)
infer_first_defined(pins, links.last.last_context, api_map)
end
|
#literal? ⇒ Boolean
86
87
88
|
# File 'lib/solargraph/source/chain.rb', line 86
def literal?
links.last.is_a?(Chain::Literal)
end
|
#splat? ⇒ Boolean
103
104
105
|
# File 'lib/solargraph/source/chain.rb', line 103
def splat?
@splat
end
|
#undefined? ⇒ Boolean
90
91
92
|
# File 'lib/solargraph/source/chain.rb', line 90
def undefined?
links.any?(&:undefined?)
end
|