Skip to content

Commit

Permalink
Support detection of Extract Variable in commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed Jan 18, 2025
1 parent 4ba4e4d commit b41b988
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,7 @@ else if(after.startsWith(variableName + " ") && initializer != null) {
infixOperandMatch(initializer, before) ||
wrappedAsArgument(initializer, before) ||
stringConcatMatch(initializer, before) ||
diamondClassInstanceCreationMatch(initializer, before) ||
reservedTokenMatch(initializer, replacement, before) ||
anonymousWithMethodSignatureChange(initializer, before, classDiff)) {
ExtractVariableRefactoring ref = new ExtractVariableRefactoring(declaration, operation1, operation2, insideExtractedOrInlinedMethod);
Expand Down Expand Up @@ -1072,6 +1073,7 @@ else if(before.startsWith("()" + JAVA.LAMBDA_ARROW + variableName + ".")) {
infixOperandMatch(initializer, after) ||
wrappedAsArgument(initializer, after) ||
stringConcatMatch(initializer, after) ||
diamondClassInstanceCreationMatch(initializer, after) ||
reservedTokenMatch(initializer, replacement, after) ||
anonymousWithMethodSignatureChange(initializer, after, classDiff)) {
InlineVariableRefactoring ref = new InlineVariableRefactoring(declaration, operation1, operation2, insideExtractedOrInlinedMethod);
Expand Down Expand Up @@ -1403,6 +1405,19 @@ private boolean ternaryMatch(AbstractExpression initializer, String replacedExpr
return false;
}

private boolean diamondClassInstanceCreationMatch(AbstractExpression initializer, String replacedExpression) {
if(initializer.getString().startsWith("new ") && replacedExpression.startsWith("new ")) {
if(initializer.getString().contains("<") && replacedExpression.contains("<")) {
String type1 = initializer.getString().substring(0, initializer.getString().indexOf("<"));
String type2 = replacedExpression.substring(0, replacedExpression.indexOf("<"));
if(type1.equals(type2)) {
return true;
}
}
}
return false;
}

private boolean stringConcatMatch(AbstractExpression initializer, String replacedExpression) {
String s1 = initializer.getString();
String s2 = replacedExpression;
Expand Down

0 comments on commit b41b988

Please sign in to comment.