public static void updateFileExtension(@NotNull Project project,
                                         @Nullable VirtualFile file,
                                         @NotNull LanguageItem item) throws IOException {
    ApplicationManager.getApplication().assertWriteAccessAllowed();
    if (CommandProcessor.getInstance().getCurrentCommand() == null) {
      throw new AssertionError("command required");
    }

    if (file == null) return;
    FileTypeManager fileTypeManager = FileTypeManager.getInstance();
    FileType prevType = getFileTypeFromName(file.getName(), fileTypeManager);
    Language currLanguage = LanguageUtil.getLanguageForPsi(project, file, item.fileType);
    FileType currType = currLanguage == null ? item.fileType : ObjectUtils.notNull(currLanguage.getAssociatedFileType(), item.fileType);
    if (prevType == currType) return;

    String nameWithoutExtension = getNameWithoutExtension(file, fileTypeManager);

    VirtualFile parent = file.getParent();
    String newName = parent != null ? VfsUtil.getNextAvailableName(parent, nameWithoutExtension, item.fileExtension) :
                     PathUtil.makeFileName(nameWithoutExtension, item.fileExtension);
    file.rename(ScratchImplUtil.class, newName);
  }
public static void updateFileExtension(@NotNull Project project,
                                         @Nullable VirtualFile file,
                                         @NotNull LanguageItem item)