Skip to content

Commit

Permalink
Fixed missed moved method in commit (CodeTracker oracle)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed Feb 16, 2024
1 parent 076b3f3 commit b687c1c
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,9 @@ else if(invocationCoveringTheEntireStatement1.arguments().contains(methodInvocat
methodInvocations1.addAll(variablesAndMethodInvocations1);
variablesAndMethodInvocations1.addAll(methodInvocations1);
variablesAndMethodInvocations1.addAll(variables1);

//perform creation replacements
findReplacements(creations1, creations2, replacementInfo, ReplacementType.CLASS_INSTANCE_CREATION, container1, container2, classDiff);

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()) {
Expand Down Expand Up @@ -730,9 +732,6 @@ else if(methodInvocations1.contains(s1) && variables2.contains(s2)) {
findReplacements(variables1, variables2, replacementInfo, ReplacementType.VARIABLE_NAME, container1, container2, classDiff);
}
}
//perform creation replacements
findReplacements(creations1, creations2, replacementInfo, ReplacementType.CLASS_INSTANCE_CREATION, container1, container2, classDiff);

findReplacements(parenthesizedExpressions1, parenthesizedExpressions2, replacementInfo, ReplacementType.PARENTHESIZED_EXPRESSION, container1, container2, classDiff);

//perform literal replacements
Expand Down Expand Up @@ -3854,6 +3853,30 @@ else if(!old.getBefore().equals(element1) && old.getAfter().equals(element2)) {
}
}
}
//remove subsumed replacements
if(replacements.values().contains(true) && replacements.values().contains(false)) {
Replacement trueReplacement = null;
for(Replacement key : replacements.keySet()) {
if(replacements.get(key) == true) {
trueReplacement = key;
break;
}
}
Set<Replacement> toBeRemoved = new LinkedHashSet<Replacement>();
for(Replacement key : replacements.keySet()) {
if(replacements.get(key) == false) {
if(key.getBefore().equals(trueReplacement.getBefore()) && trueReplacement.getAfter().contains(key.getAfter())) {
toBeRemoved.add(key);
}
else if(key.getAfter().equals(trueReplacement.getAfter()) && trueReplacement.getBefore().contains(key.getBefore())) {
toBeRemoved.add(key);
}
}
}
for(Replacement r : toBeRemoved) {
replacements.remove(r);
}
}
return replacements;
}

Expand Down Expand Up @@ -3919,6 +3942,30 @@ else if(substringBeforeIndex1.length() < substringBeforeIndex2.length()) {
}
}
}
//remove subsumed replacements
if(replacements.values().contains(true) && replacements.values().contains(false)) {
Replacement trueReplacement = null;
for(Replacement key : replacements.keySet()) {
if(replacements.get(key) == true) {
trueReplacement = key;
break;
}
}
Set<Replacement> toBeRemoved = new LinkedHashSet<Replacement>();
for(Replacement key : replacements.keySet()) {
if(replacements.get(key) == false) {
if(key.getBefore().equals(trueReplacement.getBefore()) && trueReplacement.getAfter().contains(key.getAfter())) {
toBeRemoved.add(key);
}
else if(key.getAfter().equals(trueReplacement.getAfter()) && trueReplacement.getBefore().contains(key.getBefore())) {
toBeRemoved.add(key);
}
}
}
for(Replacement r : toBeRemoved) {
replacements.remove(r);
}
}
return replacements;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6733,6 +6733,27 @@ else if(isIfBranch(grandParent, grandParent.getParent()) && !hasElseBranch(grand
if(identicalCount == 0)
elseCondition = true;
}
else {
List<CompositeStatementObject> ifParents = extractIfParentsFromBlocks(parentMap.keySet());
Set<CompositeStatementObject> grandParents = new LinkedHashSet<CompositeStatementObject>();
for(CompositeStatementObject ifParent : ifParents) {
CompositeStatementObject parent = ifParent.getParent();
while(parent != null && parent.getLocationInfo().getCodeElementType().equals(CodeElementType.BLOCK)) {
parent = parent.getParent();
}
grandParents.add(parent);
}
if(container1.getBody() != null && grandParents.size() == 1) {
CompositeStatementObject grandParent2 = grandParents.iterator().next();
List<CompositeStatementObject> innerNodes1 = container1.getBody().getCompositeStatement().getInnerNodes();
for(CompositeStatementObject innerNode1 : innerNodes1) {
if(innerNode1.getString().equals(grandParent2.getString())) {
elseCondition = true;
break;
}
}
}
}
}
if(ifFound && (elseIfFound || (elseFound && elseCondition)) && (ifElseIfChain(parentMap.keySet()) || passDueToIfBecomingElseIf)) {
Set<String> variableDeclarationNames1 = new LinkedHashSet<>();
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(12045, 20, 241);
test.assertExpectationsWithGitHubAPI(12046, 20, 240);
}
}
2 changes: 1 addition & 1 deletion src/test/resources/oracle/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -27480,7 +27480,7 @@
"description": "Move Method public addItem(item Item, count int) : void from class tconstruct.library.modifiers.Modifier to public addItem(item Item, amountNeeded int, amountMatched int) : void from class tconstruct.library.mantle.RecipeMatchRegistry",
"comment": "<p>For me, it is an 'extract class' refactoring. Class&nbsp;<span class='blob-code-inner'><span class='pl-en'>RecipeMatchRegistry</span></span> is extracted from Modifier.</p><p>See that <span class='blob-code-inner'><span class='pl-smi x x-first x-last'>RecipeMatchRegistry is an attribute of class&nbsp; Modifier in the refactored version, and the&nbsp; 3 </span></span><span class='blob-code-inner'><span class='pl-en'>addItem(..)</span></span><span class='blob-code-inner'><span class='pl-smi x x-first x-last'><span class='pl-en'> methods in the refactored version of Modifier are now </span></span></span><span class='blob-code-inner'><span class='pl-smi x x-first x-last'><span class='pl-en'>delegating to the 3 addItem(..) in RecipeMatchRegistry.</span></span></span></p><p><span class='blob-code-inner'><span class='pl-smi x x-first x-last'><span class='pl-en'>&nbsp;The method is moved with the addition of a new parameter (amountNeeded), which is not used.<br /></span></span></span></p><p><span class='blob-code-inner'><span class='pl-smi x x-first x-last'><span class='pl-en'>- public void addItem(Item item, int count) {<br />- modifierItems.add(new RecipeMatch.Item(new ItemStack(item), count));<br />- }</span></span></span></p><p><span class='blob-code-inner'><span class='pl-smi x x-first x-last'><span class='pl-en'> public void addItem(Item item, int amountNeeded, int amountMatched) {<br /> items.add(new RecipeMatch.Item(new ItemStack(item), 1, amountMatched));<br /> }</span></span></span></p>",
"validation": "TP",
"detectionTools": "RefDiff, RD-1x",
"detectionTools": "RefactoringMiner, RefDiff, RD-1x",
"validators": "Matin, Laleh, Davood, Nikos"
}, {
"type": "Change Attribute Type",
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/oracle/expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ a9379ee529ed87e28c0736c3c6657dcd6a0680e4, 5, 0, 0
687bda5a3ea1b5daae2764653843d318c77f4590, 6, 0, 0
3ffd70929c08be5cf14f156189e8050969caa87e, 1, 0, 0
da39bfeb9c370abe2d86e6e327fade252434090d, 13, 0, 0
71820e573134be3fad3935035249cd77c4412f4e, 8, 0, 3
71820e573134be3fad3935035249cd77c4412f4e, 9, 0, 2
f05e86c4d31987ff2f30330745c3eb605de4c4dc, 4, 0, 0
19d1936c3b07d97d88646aeae30de747715e3248, 21, 0, 0
b40adc25008b6f608ee3eb3422c8884fff987337, 16, 0, 0
Expand Down

0 comments on commit b687c1c

Please sign in to comment.