Introduce pattern variable: fixed when occurrence inside another local var declaration

GitOrigin-RevId: fe52fb94fcac26bee951df0f6aaa2e8b32fba95d
This commit is contained in:
Tagir Valeev
2020-01-29 06:33:37 +00:00
committed by intellij-monorepo-bot
parent bbd7f0443f
commit c76e1b4108
4 changed files with 18 additions and 1 deletions
@@ -0,0 +1,8 @@
class A {
void test(Object obj) {
if (obj instanceof String temp) {
String s = temp.trim();
System.out.println("Found");
}
}
}
@@ -0,0 +1,8 @@
class A {
void test(Object obj) {
if (obj instanceof String) {
String s = (<selection>(String)obj</selection>).trim();
System.out.println("Found");
}
}
}
@@ -135,6 +135,7 @@ public class IntroduceVariableTest extends LightJavaCodeInsightTestCase {
doTest("temp", true, false, false, "boolean");
}
public void testPatternVariableDeclarationJava14Preview() { doTest("temp", true, false, false, JAVA_LANG_STRING);}
public void testPatternVariableDeclarationUsedInLocalJava14Preview() { doTest("temp", true, false, false, JAVA_LANG_STRING);}
public void testPatternVariableDeclarationAfterIfJava14Preview() { doTest("temp", true, false, false, JAVA_LANG_STRING);}
public void testNonPatternDeclarationJava14Preview() { doTest("temp", true, false, false, JAVA_LANG_STRING);}
@@ -179,7 +179,7 @@ public class InstanceOfUtils {
}
}
if ((context instanceof PsiExpression && !(context instanceof PsiLambdaExpression)) ||
context instanceof PsiExpressionList) {
context instanceof PsiExpressionList || context instanceof PsiLocalVariable) {
context = context.getParent();
continue;
}