[java-refactoring] IDEA-338428 Inline pattern variable doesn't work when it's located in nested condition

GitOrigin-RevId: 158e71c18441ffd56eebabe107899b95ac4ac15d
This commit is contained in:
Tagir Valeev
2023-11-17 18:11:02 +00:00
committed by intellij-monorepo-bot
parent 08632d3227
commit fc4f8118d2
4 changed files with 18 additions and 0 deletions
@@ -306,6 +306,9 @@ public final class PsiUtil extends PsiUtilCore {
PsiElement codeBlock = null;
if (variable instanceof PsiParameter) {
PsiElement declarationScope = ((PsiParameter)variable).getDeclarationScope();
if (variable instanceof PsiPatternVariable) {
return declarationScope;
}
if (declarationScope instanceof PsiCatchSection) {
codeBlock = ((PsiCatchSection)declarationScope).getCatchBlock();
}
@@ -0,0 +1,7 @@
class Test {
void test(Object obj) {
if (Math.random() > 0.5 || (obj instanceof String <caret>s && s.isEmpty())) {
System.out.println();
}
}
}
@@ -0,0 +1,7 @@
class Test {
void test(Object obj) {
if (Math.random() > 0.5 || (obj instanceof String && ((String) obj).isEmpty())) {
System.out.println();
}
}
}
@@ -22,6 +22,7 @@ public class InlinePatternVariableTest extends LightJavaCodeInsightTestCase {
public void testSimple() { doTest(); }
public void testSimpleAtRef() { doTest(); }
public void testTernary() { doTest(); }
public void testInNestedCondition() { doTest(); }
@Override
protected @NotNull LightProjectDescriptor getProjectDescriptor() {