Skip to content

Commit

Permalink
Fix for issue pouryafard75#108
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed Jun 20, 2024
1 parent 4ccb848 commit c233349
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/main/java/gr/uom/java/xmi/decomposition/AbstractCall.java
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,15 @@ private int argumentIsAssigned(String statement) {
return -1;
}

private boolean expressionIsAssigned(String statement) {
if(statement.contains(JAVA.ASSIGNMENT) && statement.endsWith(JAVA.STATEMENT_TERMINATION) && expression != null) {
if(equalsIgnoringExtraParenthesis(expression, statement.substring(statement.indexOf(JAVA.ASSIGNMENT)+1, statement.length()-JAVA.STATEMENT_TERMINATION.length()))) {
return true;
}
}
return false;
}

public Replacement makeReplacementForAssignedArgument(String statement) {
int index = argumentIsAssigned(statement);
if(index >= 0 && (arguments().size() == 1 || (statement.contains(" ? ") && statement.contains(" : ")))) {
Expand All @@ -1103,6 +1112,14 @@ public Replacement makeReplacementForAssignedArgument(String statement) {
return null;
}

public Replacement makeReplacementForAssignedExpression(String statement) {
if(expressionIsAssigned(statement)) {
return new Replacement(statement.substring(statement.indexOf(JAVA.ASSIGNMENT)+1, statement.length()-JAVA.STATEMENT_TERMINATION.length()),
expression, ReplacementType.EXPRESSION_REPLACED_WITH_RIGHT_HAND_SIDE_OF_ASSIGNMENT_EXPRESSION);
}
return null;
}

private static boolean equalsIgnoringExtraParenthesis(String s1, String s2) {
if(s1.equals(s2))
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2327,6 +2327,12 @@ else if(invocationCoveringTheEntireStatement1 != null && (r = invocationCovering
replacementInfo.addReplacement(r);
return replacementInfo.getReplacements();
}
//check if the expression of the method call in the second statement is the right hand side of an assignment in the first statement
if(invocationCoveringTheEntireStatement2 != null && variableDeclarations1.toString().equals(variableDeclarations2.toString()) && variableDeclarations1.size() > 0 &&
(r = invocationCoveringTheEntireStatement2.makeReplacementForAssignedExpression(replacementInfo.getArgumentizedString1())) != null) {
replacementInfo.addReplacement(r);
return replacementInfo.getReplacements();
}
//check if the method call in the second statement is the expression (or sub-expression) of the method invocation in the first statement
if(invocationCoveringTheEntireStatement2 != null) {
for(String key1 : methodInvocationMap1.keySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public enum ReplacementType {
ARGUMENT_REPLACED_WITH_STATEMENT,
ARGUMENT_REPLACED_WITH_EXPRESSION,
ARGUMENT_REPLACED_WITH_RIGHT_HAND_SIDE_OF_ASSIGNMENT_EXPRESSION,
EXPRESSION_REPLACED_WITH_RIGHT_HAND_SIDE_OF_ASSIGNMENT_EXPRESSION,
VARIABLE_REPLACED_WITH_METHOD_INVOCATION,
VARIABLE_REPLACED_WITH_CLASS_INSTANCE_CREATION,
VARIABLE_REPLACED_WITH_EXPRESSION_OF_METHOD_INVOCATION,
Expand Down

0 comments on commit c233349

Please sign in to comment.