diff --git a/src/main/java/gr/uom/java/xmi/decomposition/OperationInvocation.java b/src/main/java/gr/uom/java/xmi/decomposition/OperationInvocation.java index 7f3b5a6d3..79bbd589f 100644 --- a/src/main/java/gr/uom/java/xmi/decomposition/OperationInvocation.java +++ b/src/main/java/gr/uom/java/xmi/decomposition/OperationInvocation.java @@ -27,6 +27,8 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.eclipse.jdt.core.dom.ClassInstanceCreation; import org.eclipse.jdt.core.dom.CompilationUnit; @@ -45,6 +47,7 @@ public class OperationInvocation extends AbstractCall { private static Map> PRIMITIVE_TYPE_WIDENING_MAP; private static Map> PRIMITIVE_TYPE_NARROWING_MAP; private static List PRIMITIVE_TYPE_LIST; + private static final Pattern LAMBDA_ARROW = Pattern.compile(JAVA.LAMBDA_ARROW); static { PRIMITIVE_TYPE_LIST = new ArrayList<>(Arrays.asList("byte", "short", "int", "long", "float", "double", "char", "boolean")); @@ -828,6 +831,34 @@ public boolean identicalWithExpressionCallChainDifference(OperationInvocation ot return false; } + public boolean identicalPipeline(OperationInvocation other) { + if(this.expression != null && other.expression != null) { + Matcher m1 = LAMBDA_ARROW.matcher(this.expression); + Matcher m2 = LAMBDA_ARROW.matcher(other.expression); + List lambdaCalls1 = extractLambdaCalls(m1, this.expression); + List lambdaCalls2 = extractLambdaCalls(m2, other.expression); + if(lambdaCalls1.equals(lambdaCalls2) && lambdaCalls1.size() > 0) { + return true; + } + } + return false; + } + + private static List extractLambdaCalls(Matcher m, String expression) { + List lambdaCalls = new ArrayList(); + int start1 = 0; + while (m.find()) { + int start = m.start(); + String subString = expression.substring(start1, start); + if(subString.contains(".")) { + String s = subString.substring(subString.lastIndexOf("."), subString.length()); + lambdaCalls.add(s); + } + start1 = m.end(); + } + return lambdaCalls; + } + public String subExpressionIsCallToSameMethod() { for(String expression : subExpressions) { if(expression.startsWith(this.getName() + "(")) { diff --git a/src/main/java/gr/uom/java/xmi/decomposition/ReplacementAlgorithm.java b/src/main/java/gr/uom/java/xmi/decomposition/ReplacementAlgorithm.java index 9e1600303..051e3d870 100644 --- a/src/main/java/gr/uom/java/xmi/decomposition/ReplacementAlgorithm.java +++ b/src/main/java/gr/uom/java/xmi/decomposition/ReplacementAlgorithm.java @@ -1900,6 +1900,11 @@ else if(invokedOperationsAfter != null && invokedOperationsAfter.size() > 0) { return replacementInfo.getReplacements(); } } + else if(((OperationInvocation)invocationCoveringTheEntireStatement1).identicalPipeline((OperationInvocation)invocationCoveringTheEntireStatement2)) { + Replacement replacement = new MethodInvocationReplacement(invocationCoveringTheEntireStatement1.actualString(), invocationCoveringTheEntireStatement2.actualString(), invocationCoveringTheEntireStatement1, invocationCoveringTheEntireStatement2, ReplacementType.METHOD_INVOCATION); + replacementInfo.addReplacement(replacement); + return replacementInfo.getReplacements(); + } String expression1 = invocationCoveringTheEntireStatement1.getExpression(); String expression2 = invocationCoveringTheEntireStatement2.getExpression(); boolean staticVSNonStatic = (expression1 == null && expression2 != null && container1 != null && container1.getClassName().endsWith("." + expression2)) || diff --git a/src/test/resources/mappings/jabref-12025.txt b/src/test/resources/mappings/jabref-12025.txt index 5379f9da5..2fa2b7676 100644 --- a/src/test/resources/mappings/jabref-12025.txt +++ b/src/test/resources/mappings/jabref-12025.txt @@ -1,5 +1,6 @@ public fetchAndMerge(entry BibEntry, fields List) : void -> private executeFetchTask(fetcher IdBasedFetcher, field Field, entry BibEntry) : void line range:75-75==line range:73-78 +line range:79-100==line range:74-77 public fetchAndMerge(entry BibEntry, fields List) : void -> private fetchAndMergeEntry(entry BibEntry, field Field) : void line range:78-78==line range:67-69 line range:77-77==line range:68-68