Skip to content

Commit

Permalink
Enable the detection of refactoring
Browse files Browse the repository at this point in the history
Extract Attribute	private singleTestExecutor : SingleTestExecutor in class org.junit.gen5.engine.HierarchicalTestExecutor
in commit
junit-team/junit5@cfefe1e
  • Loading branch information
tsantalis committed Feb 15, 2024
1 parent 9bbfda4 commit e5edfa3
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ else if(invocationCoveringTheEntireStatement1.arguments().contains(methodInvocat
variablesAndMethodInvocations1.addAll(variables1);

findReplacements(variables1, creations2, replacementInfo, ReplacementType.VARIABLE_REPLACED_WITH_CLASS_INSTANCE_CREATION, container1, container2, classDiff);
findReplacements(creations1, variables2, replacementInfo, ReplacementType.VARIABLE_REPLACED_WITH_CLASS_INSTANCE_CREATION, container1, container2, classDiff);
if(statement1.getString().startsWith(JAVA.THROW_SPACE) && statement2.getString().startsWith(JAVA.THROW_SPACE) && creationCoveringTheEntireStatement2 != null && creations2.isEmpty()) {
findReplacements(variables1, Set.of(creationCoveringTheEntireStatement2.actualString()), replacementInfo, ReplacementType.VARIABLE_REPLACED_WITH_CLASS_INSTANCE_CREATION, container1, container2, classDiff);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3050,6 +3050,32 @@ public List<AbstractCodeMapping> getExactMatchesWithoutMatchesInNestedContainers
return exactMatches;
}

public boolean allMappingsHaveSameDepthAndIndex() {
if(this.nonMappedInnerNodesT1.isEmpty() && this.nonMappedInnerNodesT2.isEmpty() &&
this.nonMappedLeavesT1.isEmpty() && this.nonMappedLeavesT2.isEmpty()) {
int count = 0;
int compositeCount = 0;
int identicalCompositeCount = 0;
for(AbstractCodeMapping mapping : mappings) {
AbstractCodeFragment f1 = mapping.getFragment1();
AbstractCodeFragment f2 = mapping.getFragment2();
if(f1.getDepth() == f2.getDepth() && f1.getIndex() == f2.getIndex()) {
count++;
if(mapping instanceof CompositeStatementObjectMapping) {
compositeCount++;
if(f1.getString().equals(f2.getString())) {
identicalCompositeCount++;
}
}
}
}
if(count == mappings.size() && compositeCount == identicalCompositeCount && compositeCount > 0) {
return true;
}
}
return false;
}

public boolean allMappingsAreExactMatches() {
int mappings = this.mappingsWithoutBlocks();
int tryMappings = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gr/uom/java/xmi/diff/UMLClassBaseDiff.java
Original file line number Diff line number Diff line change
Expand Up @@ -1662,7 +1662,7 @@ private void updateMapperSet(TreeSet<UMLOperationBodyMapper> mapperSet, UMLOpera
int mappings = operationBodyMapper.mappingsWithoutBlocks();
if(mappings > 0 || (delegatesToAnotherRemovedOperation(removedOperation) && addedOperation.getBody() != null && addedOperation.stringRepresentation().size() > 3) || (removedOperation.getName().equals(addedOperation.getName()) && removedOperation.getBody() != null && addedOperation.getBody() != null)) {
int absoluteDifferenceInPosition = computeAbsoluteDifferenceInPositionWithinClass(removedOperation, addedOperation);
if(exactMappings(operationBodyMapper)) {
if(exactMappings(operationBodyMapper) || operationBodyMapper.allMappingsHaveSameDepthAndIndex()) {
mapperSet.add(operationBodyMapper);
}
else if(mappedElementsMoreThanNonMappedT1AndT2(mappings, operationBodyMapper) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,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(12043, 20, 242);
test.assertExpectationsWithGitHubAPI(12050, 20, 241);
}
}
65 changes: 36 additions & 29 deletions src/test/resources/oracle/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,13 @@
"validation": "TP",
"detectionTools": "RefactoringMiner",
"validators": null
}, {
"type": "Extract Attribute",
"description": "Extract Attribute public ARRAY_INTERFACES : GenericTypeList in class net.bytebuddy.description.type.TypeDescription",
"comment": null,
"validation": "TP",
"detectionTools": "RefactoringMiner",
"validators": null
}],
"refDiffExecutionTime": 4590
}, {
Expand Down Expand Up @@ -68180,7 +68187,7 @@
"description": "Rename Method private TestHazelcastInstanceFactory(addresses Address[]) renamed to private init(initialNodeCount int) : void in class com.hazelcast.test.TestHazelcastInstanceFactory",
"comment": null,
"validation": "TP",
"detectionTools": "RefDiff, GumTreeDiff, RD-1x, RD-2x",
"detectionTools": "RefactoringMiner, RefDiff, GumTreeDiff, RD-1x, RD-2x",
"validators": "Matin, Davood"
}, {
"type": "Extract Method",
Expand Down Expand Up @@ -68526,43 +68533,22 @@
"detectionTools": "RefactoringMiner",
"validators": null
}, {
"type": "Inline Method",
"description": "Inline Method private TestHazelcastInstanceFactory(addresses Address[]) inlined to public TestHazelcastInstanceFactory(addresses String...) in class com.hazelcast.test.TestHazelcastInstanceFactory",
"comment": null,
"validation": "TP",
"detectionTools": "RefactoringMiner",
"validators": null
}, {
"type": "Inline Method",
"description": "Inline Method private TestHazelcastInstanceFactory(addresses Address[]) inlined to public TestHazelcastInstanceFactory(count int) in class com.hazelcast.test.TestHazelcastInstanceFactory",
"comment": null,
"validation": "TP",
"detectionTools": "RefactoringMiner",
"validators": null
}, {
"type": "Extract Method",
"description": "Extract Method private init(initialNodeCount int) : void extracted from public TestHazelcastInstanceFactory(addresses String...) in class com.hazelcast.test.TestHazelcastInstanceFactory",
"comment": null,
"validation": "TP",
"detectionTools": "RefactoringMiner",
"validators": null
}, {
"type": "Extract Method",
"description": "Extract Method private init(initialNodeCount int) : void extracted from public TestHazelcastInstanceFactory(count int) in class com.hazelcast.test.TestHazelcastInstanceFactory",
"type": "Remove Attribute Modifier",
"description": "Remove Attribute Modifier static in attribute private PORTS : AtomicInteger from class com.hazelcast.test.TestHazelcastInstanceFactory",
"comment": null,
"validation": "TP",
"detectionTools": "RefactoringMiner",
"validators": null
}, {
"type": "Rename Parameter",
"description": "Rename Parameter count : int to initialNodeCount : int in method private init(initialNodeCount int) : void from class com.hazelcast.test.TestHazelcastInstanceFactory",
"description": "Rename Parameter addresses : Address[] to initialNodeCount : int in method private init(initialNodeCount int) : void from class com.hazelcast.test.TestHazelcastInstanceFactory",
"comment": null,
"validation": "TP",
"detectionTools": "RefactoringMiner",
"validators": null
}, {
"type": "Remove Attribute Modifier",
"description": "Remove Attribute Modifier static in attribute private PORTS : AtomicInteger from class com.hazelcast.test.TestHazelcastInstanceFactory",
"type": "Change Parameter Type",
"description": "Change Parameter Type addresses : Address[] to initialNodeCount : int in method private init(initialNodeCount int) : void from class com.hazelcast.test.TestHazelcastInstanceFactory",
"comment": null,
"validation": "TP",
"detectionTools": "RefactoringMiner",
Expand Down Expand Up @@ -75566,6 +75552,13 @@
"validation": "TP",
"detectionTools": "RefactoringMiner",
"validators": null
}, {
"type": "Extract Variable",
"description": "Extract Variable entry : CreateIdStatus<Object> in method public buildRestLiResponseData(request RestRequest, routingResult RoutingResult, result Object, headers Map<String,String>) : RestLiResponseEnvelope from class com.linkedin.restli.internal.server.methods.response.BatchCreateResponseBuilder",
"comment": null,
"validation": "TP",
"detectionTools": "RefactoringMiner",
"validators": null
}],
"refDiffExecutionTime": 2657
}, {
Expand Down Expand Up @@ -81824,6 +81817,20 @@
"validation": "TP",
"detectionTools": "RefactoringMiner",
"validators": null
}, {
"type": "Extract Variable",
"description": "Extract Variable outSelector : OutSelectorImpl in method public start() : void from class com.hazelcast.nio.tcp.TcpIpConnectionManager",
"comment": null,
"validation": "TP",
"detectionTools": "RefactoringMiner",
"validators": null
}, {
"type": "Extract Variable",
"description": "Extract Variable inSelector : InSelectorImpl in method public start() : void from class com.hazelcast.nio.tcp.TcpIpConnectionManager",
"comment": null,
"validation": "TP",
"detectionTools": "RefactoringMiner",
"validators": null
}],
"refDiffExecutionTime": 5604
}, {
Expand Down Expand Up @@ -95550,8 +95557,8 @@
"type": "Move Method",
"description": "Move Method public canReceiveNewTasks(host HostState, isReplica boolean) : boolean from class com.addthis.hydra.job.spawn.SpawnBalancer to public canReceiveNewTasks(host HostState) : boolean from class com.addthis.hydra.job.spawn.balancer.SpawnBalancer",
"comment": "<p>SpawnBalancer is moved, but this method is relocated within the file and parameter isReplica is removed.</p>",
"validation": "CTP",
"detectionTools": "RefactoringMiner, RefDiff",
"validation": "FP",
"detectionTools": "RefDiff",
"validators": "Matin, Nikos"
}, {
"type": "Move Method",
Expand Down
10 changes: 5 additions & 5 deletions src/test/resources/oracle/expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ d9a2c69a9d1db6072e1d7b7ea4fcbd5c15d20b5d, 3, 0, 0
becced5f0b7bac8200df7a5706b568687b517b90, 11, 0, 1
20d39f7af2165c67d5221f556f58820c992d2cc6, 7, 0, 0
3514aaedf9624222c985cb3abb12df2d9b514b12, 13, 0, 0
372f4ae6cebcd664e3b43cade356d1df233f6467, 57, 0, 1
372f4ae6cebcd664e3b43cade356d1df233f6467, 58, 0, 1
cb98ee25ff52bf97faebe3f45cdef0ced9b4416e, 28, 0, 0
1cfc6f64f64353bc5530a8ce8cdacfc3eba3e7b2, 3, 0, 0
b47634176fa48ad925f79886c6aaca225cb9af64, 3, 0, 0
Expand Down Expand Up @@ -189,7 +189,7 @@ c00275e7f85c8a9af5785f66cc0f75dc027b6cb6, 26, 0, 0
b5cf7a0252c8b0465c4dbd906717f7a12e26e6f8, 3, 0, 0
e1aa31cff985e2a0c2babf4da96dc0a538d5e514, 2, 0, 0
09b9d989658ef5bf9333c081c92b57a7611ad207, 31, 0, 0
76d7f5e3fe4eb41b383c1d884bc1217b9fa7192e, 53, 0, 2
76d7f5e3fe4eb41b383c1d884bc1217b9fa7192e, 57, 0, 1
2d036ecf1d7170b4ec7346579a1ef8904109530a, 2, 0, 0
7f20e63a7252f33c888085134d16ee8bf45f183f, 164, 0, 0
186357ac6c2da1a5a12c0287a08408ac5ec6683b, 1, 0, 0
Expand All @@ -216,7 +216,7 @@ a1525ac9a0bb8f727167a8be94c81a3415128ef4, 2, 0, 0
d49765899cb9df6781fff9773ffc244b5167351c, 11, 0, 0
be292763b8c4cb09988023d6081b0a2d57b4c778, 10, 0, 1
db024f5ec3e9611ddf8103bdc4c3817c704f7b27, 21, 0, 0
ec5ea36faa3dd74585bb339beabdba6149ed63be, 111, 0, 2
ec5ea36faa3dd74585bb339beabdba6149ed63be, 112, 0, 2
0f8a0af934f09deef1b58e961ffe789c7299bcc1, 25, 0, 0
e84e96ff5c2bdc48cea7f75fd794506159c4e1f7, 22, 0, 0
84b7b3974ae8171a4de2f804eb94fcd1d6cd6647, 1, 0, 0
Expand Down Expand Up @@ -250,7 +250,7 @@ ce4b0e22659c16ae83d421f9621fd3e922750764, 2, 0, 0
72dda3404820a82d53f1a16bb2ed9ad95f745d3c, 6, 0, 0
35b6c869546a7968b6fd2f640add6eea87e03c22, 78, 0, 2
4184c577f4bbc57f3ac13639557cfd99cdaca3e7, 4, 0, 0
30c4ae09745d6062077925a54f27205b7401d8df, 268, 0, 4
30c4ae09745d6062077925a54f27205b7401d8df, 270, 0, 4
03573a655bcbb77f7a76d8e22d851cc22796b4f8, 3, 0, 0
043030723632627b0908dca6b24dae91d3dfd938, 10, 0, 0
e3b0d87b3ca0fd27cec39937cb3dc3a05b0cfc4e, 3, 0, 0
Expand Down Expand Up @@ -337,7 +337,7 @@ e37d577b6cfc2d3e11252cef87ab9ebba72e1d52, 3, 0, 0
4fcd7d4d366d001cf5f1f7d926c608c902e3f0af, 2, 0, 0
573a1d115b86abbe3fb53ff930464d7d8fd95600, 15, 0, 0
ec52e77ecde749e7c5a483b26cbd8041f2a5a33c, 2, 0, 0
7fea4c9d5ee97d4a61ad985cadc9c5c0ab2db780, 118, 0, 0
7fea4c9d5ee97d4a61ad985cadc9c5c0ab2db780, 117, 0, 0
664923815b5aeeba2025bfe1dc5a0cd1a02a80e2, 17, 0, 0
92dce401344a28ff966ad4cf3dd969a676852315, 4, 0, 1
7a1659c12d76b510809dea1dea1f5100bcf4cd60, 3, 0, 0
Expand Down

0 comments on commit e5edfa3

Please sign in to comment.