Skip to content

Commit

Permalink
onlyArgumentsChanged() takes into account varArgs parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed Dec 17, 2024
1 parent 03f108e commit dddf17c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
12 changes: 6 additions & 6 deletions src/main/java/gr/uom/java/xmi/decomposition/AbstractCall.java
Original file line number Diff line number Diff line change
Expand Up @@ -723,11 +723,11 @@ public boolean methodNameContainsArgumentName() {
return false;
}

private boolean onlyArgumentsChanged(AbstractCall call, Set<Replacement> replacements, Map<String, String> parameterToArgumentMap) {
private boolean onlyArgumentsChanged(AbstractCall call, Set<Replacement> replacements, Map<String, String> parameterToArgumentMap, boolean varArgsParameter) {
return identicalExpression(call, replacements, parameterToArgumentMap) &&
identicalName(call) &&
!equalArguments(call) &&
arguments().size() != call.arguments().size();
(arguments().size() != call.arguments().size() || varArgsParameter);
}

public boolean identicalWithOnlyChangesInAnonymousClassArguments(AbstractCall call, Set<Replacement> replacements, Map<String, String> parameterToArgumentMap) {
Expand All @@ -737,8 +737,8 @@ public boolean identicalWithOnlyChangesInAnonymousClassArguments(AbstractCall ca
equalArgumentsExceptForAnonymousClassArguments(call);
}

public boolean identicalWithMergedArguments(AbstractCall call, Set<Replacement> replacements, Map<String, String> parameterToArgumentMap) {
if(onlyArgumentsChanged(call, replacements, parameterToArgumentMap)) {
public boolean identicalWithMergedArguments(AbstractCall call, Set<Replacement> replacements, Map<String, String> parameterToArgumentMap, boolean varArgsParameter) {
if(onlyArgumentsChanged(call, replacements, parameterToArgumentMap, varArgsParameter)) {
List<String> updatedArguments1 = new ArrayList<String>(this.arguments);
Map<String, Set<Replacement>> commonVariableReplacementMap = new LinkedHashMap<String, Set<Replacement>>();
for(Replacement replacement : replacements) {
Expand Down Expand Up @@ -782,8 +782,8 @@ public boolean identicalWithMergedArguments(AbstractCall call, Set<Replacement>
return false;
}

public boolean identicalWithDifferentNumberOfArguments(AbstractCall call, Set<Replacement> replacements, Map<String, String> parameterToArgumentMap) {
if(onlyArgumentsChanged(call, replacements, parameterToArgumentMap)) {
public boolean identicalWithDifferentNumberOfArguments(AbstractCall call, Set<Replacement> replacements, Map<String, String> parameterToArgumentMap, boolean varArgsParameter) {
if(onlyArgumentsChanged(call, replacements, parameterToArgumentMap, varArgsParameter)) {
int argumentIntersectionSize = argumentIntersectionSize(call, replacements, parameterToArgumentMap);
if(argumentIntersectionSize > 0 || arguments().size() == 0 || call.arguments().size() == 0) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2151,11 +2151,12 @@ else if(!variableDeclarations1.get(0).getVariableName().equals(variableDeclarati
}
}
//method invocation has only changes in the arguments (different number of arguments)
boolean varArgsParameter = container1.hasVarargsParameter() || container2.hasVarargsParameter();
if(invocationCoveringTheEntireStatement1 != null && invocationCoveringTheEntireStatement2 != null) {
if(invocationCoveringTheEntireStatement1.identicalWithMergedArguments(invocationCoveringTheEntireStatement2, replacementInfo.getReplacements(), parameterToArgumentMap)) {
if(invocationCoveringTheEntireStatement1.identicalWithMergedArguments(invocationCoveringTheEntireStatement2, replacementInfo.getReplacements(), parameterToArgumentMap, varArgsParameter)) {
return replacementInfo.getReplacements();
}
else if(invocationCoveringTheEntireStatement1.identicalWithDifferentNumberOfArguments(invocationCoveringTheEntireStatement2, replacementInfo.getReplacements(), parameterToArgumentMap)) {
else if(invocationCoveringTheEntireStatement1.identicalWithDifferentNumberOfArguments(invocationCoveringTheEntireStatement2, replacementInfo.getReplacements(), parameterToArgumentMap, varArgsParameter)) {
Replacement replacement = new MethodInvocationReplacement(invocationCoveringTheEntireStatement1.actualString(),
invocationCoveringTheEntireStatement2.actualString(), invocationCoveringTheEntireStatement1, invocationCoveringTheEntireStatement2, ReplacementType.METHOD_INVOCATION_ARGUMENT);
replacementInfo.addReplacement(replacement);
Expand All @@ -2179,10 +2180,10 @@ else if(invocationCoveringTheEntireStatement1.inlinedStatementBecomesAdditionalA
if(!methodInvocations1.isEmpty() && invocationCoveringTheEntireStatement2 != null) {
for(String methodInvocation1 : methodInvocations1) {
for(AbstractCall operationInvocation1 : methodInvocationMap1.get(methodInvocation1)) {
if(operationInvocation1.identicalWithMergedArguments(invocationCoveringTheEntireStatement2, replacementInfo.getReplacements(), parameterToArgumentMap)) {
if(operationInvocation1.identicalWithMergedArguments(invocationCoveringTheEntireStatement2, replacementInfo.getReplacements(), parameterToArgumentMap, varArgsParameter)) {
return replacementInfo.getReplacements();
}
else if(operationInvocation1.identicalWithDifferentNumberOfArguments(invocationCoveringTheEntireStatement2, replacementInfo.getReplacements(), parameterToArgumentMap)) {
else if(operationInvocation1.identicalWithDifferentNumberOfArguments(invocationCoveringTheEntireStatement2, replacementInfo.getReplacements(), parameterToArgumentMap, varArgsParameter)) {
Replacement replacement = new MethodInvocationReplacement(operationInvocation1.actualString(),
invocationCoveringTheEntireStatement2.actualString(), operationInvocation1, invocationCoveringTheEntireStatement2, ReplacementType.METHOD_INVOCATION_ARGUMENT);
replacementInfo.addReplacement(replacement);
Expand Down Expand Up @@ -2724,7 +2725,7 @@ else if(invocationCoveringTheEntireStatement2.getExpression() != null && invocat
}
//object creation has only changes in the arguments
if(creationCoveringTheEntireStatement1 != null && creationCoveringTheEntireStatement2 != null) {
if(creationCoveringTheEntireStatement1.identicalWithMergedArguments(creationCoveringTheEntireStatement2, replacementInfo.getReplacements(), parameterToArgumentMap)) {
if(creationCoveringTheEntireStatement1.identicalWithMergedArguments(creationCoveringTheEntireStatement2, replacementInfo.getReplacements(), parameterToArgumentMap, varArgsParameter)) {
return replacementInfo.getReplacements();
}
else if(creationCoveringTheEntireStatement1.reorderedArguments(creationCoveringTheEntireStatement2)) {
Expand All @@ -2733,7 +2734,7 @@ else if(creationCoveringTheEntireStatement1.reorderedArguments(creationCoveringT
replacementInfo.addReplacement(replacement);
return replacementInfo.getReplacements();
}
else if(creationCoveringTheEntireStatement1.identicalWithDifferentNumberOfArguments(creationCoveringTheEntireStatement2, replacementInfo.getReplacements(), parameterToArgumentMap)) {
else if(creationCoveringTheEntireStatement1.identicalWithDifferentNumberOfArguments(creationCoveringTheEntireStatement2, replacementInfo.getReplacements(), parameterToArgumentMap, varArgsParameter)) {
Replacement replacement = new ObjectCreationReplacement(creationCoveringTheEntireStatement1.actualString(),
creationCoveringTheEntireStatement2.actualString(), creationCoveringTheEntireStatement1, creationCoveringTheEntireStatement2, ReplacementType.CLASS_INSTANCE_CREATION_ARGUMENT);
replacementInfo.addReplacement(replacement);
Expand Down Expand Up @@ -2795,7 +2796,7 @@ else if(creationCoveringTheEntireStatement1.inlinedStatementBecomesAdditionalArg
if(!creations1.isEmpty() && creationCoveringTheEntireStatement2 != null) {
for(String creation1 : creations1) {
for(AbstractCall objectCreation1 : creationMap1.get(creation1)) {
if(objectCreation1.identicalWithMergedArguments(creationCoveringTheEntireStatement2, replacementInfo.getReplacements(), parameterToArgumentMap)) {
if(objectCreation1.identicalWithMergedArguments(creationCoveringTheEntireStatement2, replacementInfo.getReplacements(), parameterToArgumentMap, varArgsParameter)) {
return replacementInfo.getReplacements();
}
else if(objectCreation1.reorderedArguments(creationCoveringTheEntireStatement2)) {
Expand All @@ -2804,7 +2805,7 @@ else if(objectCreation1.reorderedArguments(creationCoveringTheEntireStatement2))
replacementInfo.addReplacement(replacement);
return replacementInfo.getReplacements();
}
else if(objectCreation1.identicalWithDifferentNumberOfArguments(creationCoveringTheEntireStatement2, replacementInfo.getReplacements(), parameterToArgumentMap)) {
else if(objectCreation1.identicalWithDifferentNumberOfArguments(creationCoveringTheEntireStatement2, replacementInfo.getReplacements(), parameterToArgumentMap, varArgsParameter)) {
Replacement replacement = new ObjectCreationReplacement(objectCreation1.actualString(),
creationCoveringTheEntireStatement2.actualString(), (ObjectCreation)objectCreation1, creationCoveringTheEntireStatement2, ReplacementType.CLASS_INSTANCE_CREATION_ARGUMENT);
replacementInfo.addReplacement(replacement);
Expand Down Expand Up @@ -4899,6 +4900,7 @@ private static boolean processAnonymous(AbstractCodeFragment statement1, Abstrac
UMLOperationBodyMapper operationBodyMapper) throws RefactoringMinerTimedOutException {
VariableDeclarationContainer container1 = operationBodyMapper.getContainer1();
VariableDeclarationContainer container2 = operationBodyMapper.getContainer2();
boolean varArgsParameter = container1.hasVarargsParameter() || container2.hasVarargsParameter();
UMLAbstractClassDiff classDiff = operationBodyMapper.getClassDiff();
UMLModelDiff modelDiff = operationBodyMapper.getModelDiff();
UMLOperationBodyMapper parentMapper = operationBodyMapper.getParentMapper();
Expand All @@ -4911,8 +4913,8 @@ private static boolean processAnonymous(AbstractCodeFragment statement1, Abstrac
(onlyDifferentInvoker(statementWithoutAnonymous1, statementWithoutAnonymous2, invocationCoveringTheEntireStatement1, invocationCoveringTheEntireStatement2) ||
invocationCoveringTheEntireStatement1.identical(invocationCoveringTheEntireStatement2, replacementInfo.getReplacements(), parameterToArgumentMap, lambdaMappers) ||
invocationCoveringTheEntireStatement1.identicalWithOnlyChangesInAnonymousClassArguments(invocationCoveringTheEntireStatement2, replacementInfo.getReplacements(), parameterToArgumentMap) ||
invocationCoveringTheEntireStatement1.identicalWithMergedArguments(invocationCoveringTheEntireStatement2, replacementInfo.getReplacements(), parameterToArgumentMap) ||
invocationCoveringTheEntireStatement1.identicalWithDifferentNumberOfArguments(invocationCoveringTheEntireStatement2, replacementInfo.getReplacements(), parameterToArgumentMap) ||
invocationCoveringTheEntireStatement1.identicalWithMergedArguments(invocationCoveringTheEntireStatement2, replacementInfo.getReplacements(), parameterToArgumentMap, varArgsParameter) ||
invocationCoveringTheEntireStatement1.identicalWithDifferentNumberOfArguments(invocationCoveringTheEntireStatement2, replacementInfo.getReplacements(), parameterToArgumentMap, varArgsParameter) ||
invocationCoveringTheEntireStatement1.makeReplacementForReturnedArgument(replacementInfo.getArgumentizedString2()) != null ||
(invocationCoveringTheEntireStatement1 instanceof ObjectCreation && invocationCoveringTheEntireStatement2 instanceof ObjectCreation && invocationCoveringTheEntireStatement1.identicalName(invocationCoveringTheEntireStatement2))))) {
UMLAnonymousClass anonymousClass1 = operationBodyMapper.findAnonymousClass1(anonymousClassDeclaration1);
Expand Down

0 comments on commit dddf17c

Please sign in to comment.