mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java] Preserve comments in ReturnReplacementContext#stripUnnecessaryBlocks
#IDEA-369976 Fixed GitOrigin-RevId: d20a4a7d92ffb5fc7bda36c879868a2d3e2e8413
This commit is contained in:
committed by
intellij-monorepo-bot
parent
3ad99b5573
commit
d82a6a1d1a
+3
-3
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.codeInsight.intention.impl.singlereturn;
|
||||
|
||||
import com.intellij.codeInsight.BlockUtils;
|
||||
@@ -21,7 +21,7 @@ import static com.intellij.util.ObjectUtils.tryCast;
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
/**
|
||||
* Performs replacement of single return statement as the part of {@link ConvertToSingleReturnAction}.
|
||||
* Performs replacement of a single return statement as the part of {@link ConvertToSingleReturnAction}.
|
||||
*/
|
||||
final class ReturnReplacementContext {
|
||||
private final Project myProject;
|
||||
@@ -296,7 +296,7 @@ final class ReturnReplacementContext {
|
||||
if (parentIf != null && parentIf.getElseBranch() == place) {
|
||||
PsiIfStatement childIf = tryCast(ControlFlowUtils.stripBraces((PsiStatement)place), PsiIfStatement.class);
|
||||
if (childIf != null) {
|
||||
place = place.replace(childIf);
|
||||
place = new CommentTracker().replaceAndRestoreComments(place, childIf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// "Transform body to single exit-point form" "true-preview"
|
||||
class Test {
|
||||
int foo(int i) {
|
||||
int result = -1;
|
||||
// comment 1
|
||||
// comment 5
|
||||
// comment 6
|
||||
if (i == 0) { // comment 2
|
||||
// comment 3
|
||||
result = 1;// comment 4
|
||||
} else if (i == 1) { // comment 7
|
||||
// comment 8
|
||||
result = 0;// comment 9
|
||||
} // comment 10
|
||||
// comment 11
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// "Transform body to single exit-point form" "true-preview"
|
||||
class Test {
|
||||
int fo<caret>o(int i) {
|
||||
// comment 1
|
||||
if (i == 0) { // comment 2
|
||||
// comment 3
|
||||
return 1; // comment 4
|
||||
}
|
||||
// comment 5
|
||||
|
||||
// comment 6
|
||||
if (i == 1) { // comment 7
|
||||
// comment 8
|
||||
return 0; // comment 9
|
||||
}
|
||||
|
||||
// comment 10
|
||||
return -1; // comment 11
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user