use of com.intellij.util.Consumer in project intellij-community by JetBrains.
the class ExternalSystemFacadeManager method onProjectRename.
private static <V> void onProjectRename(@NotNull Map<IntegrationKey, V> data, @NotNull String oldName, @NotNull String newName) {
Set<IntegrationKey> keys = ContainerUtilRt.newHashSet(data.keySet());
for (IntegrationKey key : keys) {
if (!key.getIdeProjectName().equals(oldName)) {
continue;
}
IntegrationKey newKey = new IntegrationKey(newName, key.getIdeProjectLocationHash(), key.getExternalSystemId(), key.getExternalProjectConfigPath());
V value = data.get(key);
data.put(newKey, value);
data.remove(key);
if (value instanceof Consumer) {
//noinspection unchecked
((Consumer) value).consume(newKey);
}
}
}
use of com.intellij.util.Consumer in project intellij-community by JetBrains.
the class GroovyConsole method getOrCreateConsole.
public static void getOrCreateConsole(@NotNull final Project project, @NotNull final VirtualFile contentFile, @NotNull final Consumer<GroovyConsole> callback) {
final GroovyConsole existingConsole = contentFile.getUserData(GROOVY_CONSOLE);
if (existingConsole != null)
return;
final Consumer<Module> initializer = module -> {
final GroovyConsole console = createConsole(project, contentFile, module);
if (console != null) {
callback.consume(console);
}
};
final Module module = GroovyConsoleStateService.getInstance(project).getSelectedModule(contentFile);
if (module == null || module.isDisposed()) {
// if not, then select module, then run initializer
GroovyConsoleUtil.selectModuleAndRun(project, initializer);
} else {
// if module for console is already selected, then use it for creation
initializer.consume(module);
}
}
use of com.intellij.util.Consumer in project intellij-community by JetBrains.
the class GitCherryPicker method createChangeListAfterUpdate.
@Nullable
private LocalChangeList createChangeListAfterUpdate(@NotNull final VcsFullCommitDetails commit, @NotNull final Collection<FilePath> paths, @NotNull final String commitMessage) {
final CountDownLatch waiter = new CountDownLatch(1);
final AtomicReference<LocalChangeList> changeList = new AtomicReference<>();
ApplicationManager.getApplication().invokeAndWait(new Runnable() {
@Override
public void run() {
myChangeListManager.invokeAfterUpdate(new Runnable() {
public void run() {
changeList.set(createChangeListIfThereAreChanges(commit, commitMessage));
waiter.countDown();
}
}, InvokeAfterUpdateMode.SILENT_CALLBACK_POOLED, "Cherry-pick", new Consumer<VcsDirtyScopeManager>() {
public void consume(VcsDirtyScopeManager vcsDirtyScopeManager) {
vcsDirtyScopeManager.filePathsDirty(paths, null);
}
}, ModalityState.NON_MODAL);
}
}, ModalityState.NON_MODAL);
try {
boolean success = waiter.await(100, TimeUnit.SECONDS);
if (!success) {
LOG.error("Couldn't await for changelist manager refresh");
}
} catch (InterruptedException e) {
LOG.error(e);
return null;
}
return changeList.get();
}
use of com.intellij.util.Consumer in project intellij-community by JetBrains.
the class MvcModuleStructureUtil method getUpdateProjectStructureActions.
private static Pair<Collection<Consumer<ModifiableRootModel>>, Collection<Consumer<ModifiableFacetModel>>> getUpdateProjectStructureActions(Collection<VirtualFile> appRoots, MvcProjectStructure structure) {
for (final VirtualFile appRoot : ModuleRootManager.getInstance(structure.myModule).getContentRoots()) {
appRoot.refresh(false, false);
}
Collection<Consumer<ModifiableRootModel>> actions = ContainerUtil.newArrayList();
removeInvalidSourceRoots(actions, structure);
cleanupDefaultLibrary(structure.myModule, actions, appRoots, structure.getUserLibraryName());
moveupLibrariesFromMavenPlugin(structure.myModule, actions);
List<VirtualFile> rootsToFacetSetup = new ArrayList<>(appRoots.size());
for (VirtualFile appRoot : appRoots) {
if (checkValidity(appRoot)) {
ContainerUtil.addIfNotNull(actions, addSourceRootsAndLibDirectory(appRoot, structure));
rootsToFacetSetup.add(appRoot);
}
}
Collection<Consumer<ModifiableFacetModel>> facetActions = ContainerUtil.newArrayList();
structure.setupFacets(facetActions, rootsToFacetSetup);
return Pair.create(actions, facetActions);
}
use of com.intellij.util.Consumer in project intellij-community by JetBrains.
the class MvcModuleStructureUtil method addSourceRootsAndLibDirectory.
@Nullable
private static Consumer<ModifiableRootModel> addSourceRootsAndLibDirectory(@NotNull final VirtualFile root, final MvcProjectStructure structure) {
ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(structure.myModule);
Map<VirtualFile, JpsModuleSourceRootType<?>> sourceRoots = new HashMap<>();
for (ContentEntry entry : moduleRootManager.getContentEntries()) {
for (SourceFolder folder : entry.getSourceFolders()) {
sourceRoots.put(folder.getFile(), folder.getRootType());
}
}
root.refresh(false, true);
final List<Consumer<ContentEntry>> actions = ContainerUtil.newArrayList();
for (Map.Entry<JpsModuleSourceRootType<?>, Collection<String>> entry : structure.getSourceFolders().entrySet()) {
JpsModuleSourceRootType<?> rootType = entry.getKey();
for (String src : entry.getValue()) {
addSourceFolder(root, src, rootType, actions, sourceRoots);
}
}
for (final String src : structure.getInvalidSourceFolders()) {
removeSrcFolderFromRoots(root.findFileByRelativePath(src), actions, sourceRoots);
}
for (final VirtualFile excluded : structure.getExcludedFolders(root)) {
if (moduleRootManager.getFileIndex().isInContent(excluded)) {
actions.add(contentEntry -> contentEntry.addExcludeFolder(excluded));
}
}
final Consumer<ModifiableRootModel> modifyLib = addJarDirectory(root, structure.myModule, structure.getUserLibraryName());
if (actions.isEmpty() && modifyLib == null && findContentEntry(moduleRootManager, root) != null) {
return null;
}
return model -> {
ContentEntry contentEntry = findContentEntry(model, root);
if (contentEntry == null) {
contentEntry = model.addContentEntry(root);
}
for (final Consumer<ContentEntry> action : actions) {
action.consume(contentEntry);
}
if (modifyLib != null) {
modifyLib.consume(model);
}
};
}
Aggregations