Class: Ast::Merge::Text::ConflictResolver

Inherits:
ConflictResolverBase show all
Includes:
Ast::Merge::TrailingGroups::DestIterate
Defined in:
lib/ast/merge/text/conflict_resolver.rb

Overview

Conflict resolver for text-based AST merging.

Uses content-based matching with destination-order preservation:

  1. Lines are matched by normalized content (whitespace-trimmed)
  2. Destination order is preserved (destination is source of truth for structure)
  3. Template-only lines are optionally inserted in template order relative to their matched anchors
  4. Freeze blocks are always preserved from destination

Examples:

resolver = ConflictResolver.new(template_analysis, dest_analysis)
result = MergeResult.new
resolver.resolve(result)

Constant Summary

Constants inherited from ConflictResolverBase

ConflictResolverBase::DECISION_ADDED, ConflictResolverBase::DECISION_APPENDED, ConflictResolverBase::DECISION_DESTINATION, ConflictResolverBase::DECISION_FREEZE_BLOCK, ConflictResolverBase::DECISION_FROZEN, ConflictResolverBase::DECISION_IDENTICAL, ConflictResolverBase::DECISION_KEPT_DEST, ConflictResolverBase::DECISION_KEPT_TEMPLATE, ConflictResolverBase::DECISION_RECURSIVE, ConflictResolverBase::DECISION_REPLACED, ConflictResolverBase::DECISION_TEMPLATE

Instance Attribute Summary

Attributes inherited from ConflictResolverBase

#add_template_only_nodes, #dest_analysis, #match_refiner, #preference, #recursive, #remove_template_missing_nodes, #strategy, #template_analysis

Instance Method Summary collapse

Methods included from Ast::Merge::TrailingGroups::DestIterate

#build_dest_iterate_trailing_groups, #emit_prefix_trailing_group

Methods included from Ast::Merge::TrailingGroups::Core

#build_trailing_groups, #emit_remaining_trailing_groups, #flush_ready_trailing_groups

Methods inherited from ConflictResolverBase

#default_preference, #freeze_node?, #per_type_preference?, #preference_for_node, #resolve

Constructor Details

#initialize(template_analysis, dest_analysis, preference: :destination, add_template_only_nodes: false, resolution_mode: :eager, unresolved_policy: nil) ⇒ ConflictResolver

Initialize the conflict resolver

Parameters:

  • template_analysis (FileAnalysis)

    Analysis of template

  • dest_analysis (FileAnalysis)

    Analysis of destination

  • preference (Symbol) (defaults to: :destination)

    :destination or :template

  • add_template_only_nodes (Boolean) (defaults to: false)

    Whether to add template-only lines



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ast/merge/text/conflict_resolver.rb', line 28

def initialize(
  template_analysis,
  dest_analysis,
  preference: :destination,
  add_template_only_nodes: false,
  resolution_mode: :eager,
  unresolved_policy: nil
)
  super(
    strategy: :batch,
    preference: preference,
    template_analysis: template_analysis,
    dest_analysis: dest_analysis,
    add_template_only_nodes: add_template_only_nodes
  )
  @resolution_mode = resolution_mode
  @unresolved_policy = Ast::Merge::UnresolvedPolicy.coerce(unresolved_policy)
end