@NotNull
  @Override
  public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
    return new JavaElementVisitor() {

      @Override
      public void visitNewExpression(@NotNull PsiNewExpression newExpression) {
        super.visitNewExpression(newExpression);

        final List<String> targetTypes = Arrays.asList(
          CommonClassNames.JAVA_IO_FILE_INPUT_STREAM, CommonClassNames.JAVA_IO_FILE_OUTPUT_STREAM,
          CommonClassNames.JAVA_IO_FILE_READER, CommonClassNames.JAVA_IO_FILE_WRITER,
          CommonClassNames.JAVA_IO_PRINT_STREAM, CommonClassNames.JAVA_IO_PRINT_WRITER,
          CommonClassNames.JAVA_UTIL_FORMATTER
        );

        final PsiType type = newExpression.getType();
        if (type == null || !targetTypes.contains(type.getCanonicalText())) {
          return;
        }

        final PsiMethod constructor = newExpression.resolveConstructor();
        if (constructor == null) return;
        final PsiParameter[] params = constructor.getParameterList().getParameters();

        if (params.length == 0 || !TypeUtils.typeEquals(CommonClassNames.JAVA_IO_FILE, params[0].getType())) return;

        final PsiExpressionList argList = newExpression.getArgumentList();
        if (argList == null) return;

        final PsiExpression[] args = argList.getExpressions();
        if (args.length == 0) return;

        PsiNewExpression arg = ObjectUtils.tryCast(PsiUtil.skipParenthesizedExprDown(args[0]), PsiNewExpression.class);
        if (arg == null) return;

        final PsiMethod fileConstructor = arg.resolveConstructor();
        if (fileConstructor == null) return;

        final PsiParameter[] fileParams = fileConstructor.getParameterList().getParameters();
        if (fileParams.length != 1) return;

        if (!TypeUtils.isJavaLangString(fileParams[0].getType())) return;

        PsiExpressionList fileArgList = arg.getArgumentList();
        if (fileArgList == null) return;

        if (!canReplacedWithConstructorTakesFilename(constructor)) return;

        holder.registerProblem(arg,
                               JavaBundle.message("inspection.redundant.file.creation.description"),
                               ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
                               new TextRange(0, fileArgList.getStartOffsetInParent()),
                               new DeleteRedundantFileCreationFix());

      }
    };
  }
@NotNull
  @Override
  public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly)