private static boolean checkFileWriteAccess(FileReference reference,
                                              PsiDirectory targetRoot,
                                              String[] pathToCreate,
                                              String newFileName,
                                              boolean isDirectory) {
    PsiDirectory currentDirectory = targetRoot;
    for (String part : pathToCreate) {
      PsiDirectory subDirectory = currentDirectory.findSubdirectory(part);
      if (subDirectory == null) {
        return checkCreateSubdirectory(currentDirectory, part);
      }

      currentDirectory = subDirectory;
    }

    if (reference.getIndex() > 0) {
      FileReference[] references = reference.getFileReferenceSet().getAllReferences();

      // check that we can create first unresolved directory
      for (int i = 0; i < references.length - 1; i++) {
        String part = references[i].getFileNameToCreate();

        PsiDirectory subDirectory = currentDirectory.findSubdirectory(part);
        if (subDirectory == null) {
          return checkCreateSubdirectory(currentDirectory, part);
        }

        currentDirectory = subDirectory;
      }
    }

    if (isDirectory) {
      return checkCreateSubdirectory(currentDirectory, newFileName);
    } else {
      // if all directories exist check if we can create file in the last
      return checkCreateFile(currentDirectory, newFileName);
    }
  }
private static boolean checkFileWriteAccess(FileReference reference,
                                              PsiDirectory targetRoot,
                                              String[] pathToCreate,
                                              String newFileName,
                                              boolean isDirectory)