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:, node_typing: nil, **options) ⇒ 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:, node_typing: nil, **options) ⇒ ConflictResolver
Initialize a conflict resolver
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rbs/merge/conflict_resolver.rb', line 26 def initialize(preference:, template_analysis:, dest_analysis:, node_typing: nil, **) super( strategy: :node, preference: preference, template_analysis: template_analysis, dest_analysis: dest_analysis, ** ) @node_typing = node_typing end |
Instance Method Details
#can_recursive_merge?(template_decl, dest_decl) ⇒ Boolean
Check if declarations can be recursively merged
98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/rbs/merge/conflict_resolver.rb', line 98 def can_recursive_merge?(template_decl, dest_decl) # Only container types can be recursively merged # Container types are: class, module, interface template_type = canonical_type(template_decl) dest_type = canonical_type(dest_decl) # Both must be the same container type return false unless template_type == dest_type return false unless NodeTypeNormalizer.container_type?(template_type) # Both must have members has_members?(template_decl) && has_members?(dest_decl) end |
#declarations_identical?(decl1, decl2) ⇒ Boolean
Check if two declarations are identical
85 86 87 88 89 90 91 92 |
# File 'lib/rbs/merge/conflict_resolver.rb', line 85 def declarations_identical?(decl1, decl2) # Compare text content for backend-agnostic comparison text1 = extract_declaration_text(decl1, @template_analysis) text2 = extract_declaration_text(decl2, @dest_analysis) # Normalize whitespace for comparison normalize_text(text1) == normalize_text(text2) end |
#resolve(template_decl, dest_decl, template_index:, dest_index:) ⇒ Hash
Resolve a conflict between template and destination declarations
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/rbs/merge/conflict_resolver.rb', line 44 def resolve(template_decl, dest_decl, template_index:, dest_index:) # Freeze blocks always win (they represent protected content) # Template freeze blocks take precedence - frozen content from template is preserved if freeze_node?(template_decl) return {source: :template, declaration: template_decl, decision: DECISION_FREEZE_BLOCK} end # Destination freeze blocks also win (though less common) 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 (supports per-node-type preferences with node_typing) case resolve_preference(template_decl, dest_decl) 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 |