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 86 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
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 @namespace ||= 'Object' if duck_type? @namespace ||= 'NilClass' if nil_type? @namespace ||= (name == 'Class' || name == 'Module') && !subtypes.empty? ? subtypes.first.name : name 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 100 def qualify api_map, context = '' 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 do |t| t.qualify api_map, context end rtypes = value_types.map do |t| t.qualify api_map, context end 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 91 def rooted? @rooted end
scope()
click to toggle source
@return [Symbol] :class or :instance
# File lib/solargraph/complex_type/type_methods.rb, line 81 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