Class: Solargraph::Convention::StructDefinition::NodeProcessors::StructNode
- Inherits:
-
Parser::NodeProcessor::Base
- Object
- Parser::NodeProcessor::Base
- Solargraph::Convention::StructDefinition::NodeProcessors::StructNode
- Defined in:
- lib/solargraph/convention/struct_definition.rb
Instance Attribute Summary
Attributes inherited from Parser::NodeProcessor::Base
#locals, #node, #pins, #region
Instance Method Summary collapse
Methods inherited from Parser::NodeProcessor::Base
Constructor Details
This class inherits a constructor from Solargraph::Parser::NodeProcessor::Base
Instance Method Details
#process ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/solargraph/convention/struct_definition.rb', line 11 def process return if struct_definition_node.nil? loc = get_node_location(node) nspin = Solargraph::Pin::Namespace.new( type: :class, location: loc, closure: region.closure, name: struct_definition_node.class_name, comments: comments_for(node), visibility: :public, gates: region.closure.gates.freeze ) pins.push nspin # define initialize method initialize_method_pin = Pin::Method.new( name: 'initialize', parameters: [], scope: :instance, location: get_node_location(node), closure: nspin, visibility: :private, comments: comments_for(node) ) pins.push initialize_method_pin struct_definition_node.attributes.map do |attribute_node, attribute_name| initialize_method_pin.parameters.push( Pin::Parameter.new( name: attribute_name, decl: struct_definition_node.keyword_init? ? :kwarg : :arg, location: get_node_location(attribute_node), closure: initialize_method_pin ) ) end # define attribute accessors and instance variables struct_definition_node.attributes.each do |attribute_node, attribute_name| [attribute_name, "#{attribute_name}="].each do |name| method_pin = Pin::Method.new( name: name, parameters: [], scope: :instance, location: get_node_location(attribute_node), closure: nspin, comments: attribute_comments(attribute_node, attribute_name), visibility: :public ) pins.push method_pin next unless name.include?('=') # setter pins.push Pin::InstanceVariable.new(name: "@#{attribute_name}", closure: method_pin, location: get_node_location(attribute_node), comments: attribute_comments(attribute_node, attribute_name)) end end process_children region.update(closure: nspin, visibility: :public) end |