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

The following examples show how to use com.intellij.util.containers.ContainerUtil#newSmartList() . 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: ExternalSystemTestCase.java    From intellij-quarkus with Eclipse Public License 2.0 6 votes vote down vote up
public static Collection<String> collectRootsInside(String root) {
  final List<String> roots = ContainerUtil.newSmartList();
  roots.add(root);
  FileUtil.processFilesRecursively(new File(root), file -> {
    try {
      String path = file.getCanonicalPath();
      if (!FileUtil.isAncestor(path, path, false)) {
        roots.add(path);
      }
    }
    catch (IOException ignore) {
    }
    return true;
  });

  return roots;
}
 
Example 2
Source File: MergeModelBase.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void beforeDocumentChange(DocumentEvent e) {
  if (isDisposed()) return;
  enterBulkChangeUpdateBlock();

  if (getChangesCount() == 0) return;

  LineRange lineRange = DiffUtil.getAffectedLineRange(e);
  int shift = DiffUtil.countLinesShift(e);

  List<S> corruptedStates = ContainerUtil.newSmartList();
  for (int index = 0; index < getChangesCount(); index++) {
    S oldState = processDocumentChange(index, lineRange.start, lineRange.end, shift);
    if (oldState == null) continue;

    invalidateHighlighters(index);
    if (!isInsideCommand()) corruptedStates.add(oldState);
  }

  if (myUndoManager != null && !corruptedStates.isEmpty()) {
    // document undo is registered inside onDocumentChange, so our undo() will be called after its undo().
    // thus thus we can avoid checks for isUndoInProgress() (to avoid modification of the same TextMergeChange by this listener)
    myUndoManager.undoableActionPerformed(new MyUndoableAction(MergeModelBase.this, corruptedStates, true));
  }
}
 
Example 3
Source File: CollapsedGraph.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public List<GraphEdge> getAdjacentEdges(int nodeIndex, @Nonnull EdgeFilter filter) {
  assertNotUnderModification();
  List<GraphEdge> result = ContainerUtil.newSmartList();
  int delegateIndex = myNodesMap.getLongIndex(nodeIndex);

  // add delegate edges
  for (GraphEdge delegateEdge : myDelegatedGraph.getAdjacentEdges(delegateIndex, filter)) {
    Integer compiledUpIndex = compiledNodeIndex(delegateEdge.getUpNodeIndex());
    Integer compiledDownIndex = compiledNodeIndex(delegateEdge.getDownNodeIndex());
    if (isVisibleEdge(compiledUpIndex, compiledDownIndex)) result.add(createEdge(delegateEdge, compiledUpIndex, compiledDownIndex));
  }

  result.addAll(myEdgeStorageWrapper.getAdjacentEdges(nodeIndex, filter));

  return result;
}
 
Example 4
Source File: VfsUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static List<VirtualFile> getChildren(@Nonnull VirtualFile dir, @Nonnull VirtualFileFilter filter) {
  List<VirtualFile> result = null;
  for (VirtualFile child : dir.getChildren()) {
    if (filter.accept(child)) {
      if (result == null) result = ContainerUtil.newSmartList();
      result.add(child);
    }
  }
  return result != null ? result : ContainerUtil.<VirtualFile>emptyList();
}
 
Example 5
Source File: CanonicalPathMap.java    From consulo with Apache License 2.0 5 votes vote down vote up
CanonicalPathMap(@Nonnull List<String> recursive, @Nonnull List<String> flat) {
  myRecursiveWatchRoots = new ArrayList<>(recursive);
  myFlatWatchRoots = new ArrayList<>(flat);

  List<Pair<String, String>> mapping = ContainerUtil.newSmartList();
  Map<String, String> resolvedPaths = resolvePaths(recursive, flat);
  myCanonicalRecursiveWatchRoots = mapPaths(resolvedPaths, recursive, mapping);
  myCanonicalFlatWatchRoots = mapPaths(resolvedPaths, flat, mapping);

  myPathMapping = MultiMap.createConcurrentSet();
  addMapping(mapping);
}
 
Example 6
Source File: ToggleToolbarAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public AnAction[] getChildren(@Nullable AnActionEvent e) {
  ContentManager contentManager = myToolWindow.getContentManager();
  Content selectedContent = contentManager.getSelectedContent();
  JComponent contentComponent = selectedContent != null ? selectedContent.getComponent() : null;
  if (contentComponent == null) return EMPTY_ARRAY;
  List<AnAction> result = ContainerUtil.newSmartList();
  for (final ActionToolbar toolbar : iterateToolbars(contentComponent)) {
    JComponent c = toolbar.getComponent();
    if (c.isVisible() || !c.isValid()) continue;
    if (!result.isEmpty() && !(ContainerUtil.getLastItem(result) instanceof AnSeparator)) {
      result.add(AnSeparator.getInstance());
    }

    List<AnAction> actions = toolbar.getActions();
    for (AnAction action : actions) {
      if (action instanceof ToggleAction && !result.contains(action)) {
        result.add(action);
      }
      else if (action instanceof AnSeparator) {
        if (!result.isEmpty() && !(ContainerUtil.getLastItem(result) instanceof AnSeparator)) {
          result.add(AnSeparator.getInstance());
        }
      }
    }
  }
  boolean popup = result.size() > 3;
  setPopup(popup);
  if (!popup && !result.isEmpty()) result.add(AnSeparator.getInstance());
  return result.toArray(new AnAction[result.size()]);
}
 
Example 7
Source File: EdgeStorageWrapper.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public List<GraphEdge> getAdjacentEdges(int nodeIndex, @Nonnull EdgeFilter filter) {
  List<GraphEdge> result = ContainerUtil.newSmartList();
  for (Pair<Integer, GraphEdgeType> retrievedEdge : myEdgeStorage.getEdges(myGetNodeIdByIndex.fun(nodeIndex))) {
    GraphEdge edge = decompressEdge(nodeIndex, retrievedEdge.first, retrievedEdge.second);
    if (matchedEdge(nodeIndex, edge, filter)) result.add(edge);
  }
  return result;
}
 
Example 8
Source File: DefaultArrangementSettingsSerializer.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private List<ArrangementGroupingRule> deserializeGropings(@Nonnull Element element, @Nullable ArrangementSettings defaultSettings) {
  Element groups = element.getChild(GROUPS_ELEMENT_NAME);
  if (groups == null) {
    return defaultSettings == null ? ContainerUtil.<ArrangementGroupingRule>newSmartList() : defaultSettings.getGroupings();
  }

  final List<ArrangementGroupingRule> groupings = new ArrayList<ArrangementGroupingRule>();
  for (Object group : groups.getChildren(GROUP_ELEMENT_NAME)) {
    Element groupElement = (Element)group;

    // Grouping type.
    String groupingTypeId = groupElement.getChildText(TYPE_ELEMENT_NAME);
    ArrangementSettingsToken groupingType = StdArrangementTokens.byId(groupingTypeId);
    if (groupingType == null) {
      groupingType = myMixin.deserializeToken(groupingTypeId);
    }
    if (groupingType == null) {
      LOG.warn(String.format("Can't deserialize grouping type token by id '%s'", groupingTypeId));
      continue;
    }

    // Order type.
    String orderTypeId = groupElement.getChildText(ORDER_TYPE_ELEMENT_NAME);
    ArrangementSettingsToken orderType = StdArrangementTokens.byId(orderTypeId);
    if (orderType == null) {
      orderType = myMixin.deserializeToken(orderTypeId);
    }
    if (orderType == null) {
      LOG.warn(String.format("Can't deserialize grouping order type token by id '%s'", orderTypeId));
      continue;
    }
    groupings.add(new ArrangementGroupingRule(groupingType, orderType));
  }
  return groupings;
}
 
Example 9
Source File: PackageDirectoryCache.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private PackageInfo getPackageInfo(@Nonnull final String packageName) {
  PackageInfo info = myDirectoriesByPackageNameCache.get(packageName);
  if (info == null) {
    if (myNonExistentPackages.contains(packageName)) return null;

    if (packageName.length() > Registry.intValue("java.max.package.name.length") || StringUtil.containsAnyChar(packageName, ";[/")) {
      return null;
    }

    List<VirtualFile> result = ContainerUtil.newSmartList();

    if (StringUtil.isNotEmpty(packageName) && !StringUtil.startsWithChar(packageName, '.')) {
      int i = packageName.lastIndexOf('.');
      while (true) {
        PackageInfo parentInfo = getPackageInfo(i > 0 ? packageName.substring(0, i) : "");
        if (parentInfo != null) {
          result.addAll(parentInfo.getSubPackageDirectories(packageName.substring(i + 1)));
        }
        if (i < 0) break;
        i = packageName.lastIndexOf('.', i - 1);
        ProgressManager.checkCanceled();
      }
    }

    for (VirtualFile file : myRootsByPackagePrefix.get(packageName)) {
      if (file.isDirectory()) {
        result.add(file);
      }
    }

    if (!result.isEmpty()) {
      myDirectoriesByPackageNameCache.put(packageName, info = new PackageInfo(packageName, result));
    } else {
      myNonExistentPackages.add(packageName);
    }
  }

  return info;
}
 
Example 10
Source File: RearrangeCodeProcessor.java    From consulo with Apache License 2.0 5 votes vote down vote up
public Collection<TextRange> getRangesToFormat(@Nonnull PsiFile file, boolean processChangedTextOnly) throws FilesTooBigForDiffException {
  if (mySelectionModel != null) {
    return getSelectedRanges(mySelectionModel);
  }

  if (processChangedTextOnly) {
    return FormatChangedTextUtil.getInstance().getChangedTextRanges(myProject, file);
  }

  return ContainerUtil.newSmartList(file.getTextRange());
}
 
Example 11
Source File: DependantSpacingImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
public DependantSpacingImpl(final int minSpaces,
                            final int maxSpaces,
                            @Nonnull TextRange dependency,
                            final boolean keepLineBreaks,
                            final int keepBlankLines,
                            @Nonnull DependentSpacingRule rule)
{
  super(minSpaces, maxSpaces, 0, false, false, keepLineBreaks, keepBlankLines, false, 0);
  myDependentRegionRanges = ContainerUtil.newSmartList(dependency);
  myRule = rule;
}
 
Example 12
Source File: RootIndex.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public Query<VirtualFile> getDirectoriesByPackageName(@Nonnull final String packageName, final boolean includeLibrarySources) {
  List<VirtualFile> result = myDirectoriesByPackageNameCache.get(packageName);
  if (result == null) {
    if (myNonExistentPackages.contains(packageName)) return EmptyQuery.getEmptyQuery();

    result = ContainerUtil.newSmartList();

    if (StringUtil.isNotEmpty(packageName) && !StringUtil.startsWithChar(packageName, '.')) {
      int i = packageName.lastIndexOf('.');
      while (true) {
        String shortName = packageName.substring(i + 1);
        String parentPackage = i > 0 ? packageName.substring(0, i) : "";
        for (VirtualFile parentDir : getDirectoriesByPackageName(parentPackage, true)) {
          VirtualFile child = !parentDir.isValid() ? null : parentDir.findChild(shortName);
          if (child != null && child.isDirectory() && getInfoForFile(child).isInProject() && packageName.equals(getPackageName(child))) {
            result.add(child);
          }
        }
        if (i < 0) break;
        i = packageName.lastIndexOf('.', i - 1);
      }
    }

    for (VirtualFile file : myPackagePrefixRoots.get(packageName)) {
      if (file.isDirectory()) {
        result.add(file);
      }
    }

    if (!result.isEmpty()) {
      myDirectoriesByPackageNameCache.put(packageName, result);
    }
    else {
      myNonExistentPackages.add(packageName);
    }
  }

  if (!includeLibrarySources) {
    result = ContainerUtil.filter(result, file -> {
      DirectoryInfo info = getInfoForFile(file);
      return info.isInProject() && (!info.isInLibrarySource() || info.isInModuleSource() || info.hasLibraryClassRoot());
    });
  }
  return new CollectionQuery<>(result);
}
 
Example 13
Source File: DefaultArrangementSettingsSerializer.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
private List<StdArrangementMatchRule> deserializeRules(@Nonnull Element element, @Nullable final Set<StdArrangementRuleAliasToken> aliases) {
  if (aliases != null && myMixin instanceof MutableMixin) {
    ((MutableMixin)myMixin).setMyRuleAliases(aliases);
  }
  final List<StdArrangementMatchRule> rules = new ArrayList<StdArrangementMatchRule>();
  for (Object o : element.getChildren(RULE_ELEMENT_NAME)) {
    Element ruleElement = (Element)o;
    Element matcherElement = ruleElement.getChild(MATCHER_ELEMENT_NAME);
    if (matcherElement == null) {
      continue;
    }

    StdArrangementEntryMatcher matcher = null;
    for (Object c : matcherElement.getChildren()) {
      matcher = myMatcherSerializer.deserialize((Element)c);
      if (matcher != null) {
        break;
      }
    }

    if (matcher == null) {
      return ContainerUtil.newSmartList();
    }

    Element orderTypeElement = ruleElement.getChild(ORDER_TYPE_ELEMENT_NAME);
    ArrangementSettingsToken orderType = null;
    if (orderTypeElement != null) {
      String orderTypeId = orderTypeElement.getText();
      orderType = StdArrangementTokens.byId(orderTypeId);
      if (orderType == null) {
        orderType = myMixin.deserializeToken(orderTypeId);
      }
      if (orderType == null) {
        LOG.warn(String.format("Can't deserialize matching rule order type for id '%s'. Falling back to default (%s)",
                               orderTypeId, ArrangementMatchRule.DEFAULT_ORDER_TYPE.getId()));
      }
    }
    if (orderType == null) {
      orderType = ArrangementMatchRule.DEFAULT_ORDER_TYPE;
    }
    rules.add(new StdArrangementMatchRule(matcher, orderType));
  }
  return rules;
}
 
Example 14
Source File: BackgroundUpdaterTaskBase.java    From consulo with Apache License 2.0 4 votes vote down vote up
public BackgroundUpdaterTaskBase(@Nullable Project project, @Nonnull String title, @Nullable Comparator<T> comparator) {
  super(project, title);
  myData = comparator == null ? ContainerUtil.newSmartList() : new TreeSet<>(comparator);
}