class Jazzy::SymbolGraph::ExtNode
An ExtNode
is a node of the reconstructed syntax tree representing an extension that we fabricate to resolve certain relationships.
Attributes
all_constraints[RW]
conformances[RW]
name[RW]
real_usr[RW]
usr[RW]
Public Class Methods
new(usr, name, constraints)
click to toggle source
Calls superclass method
# File lib/jazzy/symbol_graph/ext_node.rb, line 55 def initialize(usr, name, constraints) self.usr = usr self.name = name self.all_constraints = constraints self.conformances = Set.new super() end
new_for_conformance(type_usr, type_name, protocol, constraints)
click to toggle source
Deduce an extension from a protocol conformance for some type
# File lib/jazzy/symbol_graph/ext_node.rb, line 44 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)
click to toggle source
Deduce an extension from a member of an unknown type or of known type with additional constraints
# File lib/jazzy/symbol_graph/ext_node.rb, line 35 def self.new_for_member(type_usr, member, constraints) new(type_usr, member.parent_qualified_name, constraints).tap { |o| o.add_child(member) } end
Public Instance Methods
<=>(other)
click to toggle source
# File lib/jazzy/symbol_graph/ext_node.rb, line 114 def <=>(other) sort_key <=> other.sort_key end
add_conformance(protocol)
click to toggle source
# File lib/jazzy/symbol_graph/ext_node.rb, line 69 def add_conformance(protocol) conformances.add(protocol) end
constraints()
click to toggle source
# File lib/jazzy/symbol_graph/ext_node.rb, line 65 def constraints all_constraints.merged end
full_declaration()
click to toggle source
# File lib/jazzy/symbol_graph/ext_node.rb, line 73 def full_declaration decl = "extension #{name}" unless conformances.empty? decl += " : #{conformances.sort.join(', ')}" end decl + all_constraints.ext.to_where_clause end
sort_key()
click to toggle source
# File lib/jazzy/symbol_graph/ext_node.rb, line 110 def sort_key name + constraints.map(&:to_swift).join + conformances.sort.join end
to_sourcekit(module_name, ext_module_name)
click to toggle source
# File lib/jazzy/symbol_graph/ext_node.rb, line 81 def to_sourcekit(module_name, ext_module_name) declaration = full_declaration xml_declaration = "<swift>#{CGI.escapeHTML(declaration)}</swift>" hash = { 'key.kind' => 'source.lang.swift.decl.extension', 'key.usr' => real_usr || usr, 'key.name' => name, 'key.modulename' => ext_module_name, 'key.parsed_declaration' => declaration, 'key.annotated_decl' => xml_declaration, } unless conformances.empty? hash['key.inheritedtypes'] = conformances.sort.map do |conformance| { 'key.name' => conformance } end end add_children_to_sourcekit(hash, module_name) hash end