mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java-intentions] CreateSwitchIntention: enable on Character, Byte, Short, and Integer
GitOrigin-RevId: 185df516fd2aba29b73b9183a58073eec4d3d118
This commit is contained in:
committed by
intellij-monorepo-bot
parent
e89a3d743c
commit
fb05bfd331
+9
-5
@@ -60,18 +60,22 @@ public class CreateSwitchIntention extends BaseElementAtCaretIntentionAction imp
|
||||
}
|
||||
|
||||
private static boolean isValidTypeForSwitch(@Nullable PsiType type, PsiElement context) {
|
||||
if (type == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (type instanceof PsiClassType) {
|
||||
PsiClass resolvedClass = ((PsiClassType)type).resolve();
|
||||
if (resolvedClass == null) {
|
||||
return false;
|
||||
}
|
||||
return (PsiUtil.isLanguageLevel5OrHigher(context) && resolvedClass.isEnum())
|
||||
return (PsiUtil.isLanguageLevel5OrHigher(context) &&
|
||||
(resolvedClass.isEnum() || isSuitablePrimitiveType(PsiPrimitiveType.getUnboxedType(type))))
|
||||
|| (PsiUtil.isLanguageLevel7OrHigher(context) && CommonClassNames.JAVA_LANG_STRING.equals(resolvedClass.getQualifiedName()));
|
||||
}
|
||||
return isSuitablePrimitiveType(type);
|
||||
}
|
||||
|
||||
private static boolean isSuitablePrimitiveType(@Nullable PsiType type) {
|
||||
if (type == null) {
|
||||
return false;
|
||||
}
|
||||
return type.equals(PsiType.INT) || type.equals(PsiType.BYTE) || type.equals(PsiType.SHORT) || type.equals(PsiType.CHAR);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
class X {
|
||||
|
||||
void m() {
|
||||
|
||||
Byte foo = 10;
|
||||
fo<caret>o
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
class X {
|
||||
|
||||
void m() {
|
||||
|
||||
Byte foo = 10;
|
||||
switch (foo) {<caret>
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -47,6 +47,10 @@ public class CreateSwitchTest extends JavaCodeInsightFixtureTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testBoxedType() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testNotAvailable() {
|
||||
doTestNotAvailable();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user