module Solargraph::ComplexType::TypeMethods

Methods for accessing type data.

Attributes

name[R]

@return [String]

substring[R]

@return [String]

subtypes[R]

@return [Array<ComplexType>]

tag[R]

@return [String]

Public Instance Methods

==(other) click to toggle source
# File lib/solargraph/complex_type/type_methods.rb, line 89
def == other
  return false unless self.class == other.class
  tag == other.tag
end
defined?() click to toggle source
# File lib/solargraph/complex_type/type_methods.rb, line 40
def defined?
  !undefined?
end
duck_type?() click to toggle source

@return [Boolean]

# File lib/solargraph/complex_type/type_methods.rb, line 21
def duck_type?
  @duck_type ||= name.start_with?('#')
end
each_unique_type() { |self| ... } click to toggle source

@yieldparam [UniqueType] @return [Enumerator<UniqueType>]

# File lib/solargraph/complex_type/type_methods.rb, line 128
def each_unique_type &block
  return enum_for(__method__) unless block_given?
  yield self
end
fixed_parameters?() click to toggle source

@return [Boolean]

# File lib/solargraph/complex_type/type_methods.rb, line 54
def fixed_parameters?
  substring.start_with?('(')
end
hash_parameters?() click to toggle source

@return [Boolean]

# File lib/solargraph/complex_type/type_methods.rb, line 59
def hash_parameters?
  substring.start_with?('{')
end
key_types() click to toggle source

@return [Array<ComplexType>]

# File lib/solargraph/complex_type/type_methods.rb, line 69
def key_types
  @key_types
end
list_parameters?() click to toggle source

@return [Boolean]

# File lib/solargraph/complex_type/type_methods.rb, line 49
def list_parameters?
  substring.start_with?('<')
end
namespace() click to toggle source

@return [String]

# File lib/solargraph/complex_type/type_methods.rb, line 74
def namespace
  # if priority higher than ||=, old implements cause unnecessary check
  @namespace ||= lambda do
    return 'Object' if duck_type?
    return 'NilClass' if nil_type?
    return (name == 'Class' || name == 'Module') && !subtypes.empty? ? subtypes.first.name : name
  end.call
end
nil_type?() click to toggle source

@return [Boolean]

# File lib/solargraph/complex_type/type_methods.rb, line 26
def nil_type?
  @nil_type = (name.casecmp('nil') == 0) if @nil_type.nil?
  @nil_type
end
parameters?() click to toggle source

@return [Boolean]

# File lib/solargraph/complex_type/type_methods.rb, line 32
def parameters?
  !substring.empty?
end
qualify(api_map, context = '') click to toggle source

Generate a ComplexType that fully qualifies this type’s namespaces.

@param api_map [ApiMap] The ApiMap that performs qualification @param context [String] The namespace from which to resolve names @return [ComplexType] The generated ComplexType

# File lib/solargraph/complex_type/type_methods.rb, line 103
def qualify api_map, context = ''
  return self if name == 'param'
  return ComplexType.new([self]) if duck_type? || void? || undefined?
  recon = (rooted? ? '' : context)
  fqns = api_map.qualify(name, recon)
  if fqns.nil?
    return UniqueType::BOOLEAN if tag == 'Boolean'
    return UniqueType::UNDEFINED
  end
  fqns = "::#{fqns}" # Ensure the resulting complex type is rooted
  ltypes = key_types.map { |t| t.qualify api_map, context }.uniq
  rtypes = value_types.map { |t| t.qualify api_map, context }.uniq
  if list_parameters?
    Solargraph::ComplexType.parse("#{fqns}<#{rtypes.map(&:tag).join(', ')}>")
  elsif fixed_parameters?
    Solargraph::ComplexType.parse("#{fqns}(#{rtypes.map(&:tag).join(', ')})")
  elsif hash_parameters?
    Solargraph::ComplexType.parse("#{fqns}{#{ltypes.map(&:tag).join(', ')} => #{rtypes.map(&:tag).join(', ')}}")
  else
    Solargraph::ComplexType.parse(fqns)
  end
end
rooted?() click to toggle source
# File lib/solargraph/complex_type/type_methods.rb, line 94
def rooted?
  @rooted
end
scope() click to toggle source

@return [Symbol] :class or :instance

# File lib/solargraph/complex_type/type_methods.rb, line 84
def scope
  @scope ||= :instance if duck_type? || nil_type?
  @scope ||= (name == 'Class' || name == 'Module') && !subtypes.empty? ? :class : :instance
end
undefined?() click to toggle source
# File lib/solargraph/complex_type/type_methods.rb, line 44
def undefined?
  name == 'undefined'
end
value_types() click to toggle source

@return [Array<ComplexType>]

# File lib/solargraph/complex_type/type_methods.rb, line 64
def value_types
  @subtypes
end
void?() click to toggle source
# File lib/solargraph/complex_type/type_methods.rb, line 36
def void?
  name == 'void'
end