private void appendChosenAnnotationsRoot(
     @NotNull final OrderEntry entry, @NotNull final VirtualFile vFile) {
   if (entry instanceof LibraryOrderEntry) {
     Library library = ((LibraryOrderEntry) entry).getLibrary();
     LOG.assertTrue(library != null);
     final ModifiableRootModel rootModel =
         ModuleRootManager.getInstance(entry.getOwnerModule()).getModifiableModel();
     final Library.ModifiableModel model = library.getModifiableModel();
     model.addRoot(vFile, AnnotationOrderRootType.getInstance());
     model.commit();
     rootModel.commit();
   } else if (entry instanceof ModuleSourceOrderEntry) {
     final ModifiableRootModel model =
         ModuleRootManager.getInstance(entry.getOwnerModule()).getModifiableModel();
     final JavaModuleExternalPaths extension =
         model.getModuleExtension(JavaModuleExternalPaths.class);
     extension.setExternalAnnotationUrls(
         ArrayUtil.mergeArrays(extension.getExternalAnnotationsUrls(), vFile.getUrl()));
     model.commit();
   } else if (entry instanceof JdkOrderEntry) {
     final SdkModificator sdkModificator = ((JdkOrderEntry) entry).getJdk().getSdkModificator();
     sdkModificator.addRoot(vFile, AnnotationOrderRootType.getInstance());
     sdkModificator.commitChanges();
   }
   myExternalAnnotations.clear();
 }
  private static void fillLibrary(
      @NotNull Library library,
      @NotNull Collection<VirtualFile> libraryRoots,
      Set<VirtualFile> exclusions) {
    ApplicationManager.getApplication().assertWriteAccessAllowed();

    Library.ModifiableModel libraryModel = library.getModifiableModel();
    for (String root : libraryModel.getUrls(OrderRootType.CLASSES)) {
      libraryModel.removeRoot(root, OrderRootType.CLASSES);
    }
    for (String root : libraryModel.getUrls(OrderRootType.SOURCES)) {
      libraryModel.removeRoot(root, OrderRootType.SOURCES);
    }
    for (VirtualFile libraryRoot : libraryRoots) {
      libraryModel.addRoot(
          libraryRoot,
          OrderRootType
              .CLASSES); // in order to consider GOPATH as library and show it in Ext. Libraries
      libraryModel.addRoot(
          libraryRoot, OrderRootType.SOURCES); // in order to find usages inside GOPATH
    }
    for (VirtualFile root : exclusions) {
      ((LibraryEx.ModifiableModelEx) libraryModel).addExcludedRoot(root.getUrl());
    }
    libraryModel.commit();
  }
Пример #3
0
 public static void removeExcludedRoot(Module module, VirtualFile root) {
   ModuleRootModificationUtil.updateModel(
       module,
       model -> {
         ContentEntry entry = findContentEntryWithAssertion(model, root);
         entry.removeExcludeFolder(root.getUrl());
       });
 }