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

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)


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

def initialize type, node
  if node.is_a?(::Parser::AST::Node)
    if node.type == :true
      @value = true
    elsif node.type == :false
      @value = false
    elsif [:int, :sym].include?(node.type)
      @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.



13
14
15
# File 'lib/solargraph/source/chain/literal.rb', line 13

def value
  @value
end

Instance Method Details

#resolve(api_map, name_pin, locals) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/solargraph/source/chain/literal.rb', line 37

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

#wordObject



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

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