Class: Rbs::Merge::ConflictResolver
- Inherits:
-
Ast::Merge::ConflictResolverBase
- Object
- Ast::Merge::ConflictResolverBase
- Rbs::Merge::ConflictResolver
- Defined in:
- lib/rbs/merge/conflict_resolver.rb
Overview
Resolves conflicts between template and destination declarations. Determines which version to use when both files have declarations with matching signatures but different content.
Instance Method Summary collapse
-
#can_recursive_merge?(template_decl, dest_decl) ⇒ Boolean
Check if declarations can be recursively merged.
-
#declarations_identical?(decl1, decl2) ⇒ Boolean
Check if two declarations are identical.
-
#initialize(preference:, template_analysis:, dest_analysis:) ⇒ ConflictResolver
constructor
Initialize a conflict resolver.
-
#resolve(template_decl, dest_decl, template_index:, dest_index:) ⇒ Hash
Resolve a conflict between template and destination declarations.
Constructor Details
#initialize(preference:, template_analysis:, dest_analysis:) ⇒ ConflictResolver
Initialize a conflict resolver
22 23 24 25 26 27 28 29 |
# File 'lib/rbs/merge/conflict_resolver.rb', line 22 def initialize(preference:, template_analysis:, dest_analysis:) super( strategy: :node, preference: preference, template_analysis: template_analysis, dest_analysis: dest_analysis ) end |
Instance Method Details
#can_recursive_merge?(template_decl, dest_decl) ⇒ Boolean
Check if declarations can be recursively merged
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/rbs/merge/conflict_resolver.rb', line 82 def can_recursive_merge?(template_decl, dest_decl) # Only container types can be recursively merged container_types = [ RBS::AST::Declarations::Class, RBS::AST::Declarations::Module, RBS::AST::Declarations::Interface, ] template_decl.class == dest_decl.class && container_types.any? { |type| template_decl.is_a?(type) } && template_decl.respond_to?(:members) && dest_decl.respond_to?(:members) && template_decl.members.any? && dest_decl.members.any? end |
#declarations_identical?(decl1, decl2) ⇒ Boolean
Check if two declarations are identical
73 74 75 76 |
# File 'lib/rbs/merge/conflict_resolver.rb', line 73 def declarations_identical?(decl1, decl2) # Use RBS's built-in equality decl1 == decl2 end |
#resolve(template_decl, dest_decl, template_index:, dest_index:) ⇒ Hash
Resolve a conflict between template and destination declarations
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 |
# File 'lib/rbs/merge/conflict_resolver.rb', line 38 def resolve(template_decl, dest_decl, template_index:, dest_index:) # Freeze blocks always win (they represent protected content) if freeze_node?(dest_decl) return {source: :destination, declaration: dest_decl, decision: DECISION_FREEZE_BLOCK} end # Check if declarations are identical if declarations_identical?(template_decl, dest_decl) # Prefer destination to minimize diffs return {source: :destination, declaration: dest_decl, decision: DECISION_DESTINATION} end # Check if we should recursively merge (for container types) if can_recursive_merge?(template_decl, dest_decl) return { source: :recursive, template_declaration: template_decl, dest_declaration: dest_decl, decision: DECISION_RECURSIVE, } end # Apply preference case @preference when :template {source: :template, declaration: template_decl, decision: DECISION_TEMPLATE} else # :destination (validated in initialize) {source: :destination, declaration: dest_decl, decision: DECISION_DESTINATION} end end |