Java Code Examples for com.intellij.util.containers.ContainerUtil#newLinkedHashSet()

The following examples show how to use com.intellij.util.containers.ContainerUtil#newLinkedHashSet() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FilePathReferenceProvider.java    From protobuf-jetbrains-plugin with Apache License 2.0 6 votes vote down vote up
@NotNull
public Collection<PsiFileSystemItem> getRoots(@Nullable final Module module, ProtoPsiFileRoot psiFileRoot) {
    if (module == null) {
        return Collections.emptyList();
    }

    Set<PsiFileSystemItem> result = ContainerUtil.newLinkedHashSet();
    PsiManager psiManager = PsiManager.getInstance(module.getProject());

    for (SourceRootsProvider sourceRootsProvider : sourceRootsProviders) {
        VirtualFile[] sourceRoots = sourceRootsProvider.getSourceRoots(module, psiFileRoot);
        for (VirtualFile root : sourceRoots) {
            if (root != null) {
                final PsiDirectory directory = psiManager.findDirectory(root);
                if (directory != null) {
                    result.add(directory);
                }
            }
        }
    }
    return result;
}
 
Example 2
Source File: NavigationUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
public static List<GotoRelatedItem> collectRelatedItems(@Nonnull PsiElement contextElement, @Nullable DataContext dataContext) {
  Set<GotoRelatedItem> items = ContainerUtil.newLinkedHashSet();
  for (GotoRelatedProvider provider : Extensions.getExtensions(GotoRelatedProvider.EP_NAME)) {
    items.addAll(provider.getItems(contextElement));
    if (dataContext != null) {
      items.addAll(provider.getItems(dataContext));
    }
  }
  GotoRelatedItem[] result = items.toArray(new GotoRelatedItem[items.size()]);
  Arrays.sort(result, (i1, i2) -> {
    String o1 = i1.getGroup();
    String o2 = i2.getGroup();
    return StringUtil.isEmpty(o1) ? 1 : StringUtil.isEmpty(o2) ? -1 : o1.compareTo(o2);
  });
  return Arrays.asList(result);
}
 
Example 3
Source File: RootIndex.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static OrderEntry[] calcOrderEntries(@Nonnull RootInfo info,
                                             @Nonnull MultiMap<VirtualFile, OrderEntry> depEntries,
                                             @Nonnull MultiMap<VirtualFile, OrderEntry> libClassRootEntries,
                                             @Nonnull MultiMap<VirtualFile, OrderEntry> libSourceRootEntries,
                                             @Nonnull List<VirtualFile> hierarchy) {
  @Nullable VirtualFile libraryClassRoot = info.findLibraryRootInfo(hierarchy, false);
  @Nullable VirtualFile librarySourceRoot = info.findLibraryRootInfo(hierarchy, true);
  Set<OrderEntry> orderEntries = ContainerUtil.newLinkedHashSet();
  orderEntries.addAll(info.getLibraryOrderEntries(hierarchy, libraryClassRoot, librarySourceRoot, libClassRootEntries, libSourceRootEntries));
  for (VirtualFile root : hierarchy) {
    orderEntries.addAll(depEntries.get(root));
  }
  VirtualFile moduleContentRoot = info.findModuleRootInfo(hierarchy);
  if (moduleContentRoot != null) {
    ContainerUtil.addIfNotNull(orderEntries, info.getModuleSourceEntry(hierarchy, moduleContentRoot, libClassRootEntries));
  }
  if (orderEntries.isEmpty()) {
    return null;
  }

  OrderEntry[] array = orderEntries.toArray(new OrderEntry[orderEntries.size()]);
  Arrays.sort(array, RootIndex.BY_OWNER_MODULE);
  return array;
}
 
Example 4
Source File: RootIndex.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
private LinkedHashSet<OrderEntry> getLibraryOrderEntries(@Nonnull List<VirtualFile> hierarchy,
                                                         @Nullable VirtualFile libraryClassRoot,
                                                         @Nullable VirtualFile librarySourceRoot,
                                                         @Nonnull MultiMap<VirtualFile, OrderEntry> libClassRootEntries,
                                                         @Nonnull MultiMap<VirtualFile, OrderEntry> libSourceRootEntries) {
  LinkedHashSet<OrderEntry> orderEntries = ContainerUtil.newLinkedHashSet();
  for (VirtualFile root : hierarchy) {
    if (root == libraryClassRoot && !sourceRootOf.containsKey(root)) {
      orderEntries.addAll(libClassRootEntries.get(root));
    }
    if (root == librarySourceRoot && libraryClassRoot == null) {
      orderEntries.addAll(libSourceRootEntries.get(root));
    }
    if (libClassRootEntries.containsKey(root) || sourceRootOf.containsKey(root) && librarySourceRoot == null) {
      break;
    }
  }
  return orderEntries;
}
 
Example 5
Source File: RecentProjectsManagerBase.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void doReopenLastProject() {
  GeneralSettings generalSettings = GeneralSettings.getInstance();
  if (generalSettings.isReopenLastProject()) {
    Set<String> openPaths;
    boolean forceNewFrame = true;
    synchronized (myStateLock) {
      openPaths = ContainerUtil.newLinkedHashSet(myState.openPaths);
      if (openPaths.isEmpty()) {
        openPaths = ContainerUtil.createMaybeSingletonSet(myState.lastPath);
        forceNewFrame = false;
      }
    }

    for (String openPath : openPaths) {
      if (isValidProjectPath(openPath)) {
        ProjectUtil.openAsync(openPath, null, forceNewFrame, UIAccess.current());
      }
    }
  }
}
 
Example 6
Source File: LinearBekController.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
private Set<LinearBekGraphBuilder.MergeFragment> collectFragmentsToCollapse(GraphNode node) {
  Set<LinearBekGraphBuilder.MergeFragment> result = ContainerUtil.newHashSet();

  int mergesCount = 0;

  LinkedHashSet<Integer> toProcess = ContainerUtil.newLinkedHashSet();
  toProcess.add(node.getNodeIndex());
  while (!toProcess.isEmpty()) {
    Integer i = ContainerUtil.getFirstItem(toProcess);
    toProcess.remove(i);

    LinearBekGraphBuilder.MergeFragment fragment = myLinearBekGraphBuilder.getFragment(i);
    if (fragment == null) continue;

    result.add(fragment);
    toProcess.addAll(fragment.getTailsAndBody());

    mergesCount++;
    if (mergesCount > 10) break;
  }
  return result;
}
 
Example 7
Source File: ScratchFileServiceImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public Collection<VirtualFile> additionalRoots(Project project) {
  Set<VirtualFile> result = ContainerUtil.newLinkedHashSet();
  LocalFileSystem fileSystem = LocalFileSystem.getInstance();
  ScratchFileService app = ScratchFileService.getInstance();
  for (RootType r : RootType.getAllRootTypes()) {
    ContainerUtil.addIfNotNull(result, fileSystem.findFileByPath(app.getRootPath(r)));
  }
  return result;
}
 
Example 8
Source File: ChangesTreeList.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public List<T> getSelectedChanges() {
  final TreePath[] paths = getSelectionPaths();
  if (paths == null) {
    return Collections.emptyList();
  }
  else {
    LinkedHashSet<T> changes = ContainerUtil.newLinkedHashSet();
    for (TreePath path : paths) {
      //noinspection unchecked
      changes.addAll(getSelectedObjects((ChangesBrowserNode)path.getLastPathComponent()));
    }
    return ContainerUtil.newArrayList(changes);
  }
}
 
Example 9
Source File: MultipleChangeListBrowser.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public List<Change> getSelectedChanges() {
  Set<Change> changes = ContainerUtil.newLinkedHashSet();
  TreePath[] paths = myViewer.getSelectionPaths();

  if (paths != null) {
    for (TreePath path : paths) {
      ChangesBrowserNode<?> node = (ChangesBrowserNode)path.getLastPathComponent();
      changes.addAll(node.getAllChangesUnder());
    }
  }

  return ContainerUtil.newArrayList(changes);
}
 
Example 10
Source File: ChangeListWorker.java    From consulo with Apache License 2.0 5 votes vote down vote up
public ChangeListWorker(final Project project, final PlusMinusModify<BaseRevision> deltaListener) {
  myProject = project;
  myMap = new LinkedHashMap<>();
  myIdx = new ChangeListsIndexes();
  myLocallyDeleted = new DeletedFilesHolder();
  mySwitchedHolder = new SwitchedFileHolder(project, FileHolder.HolderType.SWITCHED);

  myDelta = new ChangesDelta(deltaListener);
  myListsToDisappear = ContainerUtil.newLinkedHashSet();
}
 
Example 11
Source File: AmendComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
@javax.annotation.Nullable
private String constructAmendedMessage() {
  Set<VirtualFile> selectedRoots = getVcsRoots(getSelectedFilePaths()); // get only selected files
  LinkedHashSet<String> messages = ContainerUtil.newLinkedHashSet();
  if (myMessagesForRoots != null) {
    for (VirtualFile root : selectedRoots) {
      String message = myMessagesForRoots.get(root);
      if (message != null) {
        messages.add(message);
      }
    }
  }
  return DvcsUtil.joinMessagesOrNull(messages);
}
 
Example 12
Source File: DvcsCommitAdditionalComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
private String constructAmendedMessage() {
  Set<VirtualFile> selectedRoots = getVcsRoots(getSelectedFilePaths());        // get only selected files
  LinkedHashSet<String> messages = ContainerUtil.newLinkedHashSet();
  if (myMessagesForRoots != null) {
    for (VirtualFile root : selectedRoots) {
      String message = myMessagesForRoots.get(root);
      if (message != null) {
        messages.add(message);
      }
    }
  }
  return DvcsUtil.joinMessagesOrNull(messages);
}
 
Example 13
Source File: CachingSemiGraph.java    From consulo with Apache License 2.0 5 votes vote down vote up
private CachingSemiGraph(InboundSemiGraph<Node> original) {
  myNodes = ContainerUtil.newLinkedHashSet(original.getNodes());
  myIn = new LinkedHashMap<Node, Set<Node>>();
  for (Node node : myNodes) {
    Set<Node> value = new LinkedHashSet<Node>();
    ContainerUtil.addAll(value, original.getIn(node));
    myIn.put(node, value);
  }
}
 
Example 14
Source File: EditorHistoryManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * @return a set of valid files that are in the history, oldest first.
 */
public LinkedHashSet<VirtualFile> getFileSet() {
  LinkedHashSet<VirtualFile> result = ContainerUtil.newLinkedHashSet();
  for (VirtualFile file : getFiles()) {
    // if the file occurs several times in the history, only its last occurrence counts
    result.remove(file);
    result.add(file);
  }
  return result;
}
 
Example 15
Source File: EnableMatchCaseAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void update(@Nonnull AnActionEvent e) {
  super.update(e);

  VcsLogUi ui = e.getData(VcsLogDataKeys.VCS_LOG_UI);
  VcsLogUiProperties properties = e.getData(VcsLogInternalDataKeys.LOG_UI_PROPERTIES);
  if (ui != null && properties != null && properties.exists(MainVcsLogUiProperties.TEXT_FILTER_MATCH_CASE)) {
    boolean regexEnabled =
            properties.exists(MainVcsLogUiProperties.TEXT_FILTER_REGEX) && properties.get(MainVcsLogUiProperties.TEXT_FILTER_REGEX);
    if (!regexEnabled) {
      e.getPresentation().setText(MATCH_CASE);
    }
    else {
      Collection<VcsLogProvider> providers = ContainerUtil.newLinkedHashSet(ui.getDataPack().getLogProviders().values());
      List<VcsLogProvider> supported =
              ContainerUtil.filter(providers, p -> VcsLogProperties.get(p, VcsLogProperties.CASE_INSENSITIVE_REGEX));
      e.getPresentation().setVisible(true);
      e.getPresentation().setEnabled(!supported.isEmpty());
      if (providers.size() == supported.size() || supported.isEmpty()) {
        e.getPresentation().setText(MATCH_CASE);
      }
      else {
        String supportedText = StringUtil.join(ContainerUtil.map(supported, p -> p.getSupportedVcs().getName().toLowerCase()), ", ");
        e.getPresentation().setText(MATCH_CASE + " (" + supportedText + " only)");
      }
    }
  }
}
 
Example 16
Source File: VcsLogPersistentIndex.java    From consulo with Apache License 2.0 5 votes vote down vote up
public VcsLogPersistentIndex(@Nonnull Project project,
                             @Nonnull VcsLogStorage hashMap,
                             @Nonnull VcsLogProgress progress,
                             @Nonnull Map<VirtualFile, VcsLogProvider> providers,
                             @Nonnull FatalErrorHandler fatalErrorsConsumer,
                             @Nonnull Disposable disposableParent) {
  myHashMap = hashMap;
  myProject = project;
  myProgress = progress;
  myProviders = providers;
  myFatalErrorsConsumer = fatalErrorsConsumer;
  myRoots = ContainerUtil.newLinkedHashSet();

  for (Map.Entry<VirtualFile, VcsLogProvider> entry : providers.entrySet()) {
    if (VcsLogProperties.get(entry.getValue(), VcsLogProperties.SUPPORTS_INDEXING)) {
      myRoots.add(entry.getKey());
    }
  }

  myUserRegistry = (VcsUserRegistryImpl)ServiceManager.getService(myProject, VcsUserRegistry.class);

  myIndexStorage = createIndexStorage(fatalErrorsConsumer, calcLogId(myProject, providers));

  for (VirtualFile root : myRoots) {
    myNumberOfTasks.put(root, new AtomicInteger());
  }

  Disposer.register(disposableParent, this);
}
 
Example 17
Source File: PsiSearchHelperImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean processRequests(@Nonnull SearchRequestCollector collector, @Nonnull Processor<? super PsiReference> processor) {
  final Map<SearchRequestCollector, Processor<? super PsiReference>> collectors = ContainerUtil.newHashMap();
  collectors.put(collector, processor);

  ProgressIndicator progress = getOrCreateIndicator();
  appendCollectorsFromQueryRequests(collectors);
  boolean result;
  do {
    MultiMap<Set<IdIndexEntry>, RequestWithProcessor> globals = new MultiMap<>();
    final List<Computable<Boolean>> customs = ContainerUtil.newArrayList();
    final Set<RequestWithProcessor> locals = ContainerUtil.newLinkedHashSet();
    Map<RequestWithProcessor, Processor<PsiElement>> localProcessors = new THashMap<>();
    distributePrimitives(collectors, locals, globals, customs, localProcessors, progress);
    result = processGlobalRequestsOptimized(globals, progress, localProcessors);
    if (result) {
      for (RequestWithProcessor local : locals) {
        result = processSingleRequest(local.request, local.refProcessor);
        if (!result) break;
      }
      if (result) {
        for (Computable<Boolean> custom : customs) {
          result = custom.compute();
          if (!result) break;
        }
      }
      if (!result) break;
    }
  }
  while(appendCollectorsFromQueryRequests(collectors));
  return result;
}
 
Example 18
Source File: RootIndex.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
Set<VirtualFile> getAllRoots() {
  LinkedHashSet<VirtualFile> result = ContainerUtil.newLinkedHashSet();
  result.addAll(classAndSourceRoots);
  result.addAll(contentRootOf.keySet());
  result.addAll(excludedFromLibraries.keySet());
  result.addAll(excludedFromModule.keySet());
  result.addAll(excludedFromProject);
  return result;
}
 
Example 19
Source File: NodeFinder.java    From vue-for-idea with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@NotNull
public static List<File> searchNodeModulesBin(String exeFileName) {
    Set<File> interpreters = ContainerUtil.newLinkedHashSet();
    List<File> fromPath = PathEnvironmentVariableUtil.findAllExeFilesInPath(exeFileName);
    List<File> nvmInterpreters = listNodeInterpretersFromNvm(exeFileName);
    List<File> brewInterpreters = listNodeInterpretersFromHomeBrew(exeFileName);
    interpreters.addAll(fromPath);
    interpreters.removeAll(nvmInterpreters);
    interpreters.removeAll(brewInterpreters);
    interpreters.addAll(nvmInterpreters);
    interpreters.addAll(brewInterpreters);
    return ContainerUtil.newArrayList(interpreters);
}
 
Example 20
Source File: RootIndex.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
protected Collection<VirtualFile> createCollection() {
  return ContainerUtil.newLinkedHashSet();
}