From ce48b06ff3530d0ff92dbf8ac62bce045fc52026 Mon Sep 17 00:00:00 2001 From: Tagir Valeev Date: Wed, 22 Sep 2021 11:41:39 +0700 Subject: [PATCH] [java-completion] CatchTypeProvider: add explanatory comment, use 1 as baseline priority GitOrigin-RevId: 29b216f4f3159451129e81d6598e3c9974ff1cb3 --- .../codeInsight/completion/CatchTypeProvider.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/CatchTypeProvider.java b/java/java-impl/src/com/intellij/codeInsight/completion/CatchTypeProvider.java index ee9d8d144304..7a286d4f15a2 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/CatchTypeProvider.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/CatchTypeProvider.java @@ -54,15 +54,19 @@ final class CatchTypeProvider { if (!session.alreadyProcessed(psiClass)) { LookupElement element = createCatchTypeVariant(tryBlock, (PsiClassType)type); final int maxNumberOfHopsToConsider = 25; + // Tune priorities for classes in catch: + // 100 = class that exactly matches the thrown type + // 26..50 = superclasses of the thrown type (higher priority = less inheritance hops) + // 1..25 = subclasses of the thrown type (higher priority = less inheritance hops) int priority = StreamEx.of(preferred) .mapToInt(aClass -> { int hops = Math.min(maxNumberOfHopsToConsider, getNumberOfHops(psiClass, aClass)); if (hops >= 0) { - return 25 + maxNumberOfHopsToConsider * 2 - hops; + return 1 + maxNumberOfHopsToConsider * 2 - hops; } hops = Math.min(maxNumberOfHopsToConsider, getNumberOfHops(aClass, psiClass)); if (hops >= 0) { - return 25 + maxNumberOfHopsToConsider - hops; + return 1 + maxNumberOfHopsToConsider - hops; } return 0; })