Skip to content

Commit

Permalink
Enable Inline Method detection in commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed Dec 27, 2024
1 parent f42ea55 commit 623030f
Showing 1 changed file with 39 additions and 8 deletions.
47 changes: 39 additions & 8 deletions src/main/java/gr/uom/java/xmi/decomposition/AbstractCall.java
Original file line number Diff line number Diff line change
Expand Up @@ -1085,24 +1085,55 @@ private int argumentIsThrown(String statement) {
return -1;
}

private int argumentIsWrappedInExceptionAndThrown(String statement) {
if(statement.startsWith(JAVA.THROW_SPACE)) {
String removeThrowFromStatement = statement.substring(JAVA.THROW_SPACE.length(), statement.length()-JAVA.STATEMENT_TERMINATION.length());
int index = 0;
for(String argument : arguments()) {
if(argument.equals("true") || argument.equals("false") || argument.equals("null")) {
return -1;
}
if(argument.startsWith("()" + JAVA.LAMBDA_ARROW))
argument = argument.substring(("()" + JAVA.LAMBDA_ARROW).length());
if(removeThrowFromStatement.contains("(" + argument + ")")) {
removeThrowFromStatement = removeThrowFromStatement.replace("(" + argument + ")", "");
if(removeThrowFromStatement.startsWith("new ") && removeThrowFromStatement.endsWith("Exception")) {
return index;
}
}
index++;
}
}
return -1;
}

private boolean indexCondition(String statement, int index) {
return (arguments().size() <= 2 && (index == 0 || this.getName().equals("assertThrows") || "Assert".equals(this.getExpression()))) || (statement.contains(" ? ") && statement.contains(" : "));
}

public Replacement makeReplacementForReturnedArgument(String statement) {
int index = -1;
if((index = argumentIsReturned(statement)) != -1 && ((arguments().size() <= 2 && (index == 0 || this.getName().equals("assertThrows"))) || (statement.contains(" ? ") && statement.contains(" : ")))) {
if((index = argumentIsReturned(statement)) != -1 && indexCondition(statement, index)) {
String arg = statement.substring(JAVA.RETURN_SPACE.length(), statement.length()-JAVA.STATEMENT_TERMINATION.length());
return new Replacement(arguments().get(index), arg,
ReplacementType.ARGUMENT_REPLACED_WITH_RETURN_EXPRESSION);
}
else if((index = argumentIsThrown(statement)) != -1 && ((arguments().size() <= 2 && (index == 0 || this.getName().equals("assertThrows"))) || (statement.contains(" ? ") && statement.contains(" : ")))) {
else if((index = argumentIsThrown(statement)) != -1 && indexCondition(statement, index)) {
String arg = statement.substring(JAVA.THROW_SPACE.length(), statement.length()-JAVA.STATEMENT_TERMINATION.length());
return new Replacement(arguments().get(index), arg,
ReplacementType.ARGUMENT_REPLACED_WITH_THROW_EXPRESSION);
}
else if((index = argumentIsWrappedInExceptionAndThrown(statement)) != -1 && indexCondition(statement, index)) {
String arg = statement.substring(JAVA.THROW_SPACE.length(), statement.length()-JAVA.STATEMENT_TERMINATION.length());
return new Replacement(arguments().get(index), arg,
ReplacementType.ARGUMENT_REPLACED_WITH_THROW_EXPRESSION);
}
else if((index = argumentIsStatement(statement)) != -1 && ((arguments().size() <= 2 && (index == 0 || this.getName().equals("assertThrows"))) || (statement.contains(" ? ") && statement.contains(" : ")))) {
else if((index = argumentIsStatement(statement)) != -1 && indexCondition(statement, index)) {
String arg = statement.substring(0, statement.length()-JAVA.STATEMENT_TERMINATION.length());
return new Replacement(arguments().get(index), arg,
ReplacementType.ARGUMENT_REPLACED_WITH_STATEMENT);
}
else if((index = argumentIsExpression(statement)) != -1 && ((arguments().size() <= 2 && (index == 0 || this.getName().equals("assertThrows"))) || (statement.contains(" ? ") && statement.contains(" : ")))) {
else if((index = argumentIsExpression(statement)) != -1 && indexCondition(statement, index)) {
return new Replacement(arguments().get(index), statement,
ReplacementType.ARGUMENT_REPLACED_WITH_EXPRESSION);
}
Expand All @@ -1111,22 +1142,22 @@ else if((index = argumentIsExpression(statement)) != -1 && ((arguments().size()

public Replacement makeReplacementForWrappedCall(String statement) {
int index = -1;
if((index = argumentIsReturned(statement)) != -1 && ((arguments().size() <= 2 && (index == 0 || this.getName().equals("assertThrows"))) || (statement.contains(" ? ") && statement.contains(" : ")))) {
if((index = argumentIsReturned(statement)) != -1 && indexCondition(statement, index)) {
String arg = statement.substring(JAVA.RETURN_SPACE.length(), statement.length()-JAVA.STATEMENT_TERMINATION.length());
return new Replacement(arg, arguments().get(index),
ReplacementType.ARGUMENT_REPLACED_WITH_RETURN_EXPRESSION);
}
else if((index = argumentIsThrown(statement)) != -1 && ((arguments().size() <= 2 && (index == 0 || this.getName().equals("assertThrows"))) || (statement.contains(" ? ") && statement.contains(" : ")))) {
else if((index = argumentIsThrown(statement)) != -1 && indexCondition(statement, index)) {
String arg = statement.substring(JAVA.THROW_SPACE.length(), statement.length()-JAVA.STATEMENT_TERMINATION.length());
return new Replacement(arg, arguments().get(index),
ReplacementType.ARGUMENT_REPLACED_WITH_THROW_EXPRESSION);
}
else if((index = argumentIsStatement(statement)) != -1 && ((arguments().size() <= 2 && (index == 0 || this.getName().equals("assertThrows"))) || (statement.contains(" ? ") && statement.contains(" : ")))) {
else if((index = argumentIsStatement(statement)) != -1 && indexCondition(statement, index)) {
String arg = statement.substring(0, statement.length()-JAVA.STATEMENT_TERMINATION.length());
return new Replacement(arg, arguments().get(index),
ReplacementType.ARGUMENT_REPLACED_WITH_STATEMENT);
}
else if((index = argumentIsExpression(statement)) != -1 && ((arguments().size() <= 2 && (index == 0 || this.getName().equals("assertThrows"))) || (statement.contains(" ? ") && statement.contains(" : ")))) {
else if((index = argumentIsExpression(statement)) != -1 && indexCondition(statement, index)) {
return new Replacement(statement, arguments().get(index),
ReplacementType.ARGUMENT_REPLACED_WITH_EXPRESSION);
}
Expand Down

0 comments on commit 623030f

Please sign in to comment.