@NotNull protected ProjectRootManager registerProjectRootManager() { ProjectRootManager projectRootManager = new ProjectRootManagerImpl(myProject); myProject.registerService(ProjectRootManager.class, projectRootManager); return projectRootManager; }
@Override public boolean visitFile(@NotNull VirtualFile file) { return ReadAction.compute(() -> { boolean proceedToChildren; if (fileTypeManager.isFileIgnored(file)) { proceedToChildren = false; } else { proceedToChildren = true; if (file.isDirectory()) { propertiesUpdater.findAndUpdateValue(file, LevelPropertyPusher.this, level); } } return proceedToChildren; }); } });
@NotNull private DirectoryIndex registerDirectoryIndex(MessageBus messageBus) throws ClassNotFoundException, InvocationTargetException, InstantiationException, NoSuchMethodException, IllegalAccessException { /* MUST be registered before DirectoryIndex because DirectoryIndexImpl.markContentRootsForRefresh calls ModuleManager.getInstance(this.myProject).getModules(); */ registerModuleManager(messageBus); DirectoryIndex directoryIndex = new DirectoryIndexImpl(myProject); myProject.registerService(DirectoryIndex.class, directoryIndex); return directoryIndex; }
private void attachLibraries(@NotNull Collection<VirtualFile> libraryRoots, Set<VirtualFile> exclusions) { ApplicationManager.getApplication().assertIsDispatchThread(); if (!libraryRoots.isEmpty()) { ApplicationManager.getApplication().runWriteAction(() -> { ModuleRootManager model = ModuleRootManager.getInstance(myModule); LibraryOrderEntry goLibraryEntry = OrderEntryUtil.findLibraryOrderEntry(model, getLibraryName()); if (goLibraryEntry != null && goLibraryEntry.isValid()) { Library library = goLibraryEntry.getLibrary(); if (library != null && !((LibraryEx)library).isDisposed()) { fillLibrary(library, libraryRoots, exclusions); } } else { LibraryTable libraryTable = LibraryTablesRegistrar.getInstance().getLibraryTable(myModule.getProject()); Library library = libraryTable.createLibrary(getLibraryName()); fillLibrary(library, libraryRoots, exclusions); ModuleRootModificationUtil.addDependency(myModule, library); } }); showNotification(myModule.getProject()); } else { removeLibraryIfNeeded(); } }
private void assertLibrary(@NotNull Collection<String> libUrls, String... exclusionUrls) { UIUtil.dispatchAllInvocationEvents(); GoModuleLibrariesInitializer initializer = myModule.getComponent(GoModuleLibrariesInitializer.class); ModuleRootManager model = ModuleRootManager.getInstance(myModule); LibraryOrderEntry libraryOrderEntry = OrderEntryUtil.findLibraryOrderEntry(model, initializer.getLibraryName()); if (libUrls.isEmpty()) { assertNull(libraryOrderEntry); return; } LibraryEx library = (LibraryEx)libraryOrderEntry.getLibrary(); assertNotNull(library); assertSameElements(Arrays.asList(library.getUrls(OrderRootType.CLASSES)), libUrls); assertSameElements(library.getExcludedRootUrls(), exclusionUrls); }
private void removeLibraryIfNeeded() { ApplicationManager.getApplication().assertIsDispatchThread(); ModifiableModelsProvider modelsProvider = ModifiableModelsProvider.SERVICE.getInstance(); ModifiableRootModel model = modelsProvider.getModuleModifiableModel(myModule); LibraryOrderEntry goLibraryEntry = OrderEntryUtil.findLibraryOrderEntry(model, getLibraryName()); if (goLibraryEntry != null) { ApplicationManager.getApplication().runWriteAction(() -> { Library library = goLibraryEntry.getLibrary(); if (library != null) { LibraryTable table = library.getTable(); if (table != null) { table.removeLibrary(library); model.removeOrderEntry(goLibraryEntry); modelsProvider.commitModuleModifiableModel(model); } } else { modelsProvider.disposeModuleModifiableModel(model); } }); } else { ApplicationManager.getApplication().runWriteAction(() -> modelsProvider.disposeModuleModifiableModel(model)); } }
@Override public void performInDumbMode(@NotNull ProgressIndicator indicator) { if (!project.isDisposed()) { final PerformanceWatcher.Snapshot snapshot = PerformanceWatcher.takeSnapshot(); final List<Runnable> tasks = ReadAction.compute(() -> rootUpdateTaskList(project, sdkSet)); PushedFilePropertiesUpdaterImpl.invokeConcurrentlyIfPossible(tasks); if (!ApplicationManager.getApplication().isUnitTestMode()) { snapshot.logResponsivenessSinceCreation( "Pushing Elixir language level to " + tasks.size() + " roots in " + sdkSet.size() + " SDKs"); } } } };
@Override public void run() { if (project.isDisposed() || !ReadAction.compute(root::isValid)) return; final FileTypeManager fileTypeManager = FileTypeManager.getInstance(); final PushedFilePropertiesUpdater propertiesUpdater = PushedFilePropertiesUpdater.getInstance(project); VfsUtilCore.visitChildrenRecursively(root, new VirtualFileVisitor() { @Override public boolean visitFile(@NotNull VirtualFile file) { return ReadAction.compute(() -> { boolean proceedToChildren; if (fileTypeManager.isFileIgnored(file)) { proceedToChildren = false; } else { proceedToChildren = true; if (file.isDirectory()) { propertiesUpdater.findAndUpdateValue(file, LevelPropertyPusher.this, level); } } return proceedToChildren; }); } }); }
private void registerProjectFileIndex(MessageBus messageBus) throws ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException { DirectoryIndex directoryIndex = registerDirectoryIndex(messageBus); FileTypeRegistry fileTypeRegistry = new MockFileTypeManager(); myProject.registerService( ProjectFileIndex.class, new ProjectFileIndexImpl(myProject, directoryIndex, fileTypeRegistry) ); }
myProject.addComponent(PushedFilePropertiesUpdater.class, new PushedFilePropertiesUpdaterImpl(myProject));
private void attachLibraries(@NotNull Collection<VirtualFile> libraryRoots, Set<VirtualFile> exclusions) { ApplicationManager.getApplication().assertIsDispatchThread(); if (!libraryRoots.isEmpty()) { ApplicationManager.getApplication().runWriteAction(() -> { ModuleRootManager model = ModuleRootManager.getInstance(myModule); LibraryOrderEntry ballerinaLibraryEntry = OrderEntryUtil.findLibraryOrderEntry(model, getLibraryName()); if (ballerinaLibraryEntry != null && ballerinaLibraryEntry.isValid()) { Library library = ballerinaLibraryEntry.getLibrary(); if (library != null && !((LibraryEx) library).isDisposed()) { fillLibrary(library, libraryRoots, exclusions); } } else { LibraryTable libraryTable = LibraryTablesRegistrar.getInstance().getLibraryTable(myModule .getProject()); Library library = libraryTable.createLibrary(getLibraryName()); fillLibrary(library, libraryRoots, exclusions); ModuleRootModificationUtil.addDependency(myModule, library); } }); showNotification(myModule.getProject()); } else { removeLibraryIfNeeded(); } }
private void removeLibraryIfNeeded() { ApplicationManager.getApplication().assertIsDispatchThread(); ModifiableModelsProvider modelsProvider = ModifiableModelsProvider.SERVICE.getInstance(); ModifiableRootModel model = modelsProvider.getModuleModifiableModel(myModule); LibraryOrderEntry ballerinaLibraryEntry = OrderEntryUtil.findLibraryOrderEntry(model, getLibraryName()); if (ballerinaLibraryEntry != null) { ApplicationManager.getApplication().runWriteAction(() -> { Library library = ballerinaLibraryEntry.getLibrary(); if (library != null) { LibraryTable table = library.getTable(); if (table != null) { table.removeLibrary(library); model.removeOrderEntry(ballerinaLibraryEntry); modelsProvider.commitModuleModifiableModel(model); } } else { modelsProvider.disposeModuleModifiableModel(model); } }); } else { ApplicationManager.getApplication().runWriteAction(() -> modelsProvider.disposeModuleModifiableModel(model)); } }