Module: Solargraph::ComplexType::TypeMethods
- Included in:
- UniqueType
- Defined in:
- lib/solargraph/complex_type/type_methods.rb
Overview
Methods for accessing type data.
Instance Attribute Summary collapse
- #name ⇒ String readonly
- #substring ⇒ String readonly
- #subtypes ⇒ Array<ComplexType> readonly
- #tag ⇒ String readonly
Instance Method Summary collapse
- #==(other) ⇒ Object
- #defined? ⇒ Boolean
- #duck_type? ⇒ Boolean
- #fixed_parameters? ⇒ Boolean
- #hash_parameters? ⇒ Boolean
- #key_types ⇒ Array<ComplexType>
- #list_parameters? ⇒ Boolean
- #namespace ⇒ String
- #nil_type? ⇒ Boolean
- #parameters? ⇒ Boolean
-
#qualify(api_map, context = '') ⇒ ComplexType
Generate a ComplexType that fully qualifies this type’s namespaces.
- #rooted? ⇒ Boolean
-
#scope ⇒ Symbol
:class or :instance.
- #undefined? ⇒ Boolean
- #value_types ⇒ Array<ComplexType>
- #void? ⇒ Boolean
Instance Attribute Details
#name ⇒ String (readonly)
9 10 11 |
# File 'lib/solargraph/complex_type/type_methods.rb', line 9 def name @name end |
#substring ⇒ String (readonly)
12 13 14 |
# File 'lib/solargraph/complex_type/type_methods.rb', line 12 def substring @substring end |
#subtypes ⇒ Array<ComplexType> (readonly)
18 19 20 |
# File 'lib/solargraph/complex_type/type_methods.rb', line 18 def subtypes @subtypes end |
#tag ⇒ String (readonly)
15 16 17 |
# File 'lib/solargraph/complex_type/type_methods.rb', line 15 def tag @tag end |
Instance Method Details
#==(other) ⇒ Object
86 87 88 89 |
# File 'lib/solargraph/complex_type/type_methods.rb', line 86 def == other return false unless self.class == other.class tag == other.tag end |
#defined? ⇒ Boolean
40 41 42 |
# File 'lib/solargraph/complex_type/type_methods.rb', line 40 def defined? !undefined? end |
#duck_type? ⇒ Boolean
21 22 23 |
# File 'lib/solargraph/complex_type/type_methods.rb', line 21 def duck_type? @duck_type ||= name.start_with?('#') end |
#fixed_parameters? ⇒ Boolean
54 55 56 |
# File 'lib/solargraph/complex_type/type_methods.rb', line 54 def fixed_parameters? substring.start_with?('(') end |
#hash_parameters? ⇒ Boolean
59 60 61 |
# File 'lib/solargraph/complex_type/type_methods.rb', line 59 def hash_parameters? substring.start_with?('{') end |
#key_types ⇒ Array<ComplexType>
69 70 71 |
# File 'lib/solargraph/complex_type/type_methods.rb', line 69 def key_types @key_types end |
#list_parameters? ⇒ Boolean
49 50 51 |
# File 'lib/solargraph/complex_type/type_methods.rb', line 49 def list_parameters? substring.start_with?('<') end |
#namespace ⇒ String
74 75 76 77 78 |
# 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? ⇒ Boolean
26 27 28 29 |
# 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? ⇒ Boolean
32 33 34 |
# File 'lib/solargraph/complex_type/type_methods.rb', line 32 def parameters? !substring.empty? end |
#qualify(api_map, context = '') ⇒ ComplexType
Generate a ComplexType that fully qualifies this type’s namespaces.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# 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? ⇒ Boolean
91 92 93 |
# File 'lib/solargraph/complex_type/type_methods.rb', line 91 def rooted? @rooted end |
#scope ⇒ Symbol
Returns :class or :instance.
81 82 83 84 |
# 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? ⇒ Boolean
44 45 46 |
# File 'lib/solargraph/complex_type/type_methods.rb', line 44 def undefined? name == 'undefined' end |
#value_types ⇒ Array<ComplexType>
64 65 66 |
# File 'lib/solargraph/complex_type/type_methods.rb', line 64 def value_types @subtypes end |
#void? ⇒ Boolean
36 37 38 |
# File 'lib/solargraph/complex_type/type_methods.rb', line 36 def void? name == 'void' end |