@NotNull
  @Override
  public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly) {
    return new JavaElementVisitor() {
      @Override
      public void visitMethodCallExpression(@NotNull PsiMethodCallExpression call) {
        PsiExpressionList argList = call.getArgumentList();
        int argCount = argList.getExpressionCount();
        if (argCount < 2) return;
        JavaResolveResult result = call.getMethodExpression().advancedResolve(false);
        PsiMethod method = (PsiMethod)result.getElement();
        if (method == null || !method.isVarArgs()) return;
        PsiParameterList paramList = method.getParameterList();
        if (paramList.getParametersCount() != argCount) return;
        PsiParameter varArgParam = paramList.getParameters()[argCount - 1];
        PsiEllipsisType type = tryCast(varArgParam.getType(), PsiEllipsisType.class);
        if (type == null) return;
        PsiTypeParameter componentType = tryCast(PsiUtil.resolveClassInClassTypeOnly(type.getComponentType()), PsiTypeParameter.class);
        if (componentType == null || componentType.getOwner() != method) return;
        PsiSubstitutor substitutor = result.getSubstitutor();
        if (!TypeUtils.isJavaLangObject(substitutor.substitute(componentType))) return;
        PsiExpression[] args = argList.getExpressions();
        PsiExpression varArgExpression = args[argCount - 1];
        PsiType elementType = PsiUtil.substituteTypeParameter(varArgExpression.getType(), CommonClassNames.JAVA_LANG_ITERABLE, 0, false);
        if (elementType == null || TypeUtils.isJavaLangObject(elementType)) return;
        PsiClass elementClass = PsiUtil.resolveClassInClassTypeOnly(GenericsUtil.getVariableTypeByExpressionType(elementType));
        if (elementClass == null) return;
        PsiMethodCallExpression callCopy = (PsiMethodCallExpression)call.copy();
        if (callCopy == null) return;
        PsiExpression argCopy = ArrayUtil.getLastElement(callCopy.getArgumentList().getExpressions());
        if (argCopy == null) return;
        PsiElementFactory factory = JavaPsiFacade.getElementFactory(holder.getProject());
        String className = elementClass.getQualifiedName();
        if (className == null) {
          className = elementClass.getName();
          if (className == null) return;
        }
        String replacement = "new " + className + "[0]";
        argCopy.replace(factory.createExpressionFromText(replacement, argCopy));
        JavaResolveResult copyResult = callCopy.getMethodExpression().advancedResolve(false);
        if (copyResult.getElement() == method) {
          PsiType substitutionWithArray = copyResult.getSubstitutor().substitute(componentType);
          if (substitutionWithArray == null || TypeUtils.isJavaLangObject(substitutionWithArray)) return;
        } else {
          PsiMethod newMethod = (PsiMethod)copyResult.getElement();
          if (newMethod == null || !newMethod.isVarArgs() || newMethod.getParameterList().getParametersCount() != argCount) return;
        }
        LocalQuickFix fix = null;
        if (InheritanceUtil.isInheritor(varArgExpression.getType(), CommonClassNames.JAVA_UTIL_COLLECTION)) {
          fix = new AddToArrayFix(className);
        }
        holder.registerProblem(varArgExpression, JavaBundle.message("inspection.collection.used.as.vararg.message"), fix);
      }
    };
  }
@NotNull
  @Override
  public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly)