mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-152224 Unwrap if should check if there are conflicting variables
This commit is contained in:
+4
-2
@@ -35,6 +35,7 @@ import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.siyeh.ig.psiutils.ParenthesesUtils;
|
||||
import com.siyeh.ig.psiutils.VariableSearchUtils;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -130,14 +131,15 @@ public class SimplifyBooleanExpressionFix extends LocalQuickFixOnPsiElement {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void replaceWithStatements(final PsiStatement orig, final PsiStatement statement) throws IncorrectOperationException {
|
||||
private static void replaceWithStatements(final PsiIfStatement orig, final PsiStatement statement) throws IncorrectOperationException {
|
||||
if (statement == null) {
|
||||
orig.delete();
|
||||
return;
|
||||
}
|
||||
PsiElement parent = orig.getParent();
|
||||
if (parent == null) return;
|
||||
if (statement instanceof PsiBlockStatement && parent instanceof PsiCodeBlock) {
|
||||
if (statement instanceof PsiBlockStatement && parent instanceof PsiCodeBlock &&
|
||||
!VariableSearchUtils.containsConflictingDeclarations((PsiCodeBlock)parent, (PsiCodeBlock)parent)) {
|
||||
// See IDEADEV-24277
|
||||
// Code block can only be inlined into another (parent) code block.
|
||||
// Code blocks, which are if or loop statement branches should not be inlined.
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Unwrap 'if' statement" "true"
|
||||
class X {
|
||||
void f() {
|
||||
<caret>{
|
||||
int i = 0;
|
||||
}
|
||||
int i = 0;
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Unwrap 'if' statement" "true"
|
||||
class X {
|
||||
void f() {
|
||||
if (tru<caret>e) {
|
||||
int i = 0;
|
||||
}
|
||||
int i = 0;
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2000-2016 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* User: anna
|
||||
* Date: 21-Mar-2008
|
||||
*/
|
||||
package com.intellij.codeInsight.daemon.quickFix;
|
||||
|
||||
import com.intellij.codeInspection.LocalInspectionTool;
|
||||
import com.intellij.codeInspection.dataFlow.DataFlowInspection;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class UnwrapIfStatementFixTest extends LightQuickFixParameterizedTestCase {
|
||||
@NotNull
|
||||
@Override
|
||||
protected LocalInspectionTool[] configureLocalInspectionTools() {
|
||||
return new LocalInspectionTool[]{new DataFlowInspection()};
|
||||
}
|
||||
|
||||
public void test() throws Exception {
|
||||
doAllTests();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBasePath() {
|
||||
return "/codeInsight/daemonCodeAnalyzer/quickFix/unwrapIfStatement";
|
||||
}
|
||||
}
|
||||
@@ -51,6 +51,7 @@ public class DataFlowInspectionTestSuite {
|
||||
suite.addTestSuite(ReplaceWithTernaryOperatorTest.class);
|
||||
suite.addTestSuite(ReplaceWithOfNullableFixTest.class);
|
||||
suite.addTestSuite(ReplaceFromOfNullableFixTest.class);
|
||||
suite.addTestSuite(UnwrapIfStatementFixTest.class);
|
||||
return suite;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user