mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 21:11:28 +07:00
[java-highlighting] IJ-CR-125397 IDEA-344235 support calls with checked exceptions for instanceOf patterns
- reimplement, changing only mayCompleteNormallyVisitor GitOrigin-RevId: 67be02c535ec3d5df7a9ec9cd77395305db27e14
This commit is contained in:
committed by
intellij-monorepo-bot
parent
35ff272201
commit
8813548cbb
@@ -1067,11 +1067,19 @@ public final class ControlFlowUtil {
|
||||
if (offset > endOffset) return;
|
||||
int throwToOffset = instruction.offset;
|
||||
boolean isNormal;
|
||||
if (throwToOffset == nextOffset) {
|
||||
//if it is not PsiThrowStatement and the next step is the last step,
|
||||
//it is possible to complete it normally.
|
||||
if (throwToOffset == nextOffset && nextOffset == endOffset &&
|
||||
offset + 1 == nextOffset && !(flow.getElement(offset) instanceof PsiThrowStatement)) {
|
||||
isNormal = true;
|
||||
}
|
||||
else if (throwToOffset == nextOffset) {
|
||||
isNormal = throwToOffset <= endOffset && !isLeaf(nextOffset) && canCompleteNormally[nextOffset];
|
||||
}
|
||||
else {
|
||||
isNormal = canCompleteNormally[nextOffset];
|
||||
//if the next step is the last step, it is certainly completed normally in `not-throw` branch
|
||||
//otherwise, take completion from the next offset
|
||||
isNormal = nextOffset == endOffset || canCompleteNormally[nextOffset];
|
||||
}
|
||||
canCompleteNormally[offset] |= isNormal;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
class X {
|
||||
|
||||
void simpleIf(Object obj) {
|
||||
@@ -130,4 +134,25 @@ class X {
|
||||
}
|
||||
System.out.println(s.length());
|
||||
}
|
||||
|
||||
|
||||
public static void testWithExceptionCall() throws Exception {
|
||||
Object object = new Object();
|
||||
if (!(object instanceof Integer integer)) {
|
||||
test();
|
||||
}
|
||||
System.out.println(<error descr="Cannot resolve symbol 'integer'">integer</error>);
|
||||
}
|
||||
|
||||
public static void testWithExceptionTryWithResource() throws Exception {
|
||||
Object object = new Object();
|
||||
if (!(object instanceof Integer integer)) {
|
||||
try (InputStream inputStream = new FileInputStream(new File("input.txt"))) {
|
||||
}
|
||||
}
|
||||
System.out.println(<error descr="Cannot resolve symbol 'integer'">integer</error>);
|
||||
}
|
||||
|
||||
private static void test() throws Exception {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// "Replace 'integer' with pattern variable" "false"
|
||||
|
||||
class X {
|
||||
public static void testWithExceptionCall() throws Exception {
|
||||
Object object = new Object();
|
||||
if (!(object instanceof Integer)) {
|
||||
test();
|
||||
}
|
||||
Integer int<caret>eger = (Integer)object;
|
||||
System.out.println(integer);
|
||||
}
|
||||
|
||||
private static void test() throws Exception {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user