mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
extract if condition: ensure brackets (IDEA-134698)
This commit is contained in:
+4
-4
@@ -186,7 +186,7 @@ public class ExtractIfConditionAction extends PsiElementBaseIntentionAction {
|
||||
private static String createIfString(@NotNull PsiExpression condition,
|
||||
@NotNull PsiStatement thenBranch,
|
||||
@Nullable PsiStatement elseBranch) {
|
||||
return createIfString(condition.getText(), toThenBranchString(thenBranch), toElseBranchString(elseBranch));
|
||||
return createIfString(condition.getText(), toThenBranchString(thenBranch), toElseBranchString(elseBranch, false));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -200,7 +200,7 @@ public class ExtractIfConditionAction extends PsiElementBaseIntentionAction {
|
||||
private static String createIfString(@NotNull PsiExpression condition,
|
||||
@NotNull String thenBranch,
|
||||
@Nullable PsiStatement elseBranch) {
|
||||
return createIfString(condition.getText(), thenBranch, toElseBranchString(elseBranch));
|
||||
return createIfString(condition.getText(), thenBranch, toElseBranchString(elseBranch, true));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -221,12 +221,12 @@ public class ExtractIfConditionAction extends PsiElementBaseIntentionAction {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String toElseBranchString(@Nullable PsiStatement statement) {
|
||||
private static String toElseBranchString(@Nullable PsiStatement statement, boolean skipElse) {
|
||||
if (statement == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (statement instanceof PsiBlockStatement || statement instanceof PsiIfStatement) {
|
||||
if (statement instanceof PsiBlockStatement || skipElse && statement instanceof PsiIfStatement) {
|
||||
return statement.getText();
|
||||
}
|
||||
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// "Extract if (a)" "true"
|
||||
class TestThreadInspection {
|
||||
void f(boolean a, boolean b, boolean c){
|
||||
if (a)
|
||||
if (b) {
|
||||
System.out.println("a&b");
|
||||
} else {
|
||||
if (c) {
|
||||
System.out.println("c");
|
||||
}
|
||||
}
|
||||
else if (c) {
|
||||
System.out.println("c");
|
||||
}
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Extract if (a)" "true"
|
||||
class TestThreadInspection {
|
||||
void f(boolean a, boolean b, boolean c){
|
||||
if (a)
|
||||
if (b) {
|
||||
System.out.println("a&b");
|
||||
}
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// "Extract if (a)" "true"
|
||||
class TestThreadInspection {
|
||||
void f(boolean a, boolean b, boolean c){
|
||||
if (a) {
|
||||
System.out.println("a&b");
|
||||
} else if (b) {
|
||||
System.out.println("a&b");
|
||||
} else {
|
||||
if (c) {
|
||||
System.out.println("c");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Extract if (a)" "true"
|
||||
class TestThreadInspection {
|
||||
void f(boolean a, boolean b, boolean c){
|
||||
if (a) {
|
||||
System.out.println("a&b");
|
||||
} else if (b) {
|
||||
System.out.println("a&b");
|
||||
} else {
|
||||
System.out.println("c");
|
||||
}
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// "Extract if (a)" "true"
|
||||
class TestThreadInspection {
|
||||
void f(boolean a, boolean b, boolean c){
|
||||
if (a)
|
||||
if (b) {
|
||||
System.out.println("a&b");
|
||||
} else {
|
||||
System.out.println("c");
|
||||
}
|
||||
else {
|
||||
System.out.println("c");
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "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) {
|
||||
System.out.println("c");
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// "Extract if (a)" "true"
|
||||
class TestThreadInspection {
|
||||
void f(boolean a, boolean b, boolean c){
|
||||
if (<caret>a && b) {
|
||||
System.out.println("a&b");
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "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) {
|
||||
System.out.println("c");
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Extract if (a)" "true"
|
||||
class TestThreadInspection {
|
||||
void f(boolean a, boolean b, boolean c){
|
||||
if (<caret>a || b) {
|
||||
System.out.println("a&b");
|
||||
} else {
|
||||
System.out.println("c");
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Extract if (a)" "true"
|
||||
class TestThreadInspection {
|
||||
void f(boolean a, boolean b, boolean c){
|
||||
if (<caret>a && b) {
|
||||
System.out.println("a&b");
|
||||
} else {
|
||||
System.out.println("c");
|
||||
}
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.codeInsight.daemon.quickFix;
|
||||
|
||||
|
||||
|
||||
public class ExtractIfConditionTest extends LightQuickFixParameterizedTestCase {
|
||||
|
||||
public void test() throws Exception { doAllTests(); }
|
||||
|
||||
@Override
|
||||
protected String getBasePath() {
|
||||
return "/codeInsight/daemonCodeAnalyzer/quickFix/extractIfCondition";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user