private static @Nullable LookupElementWeigher dispreferPreviousChainCalls(PsiElement position) {
    Object2IntMap<PsiMethod> previousChainCalls = new Object2IntOpenHashMap<>();
    if (position.getParent() instanceof PsiReferenceExpression ref) {
      PsiMethodCallExpression qualifier = getCallQualifier(ref);
      PsiClass qualifierClass = qualifier == null ? null : PsiUtil.resolveClassInClassTypeOnly(qualifier.getType());
      if (BuilderCompletionKt.looksLikeBuilder(qualifierClass)) {
        while (qualifier != null) {
          PsiMethod method = qualifier.resolveMethod();
          if (method != null) {
            String name = method.getName();
            boolean seemsLikeExpectsMultipleCalls =
              name.startsWith("put") || name.startsWith("add") || name.startsWith("append") || name.startsWith("get");
            if (!seemsLikeExpectsMultipleCalls && qualifierClass == method.getContainingClass()) {
              previousChainCalls.put(method, previousChainCalls.getInt(method) + 1);
            }
          }
          qualifier = getCallQualifier(qualifier.getMethodExpression());
        }
      }
    }
    return previousChainCalls.isEmpty() ? null : new LookupElementWeigher("dispreferPreviousChainCalls") {
      @Override
      public Boolean weigh(@NotNull LookupElement element, @NotNull WeighingContext context) {
        PsiElement psi = element.getPsiElement();
        return psi instanceof PsiMethod && previousChainCalls.getInt(psi) == 1;
      }
    };
  }
private static @Nullable LookupElementWeigher dispreferPreviousChainCalls(PsiElement position)