preserve comments: extract if with end of line comments

This commit is contained in:
Anna.Kozlova
2017-11-27 16:14:35 +01:00
parent f6f68c5d42
commit ab80e0dcdd
3 changed files with 7 additions and 7 deletions

View File

@@ -218,14 +218,14 @@ public class ExtractIfConditionAction extends PsiElementBaseIntentionAction {
private static String createIfString(@NotNull String condition,
@NotNull String thenBranch,
@Nullable String elseBranch) {
final String elsePart = elseBranch != null ? " else " + elseBranch : "";
final String elsePart = elseBranch != null ? "\n else " + elseBranch : "";
return "if (" + condition + ")\n" + thenBranch + elsePart;
}
@NotNull
private static String toThenBranchString(@NotNull PsiStatement statement) {
if (!(statement instanceof PsiBlockStatement)) {
return "{ " + statement.getText() + " }";
return "{ " + statement.getText() + "\n }";
}
return statement.getText();
@@ -241,7 +241,7 @@ public class ExtractIfConditionAction extends PsiElementBaseIntentionAction {
return statement.getText();
}
return "{ " + statement.getText() + " }";
return "{ " + statement.getText() + "\n }";
}
@Nullable

View File

@@ -3,7 +3,7 @@ class TestThreadInspection {
void f(boolean a, boolean b, boolean c){
if (a)
if (b) {
System.out.println("a&b");
System.out.println("a&b");//first comment
} else {
if (c) {
System.out.println("c");

View File

@@ -1,9 +1,9 @@
// "Extract if (a)" "true"
class TestThreadInspection {
void f(boolean a, boolean b, boolean c){
if (<caret>a && b) {
System.out.println("a&b");
} else if (c) {
if (<caret>a && b)
System.out.println("a&b");//first comment
else if (c) {
System.out.println("c");
}
}