-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(parsing_handlers): Add handler to remove comments from merged trees
- Loading branch information
Showing
6 changed files
with
663 additions
and
1 deletion.
There are no files selected for viewing
181 changes: 181 additions & 0 deletions
181
bin/tests/scenarios/broken-matching-due-to-comments/base.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
package br.ufpe.cin.mergers.util; | ||
|
||
import java.io.File; | ||
|
||
import br.ufpe.cin.app.JFSTMerge; | ||
import br.ufpe.cin.files.FilesManager; | ||
import de.ovgu.cide.fstgen.ast.FSTNode; | ||
import de.ovgu.cide.fstgen.ast.FSTNonTerminal; | ||
import de.ovgu.cide.fstgen.ast.FSTTerminal; | ||
|
||
/** | ||
* Class representing a textual merge conflict. | ||
* | ||
* @author Guilherme | ||
*/ | ||
|
||
public class MergeConflict { | ||
|
||
private final String left; | ||
private final String base; | ||
private final String right; | ||
private final String body; | ||
private final String message; | ||
|
||
private int startLOC; | ||
private int endLOC; | ||
|
||
private File leftOriginFile; | ||
private File baseOriginFile; | ||
private File rightOriginFile; | ||
|
||
private String fullyQualifiedMergedClass; | ||
|
||
public static final String MINE_CONFLICT_MARKER = "<<<<<<< MINE"; | ||
public static final String BASE_CONFLICT_MARKER = "||||||| BASE"; | ||
public static final String CHANGE_CONFLICT_MARKER = "======="; | ||
public static final String YOURS_CONFLICT_MARKER = ">>>>>>> YOURS"; | ||
|
||
public MergeConflict(FSTNode left, FSTNode base, FSTNode right) { | ||
this.left = getNodeContent(left); | ||
this.base = getNodeContent(base); | ||
this.right = getNodeContent(right); | ||
this.message = ""; | ||
this.body = assembleBody(); | ||
} | ||
|
||
private String getNodeContent(FSTNode node) { | ||
if (node == null) { | ||
return ""; | ||
} else if (node instanceof FSTTerminal) { | ||
return IndentationUtils.indentFirstLine((FSTTerminal) node); | ||
} else { | ||
return FilesManager.prettyPrint((FSTNonTerminal) node); | ||
} | ||
} | ||
|
||
private String assembleBody() { | ||
StringBuilder conflict = new StringBuilder(); | ||
conflict.append(MINE_CONFLICT_MARKER) | ||
.append('\n') | ||
.append(left) | ||
.append('\n'); | ||
if(JFSTMerge.showBase) { | ||
conflict.append(BASE_CONFLICT_MARKER) | ||
.append('\n'); | ||
} | ||
conflict.append(CHANGE_CONFLICT_MARKER) | ||
.append(" " + message) | ||
.append('\n') | ||
.append(right) | ||
.append('\n') | ||
.append(YOURS_CONFLICT_MARKER); | ||
return conflict.toString(); | ||
} | ||
|
||
public MergeConflict(FSTTerminal left, FSTTerminal base, FSTTerminal right, int startLOC, int endLOC) { | ||
this(left, base, right); | ||
this.startLOC = startLOC; | ||
this.endLOC = endLOC; | ||
} | ||
|
||
public MergeConflict(String left, String base, String right) { | ||
this.left = left; | ||
this.base = base; | ||
this.right = right; | ||
this.message = ""; | ||
this.body = assembleBody(); | ||
} | ||
|
||
public MergeConflict(String left, String base, String right, int startLOC, int endLOC) { | ||
this(left, base, right); | ||
this.startLOC = startLOC; | ||
this.endLOC = endLOC; | ||
} | ||
|
||
public boolean contains(String leftPattern, String rightPattern) { | ||
if (leftPattern.isEmpty() || rightPattern.isEmpty()) { | ||
return false; | ||
} else { | ||
leftPattern = (leftPattern.replaceAll("\\r\\n|\\r|\\n", "")).replaceAll("\\s+", ""); | ||
rightPattern = (rightPattern.replaceAll("\\r\\n|\\r|\\n", "")).replaceAll("\\s+", ""); | ||
String lefttrim = (this.left.replaceAll("\\r\\n|\\r|\\n", "")).replaceAll("\\s+", ""); | ||
String righttrim = (this.right.replaceAll("\\r\\n|\\r|\\n", "")).replaceAll("\\s+", ""); | ||
return (lefttrim.contains(leftPattern) && righttrim.contains(rightPattern)); | ||
} | ||
} | ||
|
||
public void setOriginFiles(File left, File base, File right) { | ||
this.leftOriginFile = left; | ||
this.rightOriginFile = right; | ||
this.baseOriginFile = base; | ||
} | ||
|
||
public String getFullyQualifiedMergedClass() { | ||
return fullyQualifiedMergedClass; | ||
} | ||
|
||
public void setFullyQualifiedMergedClass(String fullyQualifiedMergedClass) { | ||
this.fullyQualifiedMergedClass = fullyQualifiedMergedClass; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return this.body; | ||
} | ||
|
||
/** | ||
* @return the LEFT conflicting content | ||
*/ | ||
public String getLeft() { | ||
return left; | ||
} | ||
|
||
/** | ||
* @return the BASE conflicting content | ||
*/ | ||
public String getBase() { | ||
return base; | ||
} | ||
|
||
/** | ||
* @return the YOURS conflicting content | ||
*/ | ||
public String getRight() { | ||
return right; | ||
} | ||
|
||
/** | ||
* @return the startLOC of the conflict | ||
*/ | ||
public int getStartLOC() { | ||
return startLOC; | ||
} | ||
|
||
/** | ||
* @return the endLOC | ||
*/ | ||
public int getEndLOC() { | ||
return endLOC; | ||
} | ||
|
||
/* | ||
* public boolean containsRelaxed(String leftPattern, String rightPattern){ | ||
* if(leftPattern.isEmpty() || rightPattern.isEmpty()){ return false; } else { | ||
* leftPattern = | ||
* (leftPattern.replaceAll("\\r\\n|\\r|\\n","")).replaceAll("\\s+",""); | ||
* rightPattern = | ||
* (rightPattern.replaceAll("\\r\\n|\\r|\\n","")).replaceAll("\\s+",""); String | ||
* lefttrim = (this.left.replaceAll("\\r\\n|\\r|\\n","")).replaceAll("\\s+",""); | ||
* String righttrim = | ||
* (this.right.replaceAll("\\r\\n|\\r|\\n","")).replaceAll("\\s+",""); | ||
* | ||
* leftPattern = Util.removeReservedKeywords(leftPattern); rightPattern = | ||
* Util.removeReservedKeywords(rightPattern); lefttrim = | ||
* Util.removeReservedKeywords(lefttrim); righttrim = | ||
* Util.removeReservedKeywords(righttrim); | ||
* | ||
* return (lefttrim.contains(leftPattern) && righttrim.contains(rightPattern)); | ||
* } } | ||
*/ | ||
} |
189 changes: 189 additions & 0 deletions
189
bin/tests/scenarios/broken-matching-due-to-comments/left.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
package br.ufpe.cin.mergers.util; | ||
|
||
import java.io.File; | ||
|
||
import br.ufpe.cin.app.JFSTMerge; | ||
import br.ufpe.cin.files.FilesManager; | ||
import de.ovgu.cide.fstgen.ast.FSTNode; | ||
import de.ovgu.cide.fstgen.ast.FSTNonTerminal; | ||
import de.ovgu.cide.fstgen.ast.FSTTerminal; | ||
|
||
/** | ||
* Class representing a textual merge conflict. | ||
* | ||
* @author Guilherme | ||
*/ | ||
|
||
public class MergeConflict { | ||
|
||
private final String left; | ||
private final String base; | ||
private final String right; | ||
private final String body; | ||
private final String message; | ||
|
||
private int startLOC; | ||
private int endLOC; | ||
|
||
private File leftOriginFile; | ||
private File baseOriginFile; | ||
private File rightOriginFile; | ||
|
||
private String fullyQualifiedMergedClass; | ||
|
||
public static final String MINE_CONFLICT_MARKER = "<<<<<<< MINE"; | ||
public static final String BASE_CONFLICT_MARKER = "||||||| BASE"; | ||
public static final String CHANGE_CONFLICT_MARKER = "======="; | ||
public static final String YOURS_CONFLICT_MARKER = ">>>>>>> YOURS"; | ||
|
||
public MergeConflict(FSTNode left, FSTNode base, FSTNode right) { | ||
this.left = getNodeContent(left); | ||
this.base = getNodeContent(base); | ||
this.right = getNodeContent(right); | ||
this.message = ""; | ||
this.body = assembleBody(); | ||
} | ||
|
||
private String getNodeContent(FSTNode node) { | ||
if (node == null) { | ||
return ""; | ||
} else if (node instanceof FSTTerminal) { | ||
return IndentationUtils.indentFirstLine((FSTTerminal) node); | ||
} else { | ||
return FilesManager.prettyPrint((FSTNonTerminal) node); | ||
} | ||
} | ||
|
||
private String assembleBody() { | ||
StringBuilder conflict = new StringBuilder(); | ||
conflict.append(MINE_CONFLICT_MARKER) | ||
.append('\n') | ||
.append(left) | ||
.append('\n'); | ||
if(JFSTMerge.showBase) { | ||
conflict.append(BASE_CONFLICT_MARKER) | ||
.append('\n'); | ||
} | ||
conflict.append(CHANGE_CONFLICT_MARKER) | ||
.append(" " + message) | ||
.append('\n') | ||
.append(right) | ||
.append('\n') | ||
.append(YOURS_CONFLICT_MARKER); | ||
return conflict.toString(); | ||
} | ||
|
||
public MergeConflict(FSTTerminal left, FSTTerminal base, FSTTerminal right, int startLOC, int endLOC) { | ||
this(left, base, right); | ||
this.startLOC = startLOC; | ||
this.endLOC = endLOC; | ||
} | ||
|
||
public MergeConflict(String left, String base, String right) { | ||
this.left = left; | ||
this.base = base; | ||
this.right = right; | ||
this.message = ""; | ||
this.body = assembleBody(); | ||
} | ||
|
||
public MergeConflict(String left, String base, String right, String message) { | ||
this.left = left; | ||
this.base = base; | ||
this.right = right; | ||
this.message = message; | ||
this.body = assembleBody(); | ||
} | ||
|
||
public MergeConflict(String left, String base, String right, int startLOC, int endLOC) { | ||
this(left, base, right); | ||
this.startLOC = startLOC; | ||
this.endLOC = endLOC; | ||
} | ||
|
||
public boolean contains(String leftPattern, String rightPattern) { | ||
if (leftPattern.isEmpty() || rightPattern.isEmpty()) { | ||
return false; | ||
} else { | ||
leftPattern = (leftPattern.replaceAll("\\r\\n|\\r|\\n", "")).replaceAll("\\s+", ""); | ||
rightPattern = (rightPattern.replaceAll("\\r\\n|\\r|\\n", "")).replaceAll("\\s+", ""); | ||
String lefttrim = (this.left.replaceAll("\\r\\n|\\r|\\n", "")).replaceAll("\\s+", ""); | ||
String righttrim = (this.right.replaceAll("\\r\\n|\\r|\\n", "")).replaceAll("\\s+", ""); | ||
return (lefttrim.contains(leftPattern) && righttrim.contains(rightPattern)); | ||
} | ||
} | ||
|
||
public void setOriginFiles(File left, File base, File right) { | ||
this.leftOriginFile = left; | ||
this.rightOriginFile = right; | ||
this.baseOriginFile = base; | ||
} | ||
|
||
public String getFullyQualifiedMergedClass() { | ||
return fullyQualifiedMergedClass; | ||
} | ||
|
||
public void setFullyQualifiedMergedClass(String fullyQualifiedMergedClass) { | ||
this.fullyQualifiedMergedClass = fullyQualifiedMergedClass; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return this.body; | ||
} | ||
|
||
/** | ||
* @return the LEFT conflicting content | ||
*/ | ||
public String getLeft() { | ||
return left; | ||
} | ||
|
||
/** | ||
* @return the BASE conflicting content | ||
*/ | ||
public String getBase() { | ||
return base; | ||
} | ||
|
||
/** | ||
* @return the YOURS conflicting content | ||
*/ | ||
public String getRight() { | ||
return right; | ||
} | ||
|
||
/** | ||
* @return the startLOC of the conflict | ||
*/ | ||
public int getStartLOC() { | ||
return startLOC; | ||
} | ||
|
||
/** | ||
* @return the endLOC | ||
*/ | ||
public int getEndLOC() { | ||
return endLOC; | ||
} | ||
|
||
/* | ||
* public boolean containsRelaxed(String leftPattern, String rightPattern){ | ||
* if(leftPattern.isEmpty() || rightPattern.isEmpty()){ return false; } else { | ||
* leftPattern = | ||
* (leftPattern.replaceAll("\\r\\n|\\r|\\n","")).replaceAll("\\s+",""); | ||
* rightPattern = | ||
* (rightPattern.replaceAll("\\r\\n|\\r|\\n","")).replaceAll("\\s+",""); String | ||
* lefttrim = (this.left.replaceAll("\\r\\n|\\r|\\n","")).replaceAll("\\s+",""); | ||
* String righttrim = | ||
* (this.right.replaceAll("\\r\\n|\\r|\\n","")).replaceAll("\\s+",""); | ||
* | ||
* leftPattern = Util.removeReservedKeywords(leftPattern); rightPattern = | ||
* Util.removeReservedKeywords(rightPattern); lefttrim = | ||
* Util.removeReservedKeywords(lefttrim); righttrim = | ||
* Util.removeReservedKeywords(righttrim); | ||
* | ||
* return (lefttrim.contains(leftPattern) && righttrim.contains(rightPattern)); | ||
* } } | ||
*/ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package br . ufpe . cin . mergers . util ; import java . io . File ; import br . ufpe . cin . app . JFSTMerge ; import br . ufpe . cin . files . FilesManager ; import de . ovgu . cide . fstgen . ast . FSTNode ; import de . ovgu . cide . fstgen . ast . FSTNonTerminal ; import de . ovgu . cide . fstgen . ast . FSTTerminal ; public class MergeConflict { private final String left ; private final String base ; private final String right ; private final String body ; private final String message ; private int startLOC ; private int endLOC ; private File leftOriginFile ; private File baseOriginFile ; private File rightOriginFile ; private String fullyQualifiedMergedClass ; public static final String MINE_CONFLICT_MARKER = "<<<<<<< MINE" ; public static final String BASE_CONFLICT_MARKER = "||||||| BASE" ; public static final String CHANGE_CONFLICT_MARKER = "=======" ; public static final String YOURS_CONFLICT_MARKER = ">>>>>>> YOURS" ; private String getNodeContent ( FSTNode node ) { if ( node == null ) { return "" ; } else if ( node instanceof FSTTerminal ) { return IndentationUtils . indentFirstLine ( ( FSTTerminal ) node ) ; } else { return FilesManager . prettyPrint ( ( FSTNonTerminal ) node ) ; } } private String assembleBody ( ) { StringBuilder conflict = new StringBuilder ( ) ; conflict . append ( MINE_CONFLICT_MARKER ) . append ( '\n' ) . append ( left ) . append ( '\n' ) ; if ( JFSTMerge . showBase ) { conflict . append ( BASE_CONFLICT_MARKER ) . append ( '\n' ) . append ( base ) . append ( '\n' ) ; } conflict . append ( CHANGE_CONFLICT_MARKER ) ; if ( JFSTMerge . showConflictMessages ) { conflict . append ( " " + message ) ; } conflict . append ( '\n' ) . append ( right ) . append ( '\n' ) . append ( YOURS_CONFLICT_MARKER ) ; return conflict . toString ( ) ; } public MergeConflict ( String left , String base , String right , String message ) { this . left = left ; this . base = base ; this . right = right ; this . message = message ; this . body = assembleBody ( ) ; } public boolean contains ( String leftPattern , String rightPattern ) { if ( leftPattern . isEmpty ( ) || rightPattern . isEmpty ( ) ) { return false ; } else { leftPattern = ( leftPattern . replaceAll ( "\\r\\n|\\r|\\n" , "" ) ) . replaceAll ( "\\s+" , "" ) ; rightPattern = ( rightPattern . replaceAll ( "\\r\\n|\\r|\\n" , "" ) ) . replaceAll ( "\\s+" , "" ) ; String lefttrim = ( this . left . replaceAll ( "\\r\\n|\\r|\\n" , "" ) ) . replaceAll ( "\\s+" , "" ) ; String righttrim = ( this . right . replaceAll ( "\\r\\n|\\r|\\n" , "" ) ) . replaceAll ( "\\s+" , "" ) ; return ( lefttrim . contains ( leftPattern ) && righttrim . contains ( rightPattern ) ) ; } } public void setOriginFiles ( File left , File base , File right ) { this . leftOriginFile = left ; this . rightOriginFile = right ; this . baseOriginFile = base ; } public String getFullyQualifiedMergedClass ( ) { return fullyQualifiedMergedClass ; } public void setFullyQualifiedMergedClass ( String fullyQualifiedMergedClass ) { this . fullyQualifiedMergedClass = fullyQualifiedMergedClass ; } @ Override public String toString ( ) { return this . body ; } public String getLeft ( ) { return left ; } public String getBase ( ) { return base ; } public String getRight ( ) { return right ; } public int getStartLOC ( ) { return startLOC ; } public int getEndLOC ( ) { return endLOC ; } public MergeConflict ( FSTNode left , FSTNode base , FSTNode right , String message ) { this . left = getNodeContent ( left ) ; this . base = getNodeContent ( base ) ; this . right = getNodeContent ( right ) ; this . message = message ; this . body = assembleBody ( ) ; } public MergeConflict ( FSTTerminal left , FSTTerminal base , FSTTerminal right , String message , int startLOC , int endLOC ) { this ( left , base , right , message ) ; this . startLOC = startLOC ; this . endLOC = endLOC ; } public MergeConflict ( String left , String base , String right , String message , int startLOC , int endLOC ) { this ( left , base , right , message ) ; this . startLOC = startLOC ; this . endLOC = endLOC ; } } |
Oops, something went wrong.