コード例 #1
0
  private static void addDependencyOnDartPackagesLibrary(
      @NotNull final Module module, @NotNull final Library library) {
    final ModifiableRootModel modifiableModel =
        ModuleRootManager.getInstance(module).getModifiableModel();
    try {
      for (final OrderEntry orderEntry : modifiableModel.getOrderEntries()) {
        if (orderEntry instanceof LibraryOrderEntry
            && LibraryTablesRegistrar.PROJECT_LEVEL.equals(
                ((LibraryOrderEntry) orderEntry).getLibraryLevel())
            && DartPackagesLibraryType.DART_PACKAGES_LIBRARY_NAME.equals(
                ((LibraryOrderEntry) orderEntry).getLibraryName())) {
          return; // dependency already exists
        }
      }

      modifiableModel.addLibraryEntry(library);

      ApplicationManager.getApplication()
          .runWriteAction(
              new Runnable() {
                @Override
                public void run() {
                  modifiableModel.commit();
                }
              });
    } finally {
      if (!modifiableModel.isDisposed()) {
        modifiableModel.dispose();
      }
    }
  }
コード例 #2
0
  public static void multiCommit(
      @NotNull Collection<ModifiableRootModel> rootModels,
      @NotNull ModifiableModuleModel moduleModel) {
    ApplicationManager.getApplication().assertWriteAccessAllowed();

    final List<RootModelImpl> modelsToCommit = getSortedChangedModels(rootModels, moduleModel);

    final List<ModifiableRootModel> modelsToDispose = ContainerUtil.newArrayList(rootModels);
    modelsToDispose.removeAll(modelsToCommit);

    ModuleManagerImpl.commitModelWithRunnable(
        moduleModel,
        () -> {
          for (RootModelImpl model : modelsToCommit) {
            ModuleRootManagerImpl.doCommit(model);
          }
          for (ModifiableRootModel model : modelsToDispose) {
            model.dispose();
          }
        });
  }