mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 09:19:13 +07:00
disable introduce variable from part of literal expression which is not a string
This commit is contained in:
+7
-4
@@ -37,10 +37,7 @@ import com.intellij.openapi.editor.colors.EditorColorsManager;
|
||||
import com.intellij.openapi.editor.markup.TextAttributes;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.Pass;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.util.*;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.wm.WindowManager;
|
||||
@@ -414,6 +411,12 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase {
|
||||
final PsiExpression toBeExpression = createReplacement(fakeInitializer, project, prefix, suffix, parent, rangeMarker, refIdx);
|
||||
toBeExpression.accept(errorsVisitor);
|
||||
if (hasErrors[0]) return null;
|
||||
if (literalExpression != null) {
|
||||
PsiType type = toBeExpression.getType();
|
||||
if (type != null && !type.equals(literalExpression.getType())) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
final PsiReferenceExpression refExpr = PsiTreeUtil.getParentOfType(toBeExpression.findElementAt(refIdx[0]), PsiReferenceExpression.class);
|
||||
if (refExpr == null) return null;
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
class A {
|
||||
public void test() {
|
||||
int i = <selection>1</selection>23 + 123;
|
||||
}
|
||||
}
|
||||
@@ -224,6 +224,18 @@ public class IntroduceVariableTest extends LightCodeInsightTestCase {
|
||||
doTest(new MockIntroduceVariableHandler("str", false, false, false, "java.lang.String"));
|
||||
}
|
||||
|
||||
public void testSubLiteralFailure() throws Exception {
|
||||
try {
|
||||
doTest(new MockIntroduceVariableHandler("str", false, false, false, "int"));
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertEquals(e.getMessage(), "Error message:Cannot perform refactoring.\n" +
|
||||
"Selected block should represent an expression");
|
||||
return;
|
||||
}
|
||||
fail("Should not be able to perform refactoring");
|
||||
}
|
||||
|
||||
public void testSubLiteralFromExpression() throws Exception {
|
||||
doTest(new MockIntroduceVariableHandler("str", false, false, false, "java.lang.String"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user