TerminalBlock: preserve comments after continue statement (not in the proper place though)

This commit is contained in:
Tagir Valeev
2018-09-03 19:57:02 +07:00
parent 508007a3e2
commit a0f1b41336
3 changed files with 4 additions and 3 deletions
@@ -253,7 +253,7 @@ class TerminalBlock {
FilterOp filter = tb.getLastOperation(FilterOp.class);
if (filter == null) return this;
PsiBinaryExpression binOp = tryCast(PsiUtil.skipParenthesizedExprDown(filter.getExpression()), PsiBinaryExpression.class);
if (binOp == null || !ComparisonUtils.isComparison(binOp)) return this;
if (!ComparisonUtils.isComparison(binOp)) return this;
String comparison = filter.isNegated() ? ComparisonUtils.getNegatedComparison(binOp.getOperationTokenType())
: binOp.getOperationSign().getText();
boolean flipped = false;
@@ -477,7 +477,7 @@ class TerminalBlock {
}
StreamEx.ofTree(statement, (PsiElement s) -> StreamEx.of(s.getChildren()))
.select(PsiContinueStatement.class)
.forEach(stmt -> stmt.replace(factory.createStatementFromText("return;", null)));
.forEach(stmt -> new CommentTracker().replaceAndRestoreComments(stmt, "return;"));
}
}
@@ -5,6 +5,7 @@ import java.util.Collection;
public class Test {
void test(int[] arr) {
// comment
Arrays.stream(arr).forEach(x -> {
int y = x * 2;
if (x > y) return;
@@ -6,7 +6,7 @@ public class Test {
void test(int[] arr) {
for<caret>(int x : arr) {
int y = x*2;
if(x > y) continue;
if(x > y) continue; // comment
System.out.println(x);
}
}