Class: Solargraph::Source::Chain::Literal

Inherits:
Link
  • Object
show all
Defined in:
lib/solargraph/source/chain/literal.rb

Direct Known Subclasses

Array, Hash

Constant Summary

Constants included from Logging

Logging::DEFAULT_LOG_LEVEL, Logging::LOG_LEVELS

Instance Attribute Summary collapse

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

log_level, logger

Methods included from Equality

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

Constructor Details

#initialize(type, node) ⇒ Literal

Returns a new instance of Literal.

Parameters:

  • type (String)
  • node (Parser::AST::Node, Object)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/solargraph/source/chain/literal.rb', line 13

def initialize type, node
  super("<#{type}>")

  if node.is_a?(::Parser::AST::Node)
    # @sg-ignore flow sensitive typing needs to narrow down type with an if is_a? check
    if node.type == :true
      @value = true
    # @sg-ignore flow sensitive typing needs to narrow down type with an if is_a? check
    elsif node.type == :false
      @value = false
    # @sg-ignore flow sensitive typing needs to narrow down type with an if is_a? check
    elsif %i[int sym].include?(node.type)
      # @sg-ignore flow sensitive typing needs to narrow down type with an if is_a? check
      @value = node.children.first
    end
  end
  @type = type
  @literal_type = ComplexType.try_parse(@value.inspect)
  @complex_type = ComplexType.try_parse(type)
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



9
10
11
# File 'lib/solargraph/source/chain/literal.rb', line 9

def value
  @value
end

#wordObject (readonly)

Returns the value of attribute word.



9
10
11
# File 'lib/solargraph/source/chain/literal.rb', line 9

def word
  @word
end

Instance Method Details

#resolve(api_map, name_pin, locals) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/solargraph/source/chain/literal.rb', line 40

def resolve api_map, name_pin, locals
  if api_map.super_and_sub?(@complex_type.name, @literal_type.name)
    [Pin::ProxyType.anonymous(@literal_type, source: :chain)]
  else
    # we don't support this value as a literal type
    [Pin::ProxyType.anonymous(@complex_type, source: :chain)]
  end
end