@Nullable
  private XmlFile createAnnotationsXml(
      @NotNull VirtualFile root, @NonNls @NotNull String packageName) {
    final String[] dirs = packageName.split("[\\.]");
    for (String dir : dirs) {
      if (dir.isEmpty()) break;
      VirtualFile subdir = root.findChild(dir);
      if (subdir == null) {
        try {
          subdir = root.createChildDirectory(null, dir);
        } catch (IOException e) {
          LOG.error(e);
        }
      }
      root = subdir;
    }
    final PsiDirectory directory = myPsiManager.findDirectory(root);
    if (directory == null) return null;

    final PsiFile psiFile = directory.findFile(ANNOTATIONS_XML);
    if (psiFile instanceof XmlFile) {
      return (XmlFile) psiFile;
    }

    try {
      final PsiFileFactory factory = PsiFileFactory.getInstance(myPsiManager.getProject());
      return (XmlFile)
          directory.add(
              factory.createFileFromText(ANNOTATIONS_XML, XmlFileType.INSTANCE, "<root></root>"));
    } catch (IncorrectOperationException e) {
      LOG.error(e);
    }
    return null;
  }
 protected static PsiFile createLightFile(String fileName, String text)
     throws IncorrectOperationException {
   return PsiFileFactory.getInstance(getProject())
       .createFileFromText(
           fileName,
           FileTypeManager.getInstance().getFileTypeByFileName(fileName),
           text,
           LocalTimeCounter.currentTime(),
           false);
 }
 @Nullable
 private PsiFile createFileCopyWithNewName(VirtualFile vFile, String name) {
   // TODO[ik] remove this. Event handling and generation must be in view providers mechanism since
   // we
   // need to track changes in _all_ psi views (e.g. namespace changes in XML)
   final FileTypeManager instance = FileTypeManager.getInstance();
   if (instance.isFileIgnored(name)) return null;
   final FileType fileTypeByFileName = instance.getFileTypeByFileName(name);
   final Document document = FileDocumentManager.getInstance().getDocument(vFile);
   return PsiFileFactory.getInstance(myManager.getProject())
       .createFileFromText(
           name,
           fileTypeByFileName,
           document != null ? document.getCharsSequence() : "",
           vFile.getModificationStamp(),
           true,
           false);
 }
 protected static PsiFile createPseudoPhysicalFile(String fileName, String text)
     throws IncorrectOperationException {
   FileType fileType = FileTypeManager.getInstance().getFileTypeByFileName(fileName);
   return PsiFileFactory.getInstance(getProject())
       .createFileFromText(fileName, fileType, text, LocalTimeCounter.currentTime(), true);
 }