Skip to content

Commit

Permalink
Improved matching of methods in TestVM.java → BstFunctionsTest.java
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed May 20, 2024
1 parent 720cf2e commit f5b7f0d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1754,6 +1754,24 @@ private static boolean stringConcatTextBlock(String s1, String s2, ReplacementIn
info.getReplacements().add(r);
return true;
}
else {
//identical match if one line is removed
for(String line : lines) {
if(!line.isBlank()) {
String tmp = s.replace(line, "");
String tmpFormatted = tmp.replaceAll("\\s+","");
if(tmpFormatted.equals(concatenated)) {
IntersectionReplacement r = new IntersectionReplacement(s1, s2, ReplacementType.CONCATENATION);
for(LeafExpression leaf1 : statement1.getStringLiterals()) {
LeafMapping leafMapping = new LeafMapping(leaf1, leaf2, container1, container2);
r.addSubExpressionMapping(leafMapping);
}
info.getReplacements().add(r);
return true;
}
}
}
}
}
}
return false;
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/gr/uom/java/xmi/diff/UMLClassBaseDiff.java
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ else if(removedOperation.hasTestAnnotation() && addedOperation.hasParameterizedT
}
if(!matchingMergeCandidateFound && !matchingSplitCandidateFound) {
UMLOperationBodyMapper bestMapper = findBestMapper(mapperSet);
if(bestMapper != null) {
if(bestMapper != null && !modelDiffContainsConflictingMoveOperationRefactoring(bestMapper)) {
removedOperation = bestMapper.getOperation1();
UMLOperation addedOperation = bestMapper.getOperation2();
addedOperations.remove(addedOperation);
Expand Down Expand Up @@ -1285,7 +1285,7 @@ else if(bestMapper.getContainer1().hasTestAnnotation() && addedOperation2.hasPar
if(mapperSet.size() > mapperSetSize) {
bestMapper = findBestMapper(mapperSet);
}
if(bestMapper != null) {
if(bestMapper != null && !modelDiffContainsConflictingMoveOperationRefactoring(bestMapper)) {
UMLOperation removedOperation = bestMapper.getOperation1();
addedOperation = bestMapper.getOperation2();
if(mapperSet.size() > mapperSetSize) {
Expand Down Expand Up @@ -1369,6 +1369,13 @@ else if(bestMapper.getContainer1().hasTestAnnotation() && addedOperation2.hasPar
}
}

private boolean modelDiffContainsConflictingMoveOperationRefactoring(UMLOperationBodyMapper mapper) {
if(modelDiff != null) {
return modelDiff.refactoringListContainsAnotherMoveRefactoringWithTheSameRemovedOperation(mapper);
}
return false;
}

private boolean isPerfectMapper(UMLOperationBodyMapper mapper) {
int nonMappedLeavesT1 = mapper.getNonMappedLeavesT1().size();
int nonMappedLeavesT2 = mapper.getNonMappedLeavesT2().size();
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/gr/uom/java/xmi/diff/UMLModelDiff.java
Original file line number Diff line number Diff line change
Expand Up @@ -4800,6 +4800,19 @@ private boolean refactoringListContainsAnotherMoveRefactoringWithTheSameOperatio
return false;
}

public boolean refactoringListContainsAnotherMoveRefactoringWithTheSameRemovedOperation(UMLOperationBodyMapper mapper) {
for(Refactoring refactoring : refactorings) {
if(refactoring instanceof MoveOperationRefactoring) {
MoveOperationRefactoring moveRefactoring = (MoveOperationRefactoring)refactoring;
if(moveRefactoring.getOriginalOperation().equals(mapper.getOperation1()) &&
!moveRefactoring.getMovedOperation().equals(mapper.getOperation2())) {
return true;
}
}
}
return false;
}

public boolean refactoringListContainsAnotherMoveRefactoringWithTheSameAddedOperation(UMLOperation addedOperation) {
for(Refactoring refactoring : refactorings) {
if(refactoring instanceof MoveOperationRefactoring) {
Expand Down

0 comments on commit f5b7f0d

Please sign in to comment.