private @Nullable XmlFile getFileForAnnotations(@NotNull VirtualFile root, @NotNull PsiModifierListOwner owner, Project project) {
    final PsiFile containingFile = owner.getOriginalElement().getContainingFile();
    String packageName = owner instanceof PsiPackage
                         ? ((PsiPackage)owner).getQualifiedName()
                         : containingFile instanceof PsiJavaFile
                           ? ((PsiJavaFile)containingFile).getPackageName() : null;
    if (packageName == null) {
      return null;
    }

    List<XmlFile> annotationsFiles = findExternalAnnotationsXmlFiles(owner);

    XmlFile fileInRoot = findXmlFileInRoot(annotationsFiles, root);
    if (fileInRoot != null) {
      return fileInRoot;
    }
    return WriteCommandAction.writeCommandAction(project).compute(() -> {
      XmlFile newAnnotationsFile = createAnnotationsXml(root, packageName);
      if (newAnnotationsFile == null) {
        return null;
      }

      Object key = owner instanceof PsiPackage ? owner : containingFile.getVirtualFile();
      if (key != null) {
        registerExternalAnnotations(key, newAnnotationsFile);
      }
      return newAnnotationsFile;
    });
  }
private @Nullable XmlFile getFileForAnnotations(@NotNull VirtualFile root, @NotNull PsiModifierListOwner owner, Project project)