diff --git a/bin/src/control.rs b/bin/src/control.rs index 036e855..3ce6d5f 100644 --- a/bin/src/control.rs +++ b/bin/src/control.rs @@ -50,10 +50,12 @@ pub fn run_tool_on_merge_scenario( right: &str, ) -> Result { if base == left { + log::info!("Early returning because base equals left"); return Ok(ExecutionResult::WithoutConflicts(right.to_string())); } if base == right { + log::info!("Early returning because base equals right"); return Ok(ExecutionResult::WithoutConflicts(left.to_string())); } diff --git a/bin/tests/scenarios/unordered_with_non_labelled/merge.java b/bin/tests/scenarios/unordered_with_non_labelled/merge.java index 1fb9389..ce9067a 100644 --- a/bin/tests/scenarios/unordered_with_non_labelled/merge.java +++ b/bin/tests/scenarios/unordered_with_non_labelled/merge.java @@ -1,13 +1,7 @@ - public class Main { static { int + public class Main { static { int <<<<<<< -x + x = 0 ======= -y + y = 2 >>>>>>> - = -<<<<<<< -0 -======= -2 ->>>>>>> - ; } static { System . out . println ( "I'm a static block" ) ; } public Main ( ) { System . out . println ( "I'm a constructor" ) ; int y = 3 ; } static { System . out . println ( "I don't know what's going on" ) ; } } \ No newline at end of file + ; } static { System . out . println ( "I'm a static block" ) ; } public Main ( ) { System . out . println ( "I'm a constructor" ) ; int y = 3 ; } static { System . out . println ( "I don't know what's going on" ) ; } } diff --git a/merge/src/ordered_merge.rs b/merge/src/ordered_merge.rs index befa450..5314bde 100644 --- a/merge/src/ordered_merge.rs +++ b/merge/src/ordered_merge.rs @@ -42,9 +42,9 @@ pub fn ordered_merge<'a>( right_matching_in_left, matching_base_right, ) { - (true, Some(_), Some(_), Some(_), Some(_)) => { + (true, Some(_), Some(matching_base_left), Some(_), Some(_)) => { result_children.push(crate::merge( - cur_left, + matching_base_left.matching_node, cur_left, cur_right, base_left_matchings, @@ -68,6 +68,32 @@ pub fn ordered_merge<'a>( cur_left_option = children_left_it.next(); cur_right_option = children_right_it.next(); } + (true, Some(_), Some(matching_base_left), Some(_), None) => { + result_children.push(crate::merge( + matching_base_left.matching_node, + cur_left, + cur_right, + base_left_matchings, + base_right_matchings, + left_right_matchings, + )?); + + cur_left_option = children_left_it.next(); + cur_right_option = children_right_it.next(); + } + (true, Some(_), None, Some(_), Some(matching_base_right)) => { + result_children.push(crate::merge( + matching_base_right.matching_node, + cur_left, + cur_right, + base_left_matchings, + base_right_matchings, + left_right_matchings, + )?); + + cur_left_option = children_left_it.next(); + cur_right_option = children_right_it.next(); + } (false, Some(_), Some(_), None, Some(matching_base_right)) => { if !matching_base_right.is_perfect_match { result_children.push(MergedCSTNode::Conflict { @@ -182,13 +208,36 @@ pub fn ordered_merge<'a>( cur_right_option = children_right_it.next(); } (a, b, c, d, e) => { - return Err(MergeError::InvalidMatchingConfiguration( + log::warn!( + "Reached an Invalid Matching Configuration. {} {} {} {} {}", a, b.is_some(), c.is_some(), d.is_some(), - e.is_some(), - )); + e.is_some() + ); + log::debug!( + "Involved nodes {} AND {}", + cur_left.contents(), + cur_right.contents() + ); + log::debug!( + "Involved nodes parents {} AND {}", + left.contents(), + right.contents() + ); + + if cur_left.contents() == cur_right.contents() { + result_children.push(cur_left.into()) + } else { + result_children.push(MergedCSTNode::Conflict { + left: Some(Box::new(cur_left.into())), + right: Some(Box::new(cur_right.into())), + }) + } + + cur_left_option = children_left_it.next(); + cur_right_option = children_right_it.next(); } } } diff --git a/parsing/src/tree_sitter_parser.rs b/parsing/src/tree_sitter_parser.rs index 9f697a9..c3b1945 100644 --- a/parsing/src/tree_sitter_parser.rs +++ b/parsing/src/tree_sitter_parser.rs @@ -82,6 +82,14 @@ impl From for ParserConfiguration { tree_sitter_java::language(), )), ); + + map.insert( + "variable_declarator", + Box::new(TreeSitterQuery::new( + r#"(variable_declarator (identifier) @name)"#, + tree_sitter_java::language(), + )), + ); map }, },