mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-209743 Extracted variable from case label expression should be 'final'
This commit is contained in:
+2
-1
@@ -1050,7 +1050,8 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase {
|
||||
final boolean replaceAll = replaceChoice.isMultiple();
|
||||
final SuggestedNameInfo suggestedName = getSuggestedName(typeSelectorManager.getDefaultType(), expr, anchor);
|
||||
final String variableName = suggestedName.names.length > 0 ? suggestedName.names[0] : "";
|
||||
final boolean declareFinal = replaceAll && declareFinalIfAll || !anyAssignmentLHS && createFinals(anchor.getContainingFile());
|
||||
final boolean declareFinal = replaceAll && declareFinalIfAll || !anyAssignmentLHS && createFinals(anchor.getContainingFile()) ||
|
||||
anchor instanceof PsiSwitchLabelStatementBase;
|
||||
final boolean declareVarType = canBeExtractedWithoutExplicitType(expr) && createVarType();
|
||||
final boolean replaceWrite = anyAssignmentLHS && replaceChoice.isAll();
|
||||
return new IntroduceVariableSettings() {
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
class A {
|
||||
private void A() {
|
||||
final int i = 2;
|
||||
switch (1) {
|
||||
case 1:
|
||||
System.out.println(1);
|
||||
break;
|
||||
case i:
|
||||
System.out.println(3);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
class A {
|
||||
private void A() {
|
||||
switch (1) {
|
||||
case 1:
|
||||
System.out.println(1);
|
||||
break;
|
||||
case <selection>2</selection>:
|
||||
System.out.println(3);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import com.intellij.psi.PsiType;
|
||||
import com.intellij.refactoring.JavaRefactoringSettings;
|
||||
import com.intellij.refactoring.introduceVariable.InputValidator;
|
||||
import com.intellij.refactoring.introduceVariable.IntroduceVariableBase;
|
||||
import com.intellij.refactoring.introduceVariable.IntroduceVariableHandler;
|
||||
import com.intellij.refactoring.introduceVariable.IntroduceVariableSettings;
|
||||
import com.intellij.refactoring.ui.TypeSelectorManagerImpl;
|
||||
import com.intellij.testFramework.LightCodeInsightTestCase;
|
||||
@@ -221,6 +222,10 @@ public class IntroduceVariableTest extends LightCodeInsightTestCase {
|
||||
doTest(new MockIntroduceVariableHandler("temp", true, false, false, "int"));
|
||||
}
|
||||
|
||||
public void testCaseLabelSingle() {
|
||||
doTest(new IntroduceVariableHandler());
|
||||
}
|
||||
|
||||
public void testCaseLabelEnum() {
|
||||
try {
|
||||
doTest(new MockIntroduceVariableHandler("temp", true, false, false, ""));
|
||||
|
||||
Reference in New Issue
Block a user