Skip to content

Commit

Permalink
Initial fix for issue #679
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed Mar 18, 2024
1 parent d03028a commit 03e7469
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3268,6 +3268,22 @@ else if(creationCoveringTheEntireStatement2 != null && variableReturn1) {
replacementInfo.addReplacement(replacement);
}
}
if(booleanLiterals1.size() == 1 && statement2.getInfixExpressions().size() == 1) {
boolean returnBoolean1 = statement1.getString().equals(JAVA.RETURN_SPACE + statement1.getBooleanLiterals().get(0).getString() + JAVA.STATEMENT_TERMINATION);
boolean returnInfix2 = statement2.getString().equals(JAVA.RETURN_SPACE + statement2.getInfixExpressions().get(0).getString() + JAVA.STATEMENT_TERMINATION);
if(returnBoolean1 && returnInfix2) {
Replacement replacement = new Replacement(statement1.getBooleanLiterals().get(0).getString(), statement2.getInfixExpressions().get(0).getString(), ReplacementType.BOOLEAN_REPLACED_WITH_INFIX_EXPRESSION);
replacementInfo.addReplacement(replacement);
}
}
if(booleanLiterals2.size() == 1 && statement1.getInfixExpressions().size() == 1) {
boolean returnBoolean2 = statement2.getString().equals(JAVA.RETURN_SPACE + statement2.getBooleanLiterals().get(0).getString() + JAVA.STATEMENT_TERMINATION);
boolean returnInfix1 = statement1.getString().equals(JAVA.RETURN_SPACE + statement1.getInfixExpressions().get(0).getString() + JAVA.STATEMENT_TERMINATION);
if(returnBoolean2 && returnInfix1) {
Replacement replacement = new Replacement(statement1.getInfixExpressions().get(0).getString(), statement2.getBooleanLiterals().get(0).getString(), ReplacementType.BOOLEAN_REPLACED_WITH_INFIX_EXPRESSION);
replacementInfo.addReplacement(replacement);
}
}
return replacementInfo.getReplacements();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,8 @@ else if(streamAPIStatements1.size() > 0 && streamAPIStatements2.size() == 0) {
}
}
if(remainingUnmatchedIfStatements1 > 0 && mapping instanceof LeafMapping && mapping.getFragment1().getTernaryOperatorExpressions().size() == 0 &&
mapping.getFragment2().getTernaryOperatorExpressions().size() > 0 && !leaves2.contains(mapping.getFragment2())) {
(mapping.getFragment2().getTernaryOperatorExpressions().size() > 0 || mapping.getFragment2().getString().contains(" == ") || mapping.getFragment2().getString().contains(" != ")) &&
!leaves2.contains(mapping.getFragment2())) {
leaves2.add(mapping.getFragment2());
//remove from hashCodes, so that it can be re-matched
mappingHashcodesT2.remove(mapping.getFragment2().hashCode());
Expand Down Expand Up @@ -7481,7 +7482,8 @@ private boolean canBeAdded(LeafMapping minStatementMapping, Map<String, String>
for(AbstractCodeMapping mapping : mappings) {
if(mapping.getFragment1().equals(minStatementMapping.getFragment1()) ||
mapping.getFragment2().equals(minStatementMapping.getFragment2())) {
conflictingMappingFound = true;
if(newMappingReplacents > 0)
conflictingMappingFound = true;
int oldMappingReplacements = validReplacements(mapping, parameterToArgumentMap);
if(newMappingReplacents < oldMappingReplacements) {
mappingToBeRemoved = mapping;
Expand All @@ -7503,6 +7505,9 @@ private int validReplacements(AbstractCodeMapping mapping, Map<String, String> p
for(Replacement r : mapping.getReplacements()) {
if(parameterToArgumentMap.containsKey(r.getAfter()) && parameterToArgumentMap.get(r.getAfter()).equals(r.getBefore())) {

}
else if(r.getType().equals(ReplacementType.INFIX_OPERATOR)) {

}
else {
validReplacements++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public enum ReplacementType {
VARIABLE_DECLARATION_INITIALIZER,
BOOLEAN_REPLACED_WITH_VARIABLE,
BOOLEAN_REPLACED_WITH_PREFIX_EXPRESSION,
BOOLEAN_REPLACED_WITH_INFIX_EXPRESSION,
BOOLEAN_REPLACED_WITH_ARGUMENT,
TYPE_LITERAL_REPLACED_WITH_VARIABLE,
STRING_LITERAL_REPLACED_WITH_CHAR_LITERAL,
Expand Down

0 comments on commit 03e7469

Please sign in to comment.