Module: Ast::Merge::StructuralEdit::BoundarySupport
- Extended by:
- BoundarySupport
- Includes:
- LineRangeSupport
- Included in:
- BoundarySupport
- Defined in:
- lib/ast/merge/structural_edit/boundary_support.rb
Overview
Shared helpers for building structural-edit boundaries and removed attachment payloads from statement-like objects.
This module stays parser-agnostic: it only depends on the shared
analysis attachment hooks (layout_attachment_for,
comment_attachment_for) plus statement-like line-range interfaces
(start_line / end_line or source_position).
Instance Method Summary collapse
- #attachment_preserves_fragments?(attachment) ⇒ Boolean
-
#build_splice_boundary(analysis, statement, edge:, source: nil) ⇒ Boundary?
Build a boundary descriptor for a surviving statement adjacent to a splice.
-
#removed_statement_attachments_for(analysis, statements) ⇒ Array<Object>
Collect comment/layout attachments from removed statements when they preserve fragments.
-
#statement_end_line(statement) ⇒ Integer?
Return the ending line for a statement-like object.
-
#statement_start_line(statement) ⇒ Integer?
Return the starting line for a statement-like object.
Instance Method Details
#attachment_preserves_fragments?(attachment) ⇒ Boolean
57 58 59 60 61 62 63 64 |
# File 'lib/ast/merge/structural_edit/boundary_support.rb', line 57 def () return false unless return !.empty? if .respond_to?(:empty?) gaps = .respond_to?(:gaps) ? .gaps : [] regions = .respond_to?(:regions) ? .regions : [] gaps.any? || regions.any? end |
#build_splice_boundary(analysis, statement, edge:, source: nil) ⇒ Boundary?
Build a boundary descriptor for a surviving statement adjacent to a splice.
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ast/merge/structural_edit/boundary_support.rb', line 24 def build_splice_boundary(analysis, statement, edge:, source: nil) return unless statement owner = statement_owner(statement) Boundary.new( edge: edge, owner: owner, layout_attachment: analysis.respond_to?(:layout_attachment_for) ? analysis.(owner) : nil, comment_attachment: analysis.respond_to?(:comment_attachment_for) ? analysis.(owner) : nil, metadata: source ? { source: source } : {} ) end |
#removed_statement_attachments_for(analysis, statements) ⇒ Array<Object>
Collect comment/layout attachments from removed statements when they preserve fragments.
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/ast/merge/structural_edit/boundary_support.rb', line 43 def (analysis, statements) Array(statements).filter_map do |statement| owner = statement_owner(statement) = if analysis.respond_to?(:comment_attachment_for) analysis.(owner) end next if () = (analysis.(owner) if analysis.respond_to?(:layout_attachment_for)) next if () end end |
#statement_end_line(statement) ⇒ Integer?
Return the ending line for a statement-like object.
78 79 80 |
# File 'lib/ast/merge/structural_edit/boundary_support.rb', line 78 def statement_end_line(statement) object_end_line(statement) end |
#statement_start_line(statement) ⇒ Integer?
Return the starting line for a statement-like object.
70 71 72 |
# File 'lib/ast/merge/structural_edit/boundary_support.rb', line 70 def statement_start_line(statement) object_start_line(statement) end |