Skip to content

Commit

Permalink
Optimize Move Code mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed Oct 26, 2024
1 parent dc6a601 commit 97e6313
Show file tree
Hide file tree
Showing 11 changed files with 1,439 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/gr/uom/java/xmi/diff/UMLClassBaseDiff.java
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@ else if(removedOperation.isConstructor()) {
MoveCodeRefactoring ref = new MoveCodeRefactoring(moveCodeMapper.getContainer1(), moveCodeMapper.getContainer2(), moveCodeMapper, Type.MOVE_BETWEEN_EXISTING);
if(!moveCodeMappers.contains(moveCodeMapper))
moveCodeMappers.add(moveCodeMapper);
if(!moveCodeMappers.contains(caller))
moveCodeMappers.add(caller);
refactorings.add(ref);
}
}
Expand Down
60 changes: 60 additions & 0 deletions src/test/java/org/refactoringminer/test/TestStatementMappings.java
Original file line number Diff line number Diff line change
Expand Up @@ -1187,6 +1187,66 @@ else if(ref instanceof MoveCodeRefactoring) {
Assertions.assertTrue(expected.size() == actual.size() && expected.containsAll(actual) && actual.containsAll(expected));
}

@Test
public void testMoveCodeStatementMappings2() throws Exception {
GitHistoryRefactoringMinerImpl miner = new GitHistoryRefactoringMinerImpl();
final List<String> actual = new ArrayList<>();
miner.detectAtCommitWithGitHubAPI("https://github.com/junit-team/junit5.git", "3e3b402131a99f01480c57dd82c2e81ad6d9a4ea", new File(REPOS), new RefactoringHandler() {
@Override
public void handleModelDiff(String commitId, List<Refactoring> refactorings, UMLModelDiff modelDiff) {
List<UMLOperationBodyMapper> parentMappers = new ArrayList<>();
for (Refactoring ref : refactorings) {
if(ref instanceof ExtractOperationRefactoring) {
ExtractOperationRefactoring ex = (ExtractOperationRefactoring)ref;
UMLOperationBodyMapper bodyMapper = ex.getBodyMapper();
if(!bodyMapper.isNested()) {
if(!parentMappers.contains(bodyMapper.getParentMapper())) {
parentMappers.add(bodyMapper.getParentMapper());
}
}
mapperInfo(bodyMapper, actual);
}
else if(ref instanceof InlineOperationRefactoring) {
InlineOperationRefactoring in = (InlineOperationRefactoring)ref;
UMLOperationBodyMapper bodyMapper = in.getBodyMapper();
if(!bodyMapper.isNested()) {
if(!parentMappers.contains(bodyMapper.getParentMapper())) {
parentMappers.add(bodyMapper.getParentMapper());
}
}
mapperInfo(bodyMapper, actual);
}
else if(ref instanceof MoveCodeRefactoring) {
MoveCodeRefactoring in = (MoveCodeRefactoring)ref;
UMLOperationBodyMapper bodyMapper = in.getBodyMapper();
mapperInfo(bodyMapper, actual);
}
}
for(UMLOperationBodyMapper parentMapper : parentMappers) {
mapperInfo(parentMapper, actual);
}
//add main mapper
UMLClassBaseDiff classDiff = modelDiff.getUMLClassDiff("org.junit.jupiter.engine.descriptor.ClassTestDescriptor");
for(UMLOperationBodyMapper mapper : classDiff.getOperationBodyMapperList()) {
if(mapper.getContainer1().getName().equals("before") && mapper.getContainer2().getName().equals("before")) {
mapperInfo(mapper, actual);
}
if(mapper.getContainer1().getName().equals("after") && mapper.getContainer2().getName().equals("after")) {
mapperInfo(mapper, actual);
}
}
classDiff = modelDiff.getUMLClassDiff("org.junit.jupiter.engine.descriptor.MethodTestDescriptor");
for(UMLOperationBodyMapper mapper : classDiff.getOperationBodyMapperList()) {
if(mapper.getContainer1().getName().equals("execute") && mapper.getContainer2().getName().equals("execute")) {
mapperInfo(mapper, actual);
}
}
}
});
List<String> expected = IOUtils.readLines(new FileReader(EXPECTED_PATH + "junit5-3e3b402131a99f01480c57dd82c2e81ad6d9a4ea.txt"));
Assertions.assertTrue(expected.size() == actual.size() && expected.containsAll(actual) && actual.containsAll(expected));
}

@Test
public void testLogGuardStatementMappings() throws Exception {
GitHistoryRefactoringMinerImpl miner = new GitHistoryRefactoringMinerImpl();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2432,6 +2432,66 @@ else if(ref instanceof MoveCodeRefactoring) {
Assert.assertTrue(expected.size() == actual.size() && expected.containsAll(actual) && actual.containsAll(expected));
}

@Test
public void testMoveCodeStatementMappings2() throws Exception {
GitHistoryRefactoringMinerImpl miner = new GitHistoryRefactoringMinerImpl();
final List<String> actual = new ArrayList<>();
miner.detectAtCommitWithGitHubAPI("https://github.com/junit-team/junit5.git", "3e3b402131a99f01480c57dd82c2e81ad6d9a4ea", new File(REPOS), new RefactoringHandler() {
@Override
public void handleModelDiff(String commitId, List<Refactoring> refactorings, UMLModelDiff modelDiff) {
List<UMLOperationBodyMapper> parentMappers = new ArrayList<>();
for (Refactoring ref : refactorings) {
if(ref instanceof ExtractOperationRefactoring) {
ExtractOperationRefactoring ex = (ExtractOperationRefactoring)ref;
UMLOperationBodyMapper bodyMapper = ex.getBodyMapper();
if(!bodyMapper.isNested()) {
if(!parentMappers.contains(bodyMapper.getParentMapper())) {
parentMappers.add(bodyMapper.getParentMapper());
}
}
mapperInfo(bodyMapper, actual);
}
else if(ref instanceof InlineOperationRefactoring) {
InlineOperationRefactoring in = (InlineOperationRefactoring)ref;
UMLOperationBodyMapper bodyMapper = in.getBodyMapper();
if(!bodyMapper.isNested()) {
if(!parentMappers.contains(bodyMapper.getParentMapper())) {
parentMappers.add(bodyMapper.getParentMapper());
}
}
mapperInfo(bodyMapper, actual);
}
else if(ref instanceof MoveCodeRefactoring) {
MoveCodeRefactoring in = (MoveCodeRefactoring)ref;
UMLOperationBodyMapper bodyMapper = in.getBodyMapper();
mapperInfo(bodyMapper, actual);
}
}
for(UMLOperationBodyMapper parentMapper : parentMappers) {
mapperInfo(parentMapper, actual);
}
//add main mapper
UMLClassBaseDiff classDiff = modelDiff.getUMLClassDiff("org.junit.jupiter.engine.descriptor.ClassTestDescriptor");
for(UMLOperationBodyMapper mapper : classDiff.getOperationBodyMapperList()) {
if(mapper.getContainer1().getName().equals("before") && mapper.getContainer2().getName().equals("before")) {
mapperInfo(mapper, actual);
}
if(mapper.getContainer1().getName().equals("after") && mapper.getContainer2().getName().equals("after")) {
mapperInfo(mapper, actual);
}
}
classDiff = modelDiff.getUMLClassDiff("org.junit.jupiter.engine.descriptor.MethodTestDescriptor");
for(UMLOperationBodyMapper mapper : classDiff.getOperationBodyMapperList()) {
if(mapper.getContainer1().getName().equals("execute") && mapper.getContainer2().getName().equals("execute")) {
mapperInfo(mapper, actual);
}
}
}
});
List<String> expected = IOUtils.readLines(new FileReader(EXPECTED_PATH + "junit5-3e3b402131a99f01480c57dd82c2e81ad6d9a4ea.txt"));
Assert.assertTrue(expected.size() == actual.size() && expected.containsAll(actual) && actual.containsAll(expected));
}

@Test
public void testLogGuardStatementMappings() throws Exception {
GitHistoryRefactoringMinerImpl miner = new GitHistoryRefactoringMinerImpl();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
public before(context JupiterEngineExecutionContext) : JupiterEngineExecutionContext -> private invokeBeforeAllCallbacks(context JupiterEngineExecutionContext) : void
line range:157-157==line range:198-198
line range:158-158==line range:199-199
public before(context JupiterEngineExecutionContext) : JupiterEngineExecutionContext -> private invokeBeforeAllMethods(context JupiterEngineExecutionContext) : void
line range:157-157==line range:211-211
line range:158-158==line range:212-212
public after(context JupiterEngineExecutionContext) : void -> private invokeAfterAllMethods(context JupiterEngineExecutionContext) : void
line range:173-173==line range:224-224
line range:174-174==line range:225-225
line range:175-175==line range:226-226
public after(context JupiterEngineExecutionContext) : void -> private invokeAfterAllCallbacks(context JupiterEngineExecutionContext) : void
line range:173-173==line range:233-233
line range:174-174==line range:234-234
line range:175-175==line range:235-235
public execute(context JupiterEngineExecutionContext) : JupiterEngineExecutionContext -> private invokeBeforeEachCallbacks(context JupiterEngineExecutionContext) : void
line range:148-148==line range:172-172
line range:149-149==line range:173-173
public execute(context JupiterEngineExecutionContext) : JupiterEngineExecutionContext -> private invokeBeforeEachMethods(context JupiterEngineExecutionContext) : void
line range:148-148==line range:185-185
line range:149-149==line range:186-186
public execute(context JupiterEngineExecutionContext) : JupiterEngineExecutionContext -> private invokeBeforeTestExecutionCallbacks(context JupiterEngineExecutionContext) : void
line range:148-148==line range:198-198
line range:149-149==line range:199-199
public execute(context JupiterEngineExecutionContext) : JupiterEngineExecutionContext -> protected invokeTestMethod(context JupiterEngineExecutionContext) : void
line range:149-149==line range:211-211
public execute(context JupiterEngineExecutionContext) : JupiterEngineExecutionContext -> private invokeAfterTestExecutionCallbacks(context JupiterEngineExecutionContext) : void
line range:148-148==line range:250-250
line range:149-149==line range:251-251
public execute(context JupiterEngineExecutionContext) : JupiterEngineExecutionContext -> private invokeAfterEachMethods(context JupiterEngineExecutionContext) : void
line range:148-148==line range:259-259
line range:149-149==line range:260-260
public execute(context JupiterEngineExecutionContext) : JupiterEngineExecutionContext -> private invokeAfterEachCallbacks(context JupiterEngineExecutionContext) : void
line range:148-148==line range:268-268
line range:149-149==line range:269-269
public before(context JupiterEngineExecutionContext) : JupiterEngineExecutionContext -> public before(context JupiterEngineExecutionContext) : JupiterEngineExecutionContext
line range:159-159==line range:157-157
line range:163-163==line range:161-161
line range:166-166==line range:165-165
line range:168-168==line range:167-167
line range:161-161==line range:159-159
line range:164-164==line range:162-162
line range:162-165==line range:160-163
line range:162-165==line range:160-163
public after(context JupiterEngineExecutionContext) : void -> public after(context JupiterEngineExecutionContext) : void
line range:178-178==line range:173-173
line range:180-180==line range:175-175
line range:181-181==line range:177-177
line range:177-179==line range:172-174
line range:177-179==line range:172-174
public execute(context JupiterEngineExecutionContext) : JupiterEngineExecutionContext -> public execute(context JupiterEngineExecutionContext) : JupiterEngineExecutionContext
line range:168-168==line range:166-166
line range:170-170==line range:168-168
line range:153-153==line range:151-151
line range:155-155==line range:153-153
line range:157-157==line range:155-155
line range:159-159==line range:157-157
line range:161-161==line range:159-159
line range:163-163==line range:161-161
line range:165-165==line range:163-163
line range:158-160==line range:156-158
line range:156-162==line range:154-160
line range:154-164==line range:152-162
line range:158-160==line range:156-158
line range:156-162==line range:154-160
line range:154-164==line range:152-162
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"parentCommitId":"62c433c14ce9d70fa5b82ef385a6e15c22cc0003","currentCommitId":"3e3b402131a99f01480c57dd82c2e81ad6d9a4ea","filesBefore":["junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/ClassTestDescriptor.java","junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/MethodTestDescriptor.java","junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/TestFactoryTestDescriptor.java","junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/execution/JupiterEngineExecutionContext.java"],"filesCurrent":["junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/ClassTestDescriptor.java","junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/MethodTestDescriptor.java","junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/TestFactoryTestDescriptor.java","junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/execution/JupiterEngineExecutionContext.java"],"renamedFilesHint":{},"repositoryDirectoriesBefore":["junit-jupiter-engine","junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor","junit-jupiter-engine/src/main/java","junit-jupiter-engine/src/main/java/org","junit-jupiter-engine/src/main/java/org/junit/jupiter/engine","junit-jupiter-engine/src/main","junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/execution","junit-jupiter-engine/src/main/java/org/junit","junit-jupiter-engine/src/main/java/org/junit/jupiter","junit-jupiter-engine/src"],"repositoryDirectoriesCurrent":["junit-jupiter-engine","junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor","junit-jupiter-engine/src/main/java","junit-jupiter-engine/src/main/java/org","junit-jupiter-engine/src/main/java/org/junit/jupiter/engine","junit-jupiter-engine/src/main","junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/execution","junit-jupiter-engine/src/main/java/org/junit","junit-jupiter-engine/src/main/java/org/junit/jupiter","junit-jupiter-engine/src"],"commitTime":0,"authoredTime":0,"commitAuthorName":null}
Loading

0 comments on commit 97e6313

Please sign in to comment.