Skip to content

Commit

Permalink
Fix SwitchFixOperation to not cause a MalformedTreeException (#1511)
Browse files Browse the repository at this point in the history
* Fix SwitchFixOperation to not cause a MalformedTreeException

- fix SwitchFixCore.SwitchFixOperation to copy the remaining statement
  without extended range to avoid a mismatch of length when the
  original if statement is replaced
- add trailing comment to test in CleanUpTest12 to emulate
  circumstances of failure
- fixes #1509

* Remove unused code
  • Loading branch information
jjohnstn authored Jul 16, 2024
1 parent 99c8987 commit 78f3cdb
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021, 2022 Fabrice TIERCELIN and others.
* Copyright (c) 2021, 2024 Fabrice TIERCELIN and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -354,6 +354,7 @@ public SourceRange computeSourceRange(final ASTNode nodeWithComment) {
}

if (remainingStatement != null) {
remainingStatement.setProperty(UNTOUCH_COMMENT_PROPERTY, Boolean.TRUE);
addCaseWithStatements(rewrite, ast, switchStatement, null, ASTNodes.asList(remainingStatement));
} else {
addCaseWithStatements(rewrite, ast, switchStatement, null, Collections.emptyList());
Expand Down Expand Up @@ -393,7 +394,7 @@ private void addCaseWithStatements(final ASTRewrite rewrite, final AST ast, fina
// Add the statement(s) for this case(s)
if (!innerStatements.isEmpty()) {
for (Statement statement : innerStatements) {
statementsList.add(ASTNodes.createMoveTarget(rewrite, statement));
statementsList.add((Statement) rewrite.createCopyTarget(statement));
}

isBreakNeeded= !ASTNodes.fallsThrough(innerStatements.get(innerStatements.size() - 1));
Expand Down
Loading

0 comments on commit 78f3cdb

Please sign in to comment.