Class: Jazzy::SymbolGraph::ExtNode
- Includes:
- Comparable
- Defined in:
- lib/jazzy/symbol_graph/ext_node.rb
Overview
An ExtNode is a node of the reconstructed syntax tree representing an extension that we fabricate to resolve certain relationships.
Instance Attribute Summary collapse
-
#all_constraints ⇒ Object
ExtConstraints.
-
#conformances ⇒ Object
array, can be empty.
-
#name ⇒ Object
Returns the value of attribute name.
-
#usr ⇒ Object
Returns the value of attribute usr.
Attributes inherited from BaseNode
Class Method Summary collapse
-
.new_for_conformance(type_usr, type_name, protocol, constraints) ⇒ Object
Deduce an extension from a protocol conformance for some type.
-
.new_for_member(type_usr, member, constraints) ⇒ Object
Deduce an extension from a member of an unknown type or of known type with additional constraints.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #add_conformance(protocol) ⇒ Object
- #constraints ⇒ Object
- #full_declaration ⇒ Object
- #sort_key ⇒ Object
- #to_sourcekit(module_name) ⇒ Object
Methods inherited from BaseNode
#add_child, #children_to_sourcekit
Instance Attribute Details
#all_constraints ⇒ Object
ExtConstraints
25 26 27 |
# File 'lib/jazzy/symbol_graph/ext_node.rb', line 25 def all_constraints @all_constraints end |
#conformances ⇒ Object
array, can be empty
26 27 28 |
# File 'lib/jazzy/symbol_graph/ext_node.rb', line 26 def conformances @conformances end |
#name ⇒ Object
Returns the value of attribute name.
24 25 26 |
# File 'lib/jazzy/symbol_graph/ext_node.rb', line 24 def name @name end |
#usr ⇒ Object
Returns the value of attribute usr.
23 24 25 |
# File 'lib/jazzy/symbol_graph/ext_node.rb', line 23 def usr @usr end |
Class Method Details
.new_for_conformance(type_usr, type_name, protocol, constraints) ⇒ Object
Deduce an extension from a protocol conformance for some type
39 40 41 42 43 44 45 46 |
# File 'lib/jazzy/symbol_graph/ext_node.rb', line 39 def self.new_for_conformance(type_usr, type_name, protocol, constraints) new(type_usr, type_name, constraints).tap do |o| o.add_conformance(protocol) end end |
.new_for_member(type_usr, member, constraints) ⇒ Object
Deduce an extension from a member of an unknown type or of known type with additional constraints
30 31 32 33 34 35 36 |
# File 'lib/jazzy/symbol_graph/ext_node.rb', line 30 def self.new_for_member(type_usr, member, constraints) new(type_usr, member.parent_qualified_name, constraints).tap { |o| o.add_child(member) } end |
Instance Method Details
#<=>(other) ⇒ Object
109 110 111 |
# File 'lib/jazzy/symbol_graph/ext_node.rb', line 109 def <=>(other) sort_key <=> other.sort_key end |
#add_conformance(protocol) ⇒ Object
64 65 66 |
# File 'lib/jazzy/symbol_graph/ext_node.rb', line 64 def add_conformance(protocol) conformances.append(protocol).sort! end |
#constraints ⇒ Object
60 61 62 |
# File 'lib/jazzy/symbol_graph/ext_node.rb', line 60 def constraints all_constraints.merged end |
#full_declaration ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/jazzy/symbol_graph/ext_node.rb', line 68 def full_declaration decl = "extension #{name}" unless conformances.empty? decl += ' : ' + conformances.join(', ') end decl + all_constraints.ext.to_where_clause end |
#sort_key ⇒ Object
105 106 107 |
# File 'lib/jazzy/symbol_graph/ext_node.rb', line 105 def sort_key name + constraints.map(&:to_swift).join end |
#to_sourcekit(module_name) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/jazzy/symbol_graph/ext_node.rb', line 76 def to_sourcekit(module_name) declaration = full_declaration xml_declaration = "<swift>#{CGI.escapeHTML(declaration)}</swift>" hash = { 'key.kind' => 'source.lang.swift.decl.extension', 'key.usr' => usr, 'key.name' => name, 'key.modulename' => module_name, 'key.parsed_declaration' => declaration, 'key.annotated_decl' => xml_declaration, } unless conformances.empty? hash['key.inheritedtypes'] = conformances.map do |conformance| { 'key.name' => conformance } end end unless children.empty? hash['key.substructure'] = children_to_sourcekit end hash end |