[java-intentions] EA-465575 - AE: JavaParserUtil.parseFragment

GitOrigin-RevId: 51d05798ab9a127508bcf531a3aa1a13cdda5aae
This commit is contained in:
Tagir Valeev
2022-08-01 10:36:10 +02:00
committed by intellij-monorepo-bot
parent b5c5a86f77
commit 46c6cb94ad
6 changed files with 32 additions and 2 deletions

View File

@@ -310,7 +310,7 @@ public class ConvertSwitchToIfIntention implements IntentionActionWithFixAllOpti
if (caseElement instanceof PsiExpression) {
PsiExpression caseExpression = PsiUtil.skipParenthesizedExprDown((PsiExpression)caseElement);
String caseValue = getCaseValueText(caseExpression, commentTracker);
if (useEquals && !ExpressionUtils.isNullLiteral(caseExpression)) {
if (useEquals && caseExpression != null && !(caseExpression.getType() instanceof PsiPrimitiveType)) {
if (PsiPrecedenceUtil.getPrecedence(caseExpression) > PsiPrecedenceUtil.METHOD_CALL_PRECEDENCE) {
caseValue = "(" + caseValue + ")";
}

View File

@@ -0,0 +1,7 @@
// "Replace 'switch' with 'if'" "true-preview"
class Test {
void test(Object obj) {
if (obj == 1) {
}
}
}

View File

@@ -1,7 +1,7 @@
// "Replace 'switch' with 'if'" "true-preview"
class Test {
void test(Object obj) {
if ((obj instanceof String s).equals(obj)) {
if (obj == obj instanceof String s) {
}
}
}

View File

@@ -0,0 +1,7 @@
// "Replace 'switch' with 'if'" "true-preview"
class Test {
void test(Object obj) {
if (obj == obj instanceof String) {
}
}
}

View File

@@ -0,0 +1,8 @@
// "Replace 'switch' with 'if'" "true-preview"
class Test {
void test(Object obj) {
<caret>switch (obj) {
case 1 -> {}
}
}
}

View File

@@ -0,0 +1,8 @@
// "Replace 'switch' with 'if'" "true-preview"
class Test {
void test(Object obj) {
<caret>switch (obj) {
case obj instanceof String -> {}
}
}
}