Class: Ast::Merge::StructuralEdit::Boundary

Inherits:
Object
  • Object
show all
Defined in:
lib/ast/merge/structural_edit/boundary.rb

Overview

Passive metadata about one edge of a structural splice.

A boundary captures the surviving owner adjacent to a splice plus any known shared layout/comment attachments. The first contiguous replace primitive mostly needs the owner and edge metadata, but remove/rehome work can build on the same object without inventing a new boundary shape.

Constant Summary collapse

EDGES =

Supported structural boundary edges.

Returns:

  • (Array<Symbol>)
%i[leading trailing].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(edge:, owner: nil, layout_attachment: nil, comment_attachment: nil, metadata: {}, **options) ⇒ Boundary

Returns a new instance of Boundary.



20
21
22
23
24
25
26
# File 'lib/ast/merge/structural_edit/boundary.rb', line 20

def initialize(edge:, owner: nil, layout_attachment: nil, comment_attachment: nil, metadata: {}, **options)
  @edge = normalize_edge(edge)
  @owner = owner
  @layout_attachment = layout_attachment
  @comment_attachment = comment_attachment
  @metadata = .merge(options).freeze
end

Instance Attribute Details

#comment_attachmentObject (readonly)

Returns the value of attribute comment_attachment.



18
19
20
# File 'lib/ast/merge/structural_edit/boundary.rb', line 18

def comment_attachment
  @comment_attachment
end

#edgeObject (readonly)

Returns the value of attribute edge.



18
19
20
# File 'lib/ast/merge/structural_edit/boundary.rb', line 18

def edge
  @edge
end

#layout_attachmentObject (readonly)

Returns the value of attribute layout_attachment.



18
19
20
# File 'lib/ast/merge/structural_edit/boundary.rb', line 18

def layout_attachment
  @layout_attachment
end

#metadataObject (readonly)

Returns the value of attribute metadata.



18
19
20
# File 'lib/ast/merge/structural_edit/boundary.rb', line 18

def 
  @metadata
end

#ownerObject (readonly)

Returns the value of attribute owner.



18
19
20
# File 'lib/ast/merge/structural_edit/boundary.rb', line 18

def owner
  @owner
end

Instance Method Details

#gapsArray<Layout::Gap>

Return all layout gaps attached to the boundary owner.

Returns:



39
40
41
42
43
44
# File 'lib/ast/merge/structural_edit/boundary.rb', line 39

def gaps
  attachment = layout_attachment
  return [] unless attachment.respond_to?(:gaps)

  Array(attachment.public_send(:gaps))
end

#inspectString

Return a concise debug representation of the boundary.

Returns:

  • (String)


59
60
61
# File 'lib/ast/merge/structural_edit/boundary.rb', line 59

def inspect
  "#<#{self.class.name} edge=#{edge.inspect} owner=#{owner&.class&.name} gaps=#{gaps.size} regions=#{regions.size}>"
end

#leading?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/ast/merge/structural_edit/boundary.rb', line 28

def leading?
  edge == :leading
end

#regionsArray<Comment::Region>

Return all comment regions attached to the boundary owner.

Returns:



49
50
51
52
53
54
# File 'lib/ast/merge/structural_edit/boundary.rb', line 49

def regions
  attachment = comment_attachment
  return [] unless attachment.respond_to?(:regions)

  Array(attachment.public_send(:regions))
end

#trailing?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/ast/merge/structural_edit/boundary.rb', line 32

def trailing?
  edge == :trailing
end