Class: Rust::Merge::NodeWrapper
- Inherits:
-
Object
- Object
- Rust::Merge::NodeWrapper
- Defined in:
- lib/rust/merge/node_wrapper.rb,
sig/rust/merge.rbs
Overview
Structural identity and source-range adapter for one top-level Rust item. rubocop:disable Metrics/AbcSize, Metrics/ClassLength, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity -- Rust item forms share one structural identity boundary
Constant Summary collapse
- DECLARATION_TYPES =
%w[ const_item enum_item expression_statement extern_crate_declaration function_item impl_item macro_definition mod_item static_item struct_item trait_item type_item union_item use_declaration ].freeze
- NAMED_ITEMS =
{ 'const_item' => [:const, %w[identifier]], 'enum_item' => [:enum, %w[type_identifier]], 'function_item' => [:function, %w[identifier]], 'macro_definition' => [:macro, %w[identifier]], 'mod_item' => [:module, %w[identifier]], 'static_item' => [:static, %w[identifier]], 'struct_item' => [:struct, %w[type_identifier]], 'trait_item' => [:trait, %w[type_identifier]], 'type_item' => [:type, %w[type_identifier]], 'union_item' => [:union, %w[type_identifier]] }.freeze
- COMMENT_TYPES =
%w[block_comment line_comment].freeze
- ATTRIBUTE_TYPES =
%w[attribute_item].freeze
Instance Attribute Summary collapse
-
#leading_comments ⇒ Array[untyped]
readonly
Returns the value of attribute leading_comments.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
-
#source ⇒ String
readonly
Returns the value of attribute source.
-
#trailing_comments ⇒ Array[untyped]
readonly
Returns the value of attribute trailing_comments.
Instance Method Summary collapse
- #attach_trailing_comment!(comment) ⇒ Object
- #compound? ⇒ Boolean
- #end_byte ⇒ Integer
- #end_line ⇒ Integer
-
#initialize(node, source:, leading_comments: []) ⇒ NodeWrapper
constructor
A new instance of NodeWrapper.
- #membership_signature ⇒ Array[untyped]
- #semantic_tree ⇒ Array[untyped]
- #signature ⇒ Array[untyped]
- #source_text ⇒ String
- #start_byte ⇒ Integer
- #start_line ⇒ Integer
Constructor Details
#initialize(node, source:, leading_comments: []) ⇒ NodeWrapper
Returns a new instance of NodeWrapper.
41 42 43 44 45 46 |
# File 'lib/rust/merge/node_wrapper.rb', line 41 def initialize(node, source:, leading_comments: []) @node = node @source = source @leading_comments = leading_comments.freeze @trailing_comments = [] end |
Instance Attribute Details
#leading_comments ⇒ Array[untyped] (readonly)
Returns the value of attribute leading_comments.
39 40 41 |
# File 'lib/rust/merge/node_wrapper.rb', line 39 def leading_comments @leading_comments end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
39 40 41 |
# File 'lib/rust/merge/node_wrapper.rb', line 39 def node @node end |
#source ⇒ String (readonly)
Returns the value of attribute source.
39 40 41 |
# File 'lib/rust/merge/node_wrapper.rb', line 39 def source @source end |
#trailing_comments ⇒ Array[untyped] (readonly)
Returns the value of attribute trailing_comments.
39 40 41 |
# File 'lib/rust/merge/node_wrapper.rb', line 39 def trailing_comments @trailing_comments end |
Instance Method Details
#attach_trailing_comment!(comment) ⇒ Object
71 |
# File 'lib/rust/merge/node_wrapper.rb', line 71 def attach_trailing_comment!(comment) = trailing_comments << comment |
#compound? ⇒ Boolean
65 |
# File 'lib/rust/merge/node_wrapper.rb', line 65 def compound? = compound_use? |
#end_byte ⇒ Integer
67 |
# File 'lib/rust/merge/node_wrapper.rb', line 67 def end_byte = trailing_comments.last&.end_byte || node.end_byte |
#end_line ⇒ Integer
69 |
# File 'lib/rust/merge/node_wrapper.rb', line 69 def end_line = line_for_byte(end_byte.zero? ? 0 : end_byte - 1) |
#membership_signature ⇒ Array[untyped]
59 60 61 62 63 |
# File 'lib/rust/merge/node_wrapper.rb', line 59 def membership_signature return semantic_node(use_body) if compound_use? signature end |
#semantic_tree ⇒ Array[untyped]
72 |
# File 'lib/rust/merge/node_wrapper.rb', line 72 def semantic_tree = semantic_node(node) |
#signature ⇒ Array[untyped]
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rust/merge/node_wrapper.rb', line 48 def signature value = case node.type when 'use_declaration' then use_signature when 'extern_crate_declaration' then extern_crate_signature when 'impl_item' then impl_signature when 'expression_statement' then macro_invocation_signature else named_signature(node) end value.freeze end |
#source_text ⇒ String
70 |
# File 'lib/rust/merge/node_wrapper.rb', line 70 def source_text = source.byteslice(start_byte...end_byte).to_s |
#start_byte ⇒ Integer
66 |
# File 'lib/rust/merge/node_wrapper.rb', line 66 def start_byte = leading_comments.first&.start_byte || node.start_byte |
#start_line ⇒ Integer
68 |
# File 'lib/rust/merge/node_wrapper.rb', line 68 def start_line = line_for_byte(start_byte) |