Skip to content

Commit

Permalink
Improved UMLModelDiff.conflictingExpression()
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed Jan 1, 2025
1 parent ef6c1a5 commit 76c0088
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 20 deletions.
71 changes: 61 additions & 10 deletions src/main/java/gr/uom/java/xmi/diff/UMLModelDiff.java
Original file line number Diff line number Diff line change
Expand Up @@ -4364,8 +4364,8 @@ else if(childFieldDeclarationMap != null) {
}
}
}
if(addedOperationInvocations.size() > 0) {
AbstractCall addedOperationInvocation = addedOperationInvocations.get(0);
for(AbstractCall addedOperationInvocation : addedOperationInvocations) {
//AbstractCall addedOperationInvocation = addedOperationInvocations.get(0);
UMLOperationBodyMapper operationBodyMapper = createMapperForExtractAndMove(addedOperation,
mapper, className, addedOperationInvocation, Optional.empty());
if(!anotherAddedMethodExistsWithBetterMatchingInvocationExpression(addedOperationInvocation, addedOperation, addedOperations) &&
Expand Down Expand Up @@ -4538,19 +4538,70 @@ private boolean conflictingExpression(AbstractCall invocation, UMLOperation adde
}
}
}
/*else if(expression != null && childFieldDeclarationMap != null && childFieldDeclarationMap.containsKey(expression)) {
else if(expression != null && childFieldDeclarationMap != null && childFieldDeclarationMap.containsKey(expression)) {
VariableDeclaration variableDeclaration = childFieldDeclarationMap.get(expression);
UMLClassBaseDiff classDiff = getUMLClassDiff(addedOperation.getClassName());
UMLType type = variableDeclaration.getType();
boolean superclassRelationship = false;
if(classDiff != null && type != null && classDiff.getNewSuperclass() != null &&
classDiff.getNewSuperclass().equals(type)) {
superclassRelationship = true;
boolean superclassRelationship = superclassRelationship(addedOperation, type);
String addedOperationClassName = addedOperation.getNonQualifiedClassName();
String addedOperationFullQualifiedClassName = addedOperation.getClassName().substring(0, addedOperation.getClassName().lastIndexOf(addedOperationClassName)-1);
String outerClassName = null;
if(addedOperationFullQualifiedClassName.contains(".")) {
String name = addedOperationFullQualifiedClassName.substring(addedOperationFullQualifiedClassName.lastIndexOf(".")+1, addedOperationFullQualifiedClassName.length());
if(name.length() > 0 && Character.isUpperCase(name.charAt(0))) {
outerClassName = name;
}
}
if(type != null && !addedOperation.getNonQualifiedClassName().equals(type.getClassType()) && !superclassRelationship) {
if(type != null && !addedOperationClassName.equals(type.getClassType()) && !type.getClassType().equals(outerClassName) && !superclassRelationship) {
return true;
}
}*/
}
return false;
}

private boolean superclassRelationship(UMLOperation addedOperation, UMLType type) {
UMLClassBaseDiff classDiff = getUMLClassDiff(addedOperation.getClassName());
if(classDiff != null && type != null) {
if(classDiff.getNewSuperclass() != null && classDiff.getNewSuperclass().equals(type)) {
return true;
}
for(UMLType interfaceType : classDiff.getNextClass().getImplementedInterfaces()) {
if(interfaceType.equals(type)) {
return true;
}
}

}
UMLClassBaseDiff delegateClassDiff = getUMLClassDiff(type);
if(delegateClassDiff != null && type != null) {
//check for possible delegation
for(UMLOperation operation : delegateClassDiff.getAddedOperations()) {
List<AbstractCall> invocations = operation.getAllOperationInvocations();
for(AbstractCall invocation : invocations) {
if(invocation.matchesOperation(addedOperation, operation, delegateClassDiff, this)) {
return true;
}
}
}
for(UMLOperationBodyMapper mapper : delegateClassDiff.getOperationBodyMapperList()) {
List<AbstractCall> invocations = mapper.getContainer2().getAllOperationInvocations();
for(AbstractCall invocation : invocations) {
if(invocation.matchesOperation(addedOperation, mapper.getContainer2(), delegateClassDiff, this)) {
return true;
}
}
}
}
UMLClass addedClass = getAddedClass(addedOperation.getClassName());
if(addedClass != null && type != null) {
if(addedClass.getSuperclass() != null && addedClass.getSuperclass().equals(type)) {
return true;
}
for(UMLType interfaceType : addedClass.getImplementedInterfaces()) {
if(interfaceType.equals(type)) {
return true;
}
}
}
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ public void testAllRefactorings() throws Exception {
GitHistoryRefactoringMinerImpl detector = new GitHistoryRefactoringMinerImpl();
TestBuilder test = new TestBuilder(detector, REPOS, Refactorings.All.getValue());
RefactoringPopulator.feedRefactoringsInstances(Refactorings.All.getValue(), Systems.FSE.getValue(), test);
test.assertExpectationsWithGitHubAPI(12403, 22, 226);
test.assertExpectationsWithGitHubAPI(12404, 22, 226);
}
}
21 changes: 14 additions & 7 deletions src/test/resources/oracle/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -12722,13 +12722,6 @@
"validation": "TP",
"detectionTools": "RefactoringMiner",
"validators": null
}, {
"type": "Extract And Move Method",
"description": "Extract And Move Method public edge(a int, b int, distance double, bothDirections boolean) : EdgeIteratorState extracted from public edge(a int, b int, distance double, bothDirection boolean) : EdgeIteratorState in class com.graphhopper.storage.GraphHopperStorage & moved to class com.graphhopper.storage.LevelGraphImpl",
"comment": null,
"validation": "TP",
"detectionTools": "RefactoringMiner",
"validators": null
}, {
"type": "Localize Parameter",
"description": "Localize Parameter outdir : Directory to outdir : Directory in method public newStorage(store GraphHopperStorage) : GraphHopperStorage from class com.graphhopper.util.GHUtility",
Expand Down Expand Up @@ -52171,6 +52164,20 @@
"validation": "CTP",
"detectionTools": "RefactoringMiner",
"validators": null
}, {
"type": "Rename Variable",
"description": "Rename Variable wh : File to dir : File in method public getTempDir(dirName String) : String from class org.apache.drill.BaseTestQuery",
"comment": null,
"validation": "TP",
"detectionTools": "RefactoringMiner",
"validators": null
}, {
"type": "Remove Variable Modifier",
"description": "Remove Variable Modifier final in variable wh : File in method public getInstance() : HiveTestDataGenerator from class org.apache.drill.exec.store.hive.HiveTestDataGenerator",
"comment": null,
"validation": "TP",
"detectionTools": "RefactoringMiner",
"validators": null
}],
"refDiffExecutionTime": 2022
}, {
Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/oracle/expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ b2bbd9941be6b132a83d27c0ae02c935e1dec5dd, 33, 0, 2
f1b8ae1c44e6ba46118c2f66eae1725259acdccc, 7, 0, 0
00aa01fb90f3210d1e3027d7f759fb1085b814bd, 60, 0, 5
658a918eebcbdeb4f920c2947ca8d0e79ad86d89, 1, 0, 0
c1b847acdc8cb90a1498b236b3bb5c81ca75c044, 78, 0, 3
c1b847acdc8cb90a1498b236b3bb5c81ca75c044, 80, 0, 3
35893c115ba23bd62a7036a33390420f074ce660, 19, 0, 0
f166866cd68efa963534c5bc7fc9ca38e4aa2838, 1, 0, 0
04bcfe98dbe7b05e508559930c21379ece845732, 50, 0, 0
Expand Down Expand Up @@ -333,7 +333,7 @@ b70f7ea0ce27b5defa0a7773d448732364e7aee0, 5, 0, 0
35668435090eb47cf8c5e704243510b6cee35a7b, 42, 0, 0
e37d577b6cfc2d3e11252cef87ab9ebba72e1d52, 3, 0, 0
2b2bb6c734d106cdd1c0f4691607be2fe11d7ebb, 1, 0, 0
7f80425b6a0af9bdfef12c8a873676e39e0a04a6, 399, 2, 7
7f80425b6a0af9bdfef12c8a873676e39e0a04a6, 398, 2, 7
4fcd7d4d366d001cf5f1f7d926c608c902e3f0af, 2, 0, 0
573a1d115b86abbe3fb53ff930464d7d8fd95600, 18, 0, 0
ec52e77ecde749e7c5a483b26cbd8041f2a5a33c, 2, 0, 0
Expand Down

0 comments on commit 76c0088

Please sign in to comment.