Class: Solargraph::Source::Chain::Array

Inherits:
Literal show all
Defined in:
lib/solargraph/source/chain/array.rb

Constant Summary

Constants included from Logging

Logging::DEFAULT_LOG_LEVEL, Logging::LOG_LEVELS

Instance Attribute Summary

Attributes inherited from Literal

#value

Attributes inherited from Link

#last_context

Instance Method Summary collapse

Methods inherited from Link

#clone_body, #clone_head, #constant?, #desc, #head?, #inspect, #nullable?, #to_s, #undefined?

Methods included from Logging

logger

Methods included from Equality

#==, #eql?, #equality_fields, #freeze, #hash

Constructor Details

#initialize(children, node) ⇒ Array

Returns a new instance of Array.

Parameters:

  • children (::Array<Chain>)
  • node (Parser::AST::Node)


7
8
9
10
# File 'lib/solargraph/source/chain/array.rb', line 7

def initialize children, node
  super('::Array', node)
  @children = children
end

Instance Method Details

#resolve(api_map, name_pin, locals) ⇒ Object

Parameters:



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/solargraph/source/chain/array.rb', line 19

def resolve api_map, name_pin, locals
  child_types = @children.map do |child|
    child.infer(api_map, name_pin, locals).simplify_literals
  end
  type = if child_types.length == 0 || child_types.any?(&:undefined?)
           ComplexType::UniqueType.new('Array', rooted: true)
         elsif child_types.uniq.length == 1 && child_types.first.defined?
           ComplexType::UniqueType.new('Array', [], child_types.uniq, rooted: true, parameters_type: :list)
         elsif child_types.length == 0
           ComplexType::UniqueType.new('Array', rooted: true, parameters_type: :list)
         else
           ComplexType::UniqueType.new('Array', [], child_types, rooted: true, parameters_type: :fixed)
         end
  [Pin::ProxyType.anonymous(type, source: :chain)]
end

#wordObject



12
13
14
# File 'lib/solargraph/source/chain/array.rb', line 12

def word
  @word ||= "<#{@type}>"
end