@Nullable
  private static PsiType guessElementTypeFromReference(MethodPatternMap methodPatternMap,
                                                       PsiElement ref,
                                                       TextRange rangeToIgnore) {
    PsiElement refParent = ref.getParent();
    if (refParent instanceof PsiReferenceExpression parentExpr &&
        ref.equals(parentExpr.getQualifierExpression()) &&
        parentExpr.getParent() instanceof PsiMethodCallExpression methodCall) {
      String methodName = parentExpr.getReferenceName();
      PsiExpression[] args = methodCall.getArgumentList().getExpressions();
      MethodPattern pattern = methodPatternMap.findPattern(methodName, args.length);
      if (pattern != null) {
        if (pattern.parameterIndex() < 0) { // return value
          if (methodCall.getParent() instanceof PsiTypeCastExpression cast &&
              (rangeToIgnore == null || !rangeToIgnore.contains(methodCall.getTextRange()))) {
            return cast.getType();
          }
        }
        else {
          return args[pattern.parameterIndex()].getType();
        }
      }
    }
    return null;
  }
@Nullable
  private static PsiType guessElementTypeFromReference(MethodPatternMap methodPatternMap,
                                                       PsiElement ref,
                                                       TextRange rangeToIgnore)