[java-incomplete-model] Support declared but unresolved exceptions

GitOrigin-RevId: 2e493f1820ce2e676708e191c0ff0b72b4ecaa59
This commit is contained in:
Tagir Valeev
2024-06-24 13:07:17 +02:00
committed by intellij-monorepo-bot
parent f570494f4a
commit 15bb3eb9f4
3 changed files with 18 additions and 7 deletions

View File

@@ -927,15 +927,12 @@ public final class HighlightUtil {
static HighlightInfo.Builder checkUnhandledExceptions(@NotNull PsiElement element) {
List<PsiClassType> unhandled = ExceptionUtil.getOwnUnhandledExceptions(element);
if (unhandled.isEmpty()) return null;
unhandled = ContainerUtil.filter(unhandled, type -> type.resolve() != null);
if (unhandled.isEmpty()) return null;
HighlightInfoType highlightType = getUnhandledExceptionHighlightType(element);
if (highlightType == null) return null;
if (IncompleteModelUtil.isIncompleteModel(element)) {
unhandled = ContainerUtil.filter(unhandled, type -> !IncompleteModelUtil.isUnresolvedClassType(type));
if (unhandled.isEmpty()) return null;
}
TextRange textRange = computeRange(element);
String description = getUnhandledExceptionsDescriptor(unhandled);
HighlightInfo.Builder info = HighlightInfo.newHighlightInfo(highlightType).range(textRange).descriptionAndTooltip(description);

View File

@@ -628,9 +628,8 @@ public final class ExceptionUtil {
if (!(type instanceof PsiClassType)) continue;
PsiClassType classType = (PsiClassType)type;
PsiClass exceptionClass = ((PsiClassType)type).resolve();
if (exceptionClass == null) continue;
if (exceptionClass != null && isUncheckedException(classType)) continue;
if (isUncheckedException(classType)) continue;
if (getHandlePlace(element, classType, topElement) != HandlePlace.UNHANDLED) continue;
result.add((PsiClassType)type);

View File

@@ -142,6 +142,21 @@ public class Simple {
}
}
void testThrow2() {
try {
declaredUnknownException();
}
catch (<info descr="Not resolved until the project is fully loaded">Cls</info> x) {}
}
void testThrow3() {
// We don't know whether Cls is checked or not
declaredUnknownException();
}
void declaredUnknownException() throws <info descr="Not resolved until the project is fully loaded">Cls</info> {}
void testConcat(<info descr="Not resolved until the project is fully loaded">Cls</info> cls) {
System.out.println("hello " + cls.<info descr="Not resolved until the project is fully loaded">getSomething</info>() + "!!!");
}