Skip to content

Commit

Permalink
Eliminate wrongly reported Extract Variable refactorings in commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed Jan 2, 2025
1 parent c5a3017 commit bec4d0d
Showing 1 changed file with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,17 @@ else if(container1.getBodyHashCode() != container2.getBodyHashCode() && !contain
}
}
}
if(!matchingInlinedOperationLeaf) {
boolean anotherExtractVariableWithSameInitializer = false;
for(Refactoring r : refactorings) {
if(r instanceof ExtractVariableRefactoring) {
ExtractVariableRefactoring extract = (ExtractVariableRefactoring)r;
if(extract.getVariableDeclaration().getInitializer().getString().contains(initializer.getString())) {
anotherExtractVariableWithSameInitializer = true;
break;
}
}
}
if(!matchingInlinedOperationLeaf && !anotherExtractVariableWithSameInitializer) {
ExtractVariableRefactoring ref = new ExtractVariableRefactoring(declaration, operation1, operation2, parentMapper != null);
ref.addUnmatchedStatementReference(nonMappedLeaf1);
List<LeafExpression> subExpressions = nonMappedLeaf1.findExpression(initializer.getString());
Expand Down Expand Up @@ -1015,7 +1025,17 @@ else if(container1.getBodyHashCode() != container2.getBodyHashCode() && !contain
}
}
}
if(!matchingExtractedOperationLeaf) {
boolean anotherInlineVariableWithSameInitializer = false;
for(Refactoring r : refactorings) {
if(r instanceof InlineVariableRefactoring) {
InlineVariableRefactoring inline = (InlineVariableRefactoring)r;
if(inline.getVariableDeclaration().getInitializer().getString().contains(initializer.getString())) {
anotherInlineVariableWithSameInitializer = true;
break;
}
}
}
if(!matchingExtractedOperationLeaf && !anotherInlineVariableWithSameInitializer) {
InlineVariableRefactoring ref = new InlineVariableRefactoring(declaration, operation1, operation2, parentMapper != null);
ref.addUnmatchedStatementReference(nonMappedLeaf2);
List<LeafExpression> subExpressions = nonMappedLeaf2.findExpression(initializerAfterRename != null ? initializerAfterRename : initializer.getString());
Expand Down

0 comments on commit bec4d0d

Please sign in to comment.