Skip to content

Commit

Permalink
Enable detection of overlapping Extract Variable within composite
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed Dec 27, 2024
1 parent a144814 commit 87b0460
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -711,18 +711,37 @@ else if(stringConcatMatch(initializer, before)) {
}
if(variableName.equals(after) && statement.getPatternInstanceofExpressions().size() > 0) {
for(LeafExpression expression2 : statement.getPatternInstanceofExpressions()) {
if(expression2.getString().endsWith(" " + variableName) && expression2.getString().contains(before)) {
ExtractVariableRefactoring ref = new ExtractVariableRefactoring(declaration, operation1, operation2, insideExtractedOrInlinedMethod);
List<LeafExpression> expressions1 = fragment1.findExpression(before);
if(expressions1.size() > 0) {
LeafMapping leafMapping = new LeafMapping(expressions1.get(0), expression2, operation1, operation2);
ref.addSubExpressionMapping(leafMapping);
String beforeWithoutCast = null;
if(before.startsWith("(") && before.contains(")")) {
beforeWithoutCast = before.substring(before.indexOf(")") + 1);
}
if(expression2.getString().endsWith(" " + variableName)) {
if(expression2.getString().contains(before)) {
ExtractVariableRefactoring ref = new ExtractVariableRefactoring(declaration, operation1, operation2, insideExtractedOrInlinedMethod);
List<LeafExpression> expressions1 = fragment1.findExpression(before);
for(LeafExpression expression1 : expressions1) {
LeafMapping leafMapping = new LeafMapping(expression1, expression2, operation1, operation2);
ref.addSubExpressionMapping(leafMapping);
}
processExtractVariableRefactoring(ref, refactorings);
//if(identical()) {
identicalWithInlinedVariable = true;
//}
return;
}
else if(beforeWithoutCast != null && expression2.getString().contains(beforeWithoutCast)) {
ExtractVariableRefactoring ref = new ExtractVariableRefactoring(declaration, operation1, operation2, insideExtractedOrInlinedMethod);
List<LeafExpression> expressions1 = fragment1.findExpression(beforeWithoutCast);
for(LeafExpression expression1 : expressions1) {
LeafMapping leafMapping = new LeafMapping(expression1, expression2, operation1, operation2);
ref.addSubExpressionMapping(leafMapping);
}
processExtractVariableRefactoring(ref, refactorings);
//if(identical()) {
identicalWithInlinedVariable = true;
//}
return;
}
processExtractVariableRefactoring(ref, refactorings);
//if(identical()) {
identicalWithInlinedVariable = true;
//}
return;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4730,6 +4730,11 @@ else if(replacements.size() == 1 && replacementInfo.getReplacements(ReplacementT
}
}
}
for(AbstractExpression expression : statement2.getExpressions()) {
if(expression.getPatternInstanceofExpressions().size() > 0) {
mapping.temporaryVariableAssignment(expression, leaves2, classDiff, parentMapper != null, mappings);
}
}
for(AbstractCodeFragment leaf : leaves1) {
if(leaf.getLocationInfo().before(mapping.getFragment1().getLocationInfo())) {
mapping.inlinedVariableAssignment(leaf, leaves2, classDiff, parentMapper != null);
Expand Down Expand Up @@ -5080,6 +5085,11 @@ else if(replacements.size() == 1 && replacementInfo.getReplacements(ReplacementT
}
}
}
for(AbstractExpression expression : statement2.getExpressions()) {
if(expression.getPatternInstanceofExpressions().size() > 0) {
mapping.temporaryVariableAssignment(expression, leaves2, classDiff, parentMapper != null, mappings);
}
}
for(AbstractCodeFragment leaf : leaves1) {
if(leaf.getLocationInfo().before(mapping.getFragment1().getLocationInfo())) {
mapping.inlinedVariableAssignment(leaf, leaves2, classDiff, parentMapper != null);
Expand Down

0 comments on commit 87b0460

Please sign in to comment.