From b41b9880e10a4fc020fa1d079801f17bca1e6188 Mon Sep 17 00:00:00 2001 From: tsantalis Date: Sat, 18 Jan 2025 18:02:22 -0500 Subject: [PATCH] Support detection of Extract Variable in commit https://github.com/mockito/mockito/commit/331ff01c5f840ff8a3c5b0859185ba78f9446cf0 --- .../xmi/decomposition/AbstractCodeMapping.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/java/gr/uom/java/xmi/decomposition/AbstractCodeMapping.java b/src/main/java/gr/uom/java/xmi/decomposition/AbstractCodeMapping.java index de4dac82d..9fa9299c5 100644 --- a/src/main/java/gr/uom/java/xmi/decomposition/AbstractCodeMapping.java +++ b/src/main/java/gr/uom/java/xmi/decomposition/AbstractCodeMapping.java @@ -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); @@ -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); @@ -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;