Skip to content

Commit

Permalink
Further improvement for issue #792
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed Oct 28, 2024
1 parent e3226f8 commit 5d024c6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -45,6 +47,7 @@ public class OperationInvocation extends AbstractCall {
private static Map<String, List<String>> PRIMITIVE_TYPE_WIDENING_MAP;
private static Map<String, List<String>> PRIMITIVE_TYPE_NARROWING_MAP;
private static List<String> 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"));
Expand Down Expand Up @@ -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<String> lambdaCalls1 = extractLambdaCalls(m1, this.expression);
List<String> lambdaCalls2 = extractLambdaCalls(m2, other.expression);
if(lambdaCalls1.equals(lambdaCalls2) && lambdaCalls1.size() > 0) {
return true;
}
}
return false;
}

private static List<String> extractLambdaCalls(Matcher m, String expression) {
List<String> lambdaCalls = new ArrayList<String>();
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() + "(")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) ||
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/mappings/jabref-12025.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
public fetchAndMerge(entry BibEntry, fields List<Field>) : 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<Field>) : void -> private fetchAndMergeEntry(entry BibEntry, field Field) : void
line range:78-78==line range:67-69
line range:77-77==line range:68-68
Expand Down

0 comments on commit 5d024c6

Please sign in to comment.