diff --git a/bin/tests/scenarios/fancy_argument_types_matching_issue/merge.java b/bin/tests/scenarios/fancy_argument_types_matching_issue/merge.java index 229dfeb..9d2a8a6 100644 --- a/bin/tests/scenarios/fancy_argument_types_matching_issue/merge.java +++ b/bin/tests/scenarios/fancy_argument_types_matching_issue/merge.java @@ -1 +1 @@ -package de . fosd . jdime . common ; import AST . * ; import de . fosd . jdime . common . operations . ConflictOperation ; import de . fosd . jdime . common . operations . AddOperation ; public class ASTNodeArtifact extends Artifact < ASTNodeArtifact > { private ASTNodeArtifact ( final ASTNode < ? > astnode ) { assert ( astnode != null ) ; this . astnode = astnode ; this . initializeChildren ( ) ; } public ASTNodeArtifact ( final FileArtifact artifact ) { assert ( artifact != null ) ; setRevision ( artifact . getRevision ( ) ) ; ASTNode < ? > astnode ; if ( artifact . isEmpty ( ) ) { astnode = new ASTNode < > ( ) ; } else { Program p = initProgram ( ) ; p . addSourceFile ( artifact . getPath ( ) ) ; astnode = p ; } this . astnode = astnode ; this . initializeChildren ( ) ; renumberTree ( ) ; } } \ No newline at end of file + package de . fosd . jdime . common ; import AST . * ; import de . fosd . jdime . common . operations . ConflictOperation ; import de . fosd . jdime . common . operations . AddOperation ; public class ASTNodeArtifact extends Artifact < ASTNodeArtifact > { private ASTNodeArtifact ( final ASTNode < ? > astnode ) { assert ( astnode != null ) ; this . astnode = astnode ; this . initializeChildren ( ) ; } public ASTNodeArtifact ( final FileArtifact artifact ) { assert ( artifact != null ) ; setRevision ( artifact . getRevision ( ) ) ; ASTNode < ? > astnode ; if ( artifact . isEmpty ( ) ) { astnode = new ASTNode < > ( ) ; } else { Program p = initProgram ( ) ; p . addSourceFile ( artifact . getPath ( ) ) ; astnode = p ; } this . astnode = astnode ; this . initializeChildren ( ) ; renumberTree ( ) ; } } \ No newline at end of file diff --git a/bin/tests/scenarios/import_declarations_grouping_node/merge.java b/bin/tests/scenarios/import_declarations_grouping_node/merge.java index 1fa543b..7c32aad 100644 --- a/bin/tests/scenarios/import_declarations_grouping_node/merge.java +++ b/bin/tests/scenarios/import_declarations_grouping_node/merge.java @@ -1 +1 @@ -package br . fosd . jdime . stats ; import java . text . DecimalFormat ; import java . util . HashMap ; import java . util . TreeSet ; import de . fosd . jdime . common . LangElem ; import java . util . logging . Level ; import java . util . logging . Logger ; public class ASTStats { } \ No newline at end of file + package br . fosd . jdime . stats ; import java . text . DecimalFormat ; import java . util . HashMap ; import java . util . TreeSet ; import de . fosd . jdime . common . LangElem ; import java . util . logging . Level ; import java . util . logging . Logger ; public class ASTStats { } \ No newline at end of file diff --git a/bin/tests/scenarios/imports_are_merged_correctly/merge.java b/bin/tests/scenarios/imports_are_merged_correctly/merge.java index 51b0a11..34aa9a3 100644 --- a/bin/tests/scenarios/imports_are_merged_correctly/merge.java +++ b/bin/tests/scenarios/imports_are_merged_correctly/merge.java @@ -1 +1 @@ -package de . fosd . jdime . merge ; import java . util . List ; import AST . * ; import de . fosd . jdime . operations . AddOperation ; import de . fosd . jdime . operations . ConflictOperation ; import de . fosd . jdime . operations . MergeOperation ; import static de . fosd . jdime . artifact . Artifacts . root ; import static de . fosd . jdime . strdump . DumpMode . PLAINTEXT_TREE ; \ No newline at end of file + package de . fosd . jdime . merge ; import java . util . List ; import AST . * ; import de . fosd . jdime . operations . AddOperation ; import de . fosd . jdime . operations . ConflictOperation ; import de . fosd . jdime . operations . MergeOperation ; import static de . fosd . jdime . artifact . Artifacts . root ; import static de . fosd . jdime . strdump . DumpMode . PLAINTEXT_TREE ; \ No newline at end of file diff --git a/bin/tests/scenarios/jdime_matching_issue/merge.java b/bin/tests/scenarios/jdime_matching_issue/merge.java index fece629..291b7fe 100644 --- a/bin/tests/scenarios/jdime_matching_issue/merge.java +++ b/bin/tests/scenarios/jdime_matching_issue/merge.java @@ -1 +1 @@ -package de . fosd . jdime . artifact ; import java . security . MessageDigest ; public abstract class Artifact < T extends Artifact < T > > implements Comparable < T > , StatisticsInterface { public boolean hasChanges ( Revision revision ) { if ( this . revision . equals ( revision ) ) { return false ; } if ( ! hasMatching ( revision ) ) { return true ; } T match = getMatching ( revision ) . getMatchingArtifact ( this ) ; return getTreeSize ( ) != match . getTreeSize ( ) || ! getTreeHash ( ) . equals ( match . getTreeHash ( ) ) ; } } \ No newline at end of file + package de . fosd . jdime . artifact ; import java . security . MessageDigest ; public abstract class Artifact < T extends Artifact < T > > implements Comparable < T > , StatisticsInterface { public boolean hasChanges ( Revision revision ) { if ( this . revision . equals ( revision ) ) { return false ; } if ( ! hasMatching ( revision ) ) { return true ; } T match = getMatching ( revision ) . getMatchingArtifact ( this ) ; return getTreeSize ( ) != match . getTreeSize ( ) || ! getTreeHash ( ) . equals ( match . getTreeHash ( ) ) ; } } \ No newline at end of file diff --git a/bin/tests/scenarios/left_deletes_changed_node_in_right/merge.java b/bin/tests/scenarios/left_deletes_changed_node_in_right/merge.java index e593c02..6819519 100644 --- a/bin/tests/scenarios/left_deletes_changed_node_in_right/merge.java +++ b/bin/tests/scenarios/left_deletes_changed_node_in_right/merge.java @@ -1 +1,6 @@ - class Test { <<<<<<<<< ========= public static void main ( ) { System . out . println ( "Hello, Joao!" ) ; } >>>>>>>>> } \ No newline at end of file + class Test { +<<<<<<<<< +========= + public static void main ( ) { System . out . println ( "Hello, Joao!" ) ; } +>>>>>>>>> + } \ No newline at end of file diff --git a/bin/tests/scenarios/overload_methods_with_spread_parameter/merge.java b/bin/tests/scenarios/overload_methods_with_spread_parameter/merge.java index 0ec2e12..542a791 100644 --- a/bin/tests/scenarios/overload_methods_with_spread_parameter/merge.java +++ b/bin/tests/scenarios/overload_methods_with_spread_parameter/merge.java @@ -1 +1 @@ -package de . fosd . jdime ; import java . io . File ; import java . net . URISyntaxException ; import java . net . URL ; import java . util . Arrays ; import org . junit . BeforeClass ; import static org . junit . Assert . assertNotNull ; import static org . junit . Assert . assertTrue ; import static org . junit . Assert . fail ; public class JDimeTest { protected static File file ( File parent , String child ) { File f = new File ( parent , child ) ; assertTrue ( f + " does not exist." , f . exists ( ) ) ; return f ; } protected static File file ( File parent , String name , String ... names ) { if ( names != null ) { String path = String . format ( "%s/%s" , name , String . join ( "/" , names ) ) ; return file ( parent , path ) ; } else { return file ( parent , name ) ; } } protected static File file ( String path ) { URL res = JDimeTest . class . getResource ( path ) ; assertNotNull ( "The file " + path + " was not found." , res ) ; try { return new File ( res . toURI ( ) ) ; } catch ( URISyntaxException e ) { fail ( e . getMessage ( ) ) ; return null ; } } protected static File file ( String name , String ... names ) { if ( names != null ) { String path = String . format ( "/%s/%s" , name , String . join ( "/" , names ) ) ; return file ( path ) ; } else { return file ( "/" + name ) ; } } } \ No newline at end of file + package de . fosd . jdime ; import java . io . File ; import java . net . URISyntaxException ; import java . net . URL ; import java . util . Arrays ; import org . junit . BeforeClass ; import static org . junit . Assert . assertNotNull ; import static org . junit . Assert . assertTrue ; import static org . junit . Assert . fail ; public class JDimeTest { protected static File file ( File parent , String child ) { File f = new File ( parent , child ) ; assertTrue ( f + " does not exist." , f . exists ( ) ) ; return f ; } protected static File file ( File parent , String name , String ... names ) { if ( names != null ) { String path = String . format ( "%s/%s" , name , String . join ( "/" , names ) ) ; return file ( parent , path ) ; } else { return file ( parent , name ) ; } } protected static File file ( String path ) { URL res = JDimeTest . class . getResource ( path ) ; assertNotNull ( "The file " + path + " was not found." , res ) ; try { return new File ( res . toURI ( ) ) ; } catch ( URISyntaxException e ) { fail ( e . getMessage ( ) ) ; return null ; } } protected static File file ( String name , String ... names ) { if ( names != null ) { String path = String . format ( "/%s/%s" , name , String . join ( "/" , names ) ) ; return file ( path ) ; } else { return file ( "/" + name ) ; } } } \ No newline at end of file diff --git a/bin/tests/scenarios/right_deletes_changed_node_in_left/merge.java b/bin/tests/scenarios/right_deletes_changed_node_in_left/merge.java index b394407..5766785 100644 --- a/bin/tests/scenarios/right_deletes_changed_node_in_left/merge.java +++ b/bin/tests/scenarios/right_deletes_changed_node_in_left/merge.java @@ -1 +1,6 @@ - class Test { <<<<<<<<< public static void main ( ) { System . out . println ( "Hello, Joao!" ) ; } ========= >>>>>>>>> } \ No newline at end of file + class Test { +<<<<<<<<< + public static void main ( ) { System . out . println ( "Hello, Joao!" ) ; } +========= +>>>>>>>>> + } \ No newline at end of file diff --git a/bin/tests/scenarios/semi_structured/merge.java b/bin/tests/scenarios/semi_structured/merge.java index 3faf0ae..9f6ba0a 100644 --- a/bin/tests/scenarios/semi_structured/merge.java +++ b/bin/tests/scenarios/semi_structured/merge.java @@ -1 +1,7 @@ - public class Test { long fibo ( int n ) { if ( n < 2 ) { return n ; } else { return fibo ( n - 1 ) + fibo ( n - 2 ) ; } } int calc ( int a , int b ) { return a <<<<<<<<< + ========= * >>>>>>>>> b ; } } \ No newline at end of file + public class Test { long fibo ( int n ) { if ( n < 2 ) { return n ; } else { return fibo ( n - 1 ) + fibo ( n - 2 ) ; } } int calc ( int a , int b ) { return a +<<<<<<<<< ++ +========= +* +>>>>>>>>> + b ; } } \ No newline at end of file diff --git a/bin/tests/scenarios/smoke_java/merge.java b/bin/tests/scenarios/smoke_java/merge.java index 6ac5efa..fd9fb86 100644 --- a/bin/tests/scenarios/smoke_java/merge.java +++ b/bin/tests/scenarios/smoke_java/merge.java @@ -1 +1,13 @@ - public class Main { void delete ( Pessoa pessoa ) ; void create ( Pessoa pessoa ) ; public static void main ( String [ ] args ) { int x = 0 ; System . out . println ( <<<<<<<<< "Hello, João!" ========= "Hello, Paulo!" >>>>>>>>> ) ; int y = <<<<<<<<< 3 ========= 5 >>>>>>>>> ; } void upsert ( Pessoa pessoa ) ; } \ No newline at end of file + public class Main { void delete ( Pessoa pessoa ) ; void create ( Pessoa pessoa ) ; public static void main ( String [ ] args ) { int x = 0 ; System . out . println ( +<<<<<<<<< +"Hello, João!" +========= +"Hello, Paulo!" +>>>>>>>>> + ) ; int y = +<<<<<<<<< +3 +========= +5 +>>>>>>>>> + ; } void upsert ( Pessoa pessoa ) ; } \ No newline at end of file diff --git a/bin/tests/scenarios/unordered_with_non_labelled/merge.java b/bin/tests/scenarios/unordered_with_non_labelled/merge.java index 263386c..b316949 100644 --- a/bin/tests/scenarios/unordered_with_non_labelled/merge.java +++ b/bin/tests/scenarios/unordered_with_non_labelled/merge.java @@ -1 +1,13 @@ - public class Main { static { int <<<<<<<<< x ========= y >>>>>>>>> = <<<<<<<<< 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" ) ; } } + public class Main { static { int +<<<<<<<<< +x +========= +y +>>>>>>>>> + = +<<<<<<<<< +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 diff --git a/merge/src/merged_cst_node.rs b/merge/src/merged_cst_node.rs index 8778415..78a670e 100644 --- a/merge/src/merged_cst_node.rs +++ b/merge/src/merged_cst_node.rs @@ -63,15 +63,28 @@ impl Display for MergedCSTNode<'_> { } MergedCSTNode::Conflict { left, right } => match (left, right) { (Some(left), Some(right)) => { - write!(f, "<<<<<<<<< {} ========= {} >>>>>>>>>", left, right) + writeln!(f)?; + writeln!(f, "<<<<<<<<<")?; + writeln!(f, "{}", left)?; + writeln!(f, "=========")?; + writeln!(f, "{}", right)?; + writeln!(f, ">>>>>>>>>") } (Some(left), None) => { - write!(f, "<<<<<<<<< {} ========= >>>>>>>>>", left) + writeln!(f)?; + writeln!(f, "<<<<<<<<<")?; + writeln!(f, "{}", left)?; + writeln!(f, "=========")?; + writeln!(f, ">>>>>>>>>") } (None, Some(right)) => { - write!(f, "<<<<<<<<< ========= {} >>>>>>>>>", right) + writeln!(f)?; + writeln!(f, "<<<<<<<<<")?; + writeln!(f, "=========")?; + writeln!(f, "{}", right)?; + writeln!(f, ">>>>>>>>>") } - (None, None) => panic!("Invalid conflict provided"), + (None, None) => unreachable!("Invalid conflict provided"), }, } }