com.intellij.util.containers.ContainerUtil Java Examples

The following examples show how to use com.intellij.util.containers.ContainerUtil. 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: PhpFunctionRegistrarMatcher.java    From idea-php-toolbox with MIT License 6 votes vote down vote up
@Override
public boolean matches(@NotNull LanguageMatcherParameter parameter) {

    PsiElement parent = parameter.getElement().getParent();
    if(!(parent instanceof StringLiteralExpression)) {
        return false;
    }

    Collection<JsonSignature> signatures = ContainerUtil.filter(
        parameter.getRegistrar().getSignatures(),
        ContainerConditions.DEFAULT_TYPE_FILTER
    );

    if(signatures.size() == 0) {
        return false;
    }

    return PhpMatcherUtil.matchesArraySignature(parent, signatures);
}
 
Example #2
Source File: PatchReader.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
public ThrowableComputable<Map<String, Map<String, CharSequence>>, PatchSyntaxException> getAdditionalInfo(@Nullable Set<String> paths) {
  ThrowableComputable<Map<String, Map<String, CharSequence>>, PatchSyntaxException> result;
  PatchSyntaxException e = myAdditionalInfoParser.getSyntaxException();

  if (e != null) {
    result = () -> {
      throw e;
    };
  }
  else {
    Map<String, Map<String, CharSequence>> additionalInfo = ContainerUtil.filter(myAdditionalInfoParser.getResultMap(), path -> paths == null || paths
            .contains(path));
    result = () -> additionalInfo;
  }

  return result;
}
 
Example #3
Source File: GitLanguage.java    From idea-gitignore with MIT License 6 votes vote down vote up
/**
 * Returns outer files for the current language.
 *
 * @param project current project
 * @return outer files
 */
@NotNull
@Override
public Set<VirtualFile> getOuterFiles(@NotNull final Project project, boolean dumb) {
    final int key = new HashCodeBuilder().append(project).append(getFileType()).toHashCode();

    if (dumb || (fetched && outerFiles.get(key) != null)) {
        return super.getOuterFiles(project, true);
    }

    fetched = true;
    final Set<VirtualFile> parentFiles = super.getOuterFiles(project, false);
    final ArrayList<VirtualFile> files = new ArrayList<>(ContainerUtil.filter(
            IgnoreFilesIndex.getFiles(project, GitExcludeFileType.INSTANCE),
            virtualFile -> Utils.isInProject(virtualFile, project)
    ));

    ContainerUtil.addAllNotNull(parentFiles, files);
    return outerFiles.getOrElse(key, new HashSet<>());
}
 
Example #4
Source File: ServiceCollectorTest.java    From idea-php-shopware-plugin with MIT License 6 votes vote down vote up
public void testCollectionForSubscriberEvents() {
    ServiceCollector serviceCollector = new ServiceCollector();

    Collection<String> names = new ArrayList<>();
    serviceCollector.collectIds(new ServiceCollectorParameter.Id(getProject(), names));
    assertTrue(names.contains("foobar.my.subscriber"));

    Collection<ServiceInterface> services = new ArrayList<>();
    serviceCollector.collectServices(new ServiceCollectorParameter.Service(getProject(), services));

    ServiceInterface service = ContainerUtil.find(services, serviceInterface ->
        serviceInterface.getId().equals("foobar.my.subscriber")
    );

    assertNotNull(service);
    assertEquals("Foo\\MySubscriber", service.getClassName());
}
 
Example #5
Source File: DvcsTaskHandler.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
private List<R> getRepositories(@Nonnull Collection<String> urls) {
  final List<R> repositories = myRepositoryManager.getRepositories();
  return ContainerUtil.mapNotNull(urls, new NullableFunction<String, R>() {
    @Nullable
    @Override
    public R fun(final String s) {

      return ContainerUtil.find(repositories, new Condition<R>() {
        @Override
        public boolean value(R repository) {
          return s.equals(repository.getPresentableUrl());
        }
      });
    }
  });
}
 
Example #6
Source File: XmlGotoCompletionRegistrar.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public Collection<LookupElement> getLookupElements() {
    PsiElement parent = getElement().getParent();
    if(!(parent instanceof XmlAttributeValue)) {
        return Collections.emptyList();
    }

    Collection<PhpClass> phpClasses = new ArrayList<>();

    ContainerUtil.addIfNotNull(phpClasses, XmlHelper.getPhpClassForClassFactory((XmlAttributeValue) parent));
    ContainerUtil.addIfNotNull(phpClasses, XmlHelper.getPhpClassForServiceFactory((XmlAttributeValue) parent));

    Collection<LookupElement> lookupElements = new ArrayList<>();

    for (PhpClass phpClass : phpClasses) {
        lookupElements.addAll(PhpElementsUtil.getClassPublicMethod(phpClass).stream()
            .map(PhpLookupElement::new)
            .collect(Collectors.toList())
        );
    }

    return lookupElements;
}
 
Example #7
Source File: CodeStyleSettingPresentation.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * Returns an immutable map containing all standard settings in a mapping of type (group -> settings contained in the group).
 * Notice that lists containing settings for a specific group are also immutable. Use copies to make modifications.
 *
 * @param settingsType type to get standard settings for
 * @return mapping setting groups to contained setting presentations
 */
@Nonnull
public static Map<SettingsGroup, List<CodeStyleSettingPresentation>> getStandardSettings(LanguageCodeStyleSettingsProvider.SettingsType settingsType) {
  switch (settingsType) {
    case BLANK_LINES_SETTINGS:
      return BLANK_LINES_STANDARD_SETTINGS;
    case SPACING_SETTINGS:
      return SPACING_STANDARD_SETTINGS;
    case WRAPPING_AND_BRACES_SETTINGS:
      return WRAPPING_AND_BRACES_STANDARD_SETTINGS;
    case INDENT_SETTINGS:
      return INDENT_STANDARD_SETTINGS;
    case LANGUAGE_SPECIFIC:
  }
  return ContainerUtil.newLinkedHashMap();
}
 
Example #8
Source File: PhpFunctionRegistrarMatcher.java    From idea-php-toolbox with MIT License 6 votes vote down vote up
@Override
public boolean matches(@NotNull LanguageMatcherParameter parameter) {

    PsiElement parent = parameter.getElement().getParent();
    if(!(parent instanceof StringLiteralExpression)) {
        return false;
    }

    Collection<JsonSignature> signatures = ContainerUtil.filter(
        parameter.getRegistrar().getSignatures(),
        ContainerConditions.DEFAULT_TYPE_FILTER
    );

    if(signatures.size() == 0) {
        return false;
    }

    return PhpMatcherUtil.matchesArraySignature(parent, signatures);
}
 
Example #9
Source File: ExternalExec.java    From idea-gitignore with MIT License 6 votes vote down vote up
/**
 * Returns list of unignored files for the given directory.
 *
 * @param language to check
 * @param project  current project
 * @param file     current file
 * @return unignored files list
 */
@NotNull
public static List<String> getUnignoredFiles(@NotNull IgnoreLanguage language, @NotNull Project project,
                                             @NotNull VirtualFile file) {
    if (!Utils.isInProject(file, project)) {
        return new ArrayList<>();
    }

    ArrayList<String> result = run(
            language,
            GIT_UNIGNORED_FILES,
            file.getParent(),
            new GitUnignoredFilesOutputParser()
    );
    return ContainerUtil.notNullize(result);
}
 
Example #10
Source File: DefaultInspectionToolPresentation.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
@Nonnull
public FileStatus getProblemStatus(@Nonnull final CommonProblemDescriptor descriptor) {
  final GlobalInspectionContextImpl context = getContext();
  if (!isDisposed() && context.getUIOptions().SHOW_DIFF_WITH_PREVIOUS_RUN){
    if (myOldProblemElements != null){
      final Set<CommonProblemDescriptor> allAvailable = new HashSet<CommonProblemDescriptor>();
      for (CommonProblemDescriptor[] descriptors : myOldProblemElements.values()) {
        if (descriptors != null) {
          ContainerUtil.addAll(allAvailable, descriptors);
        }
      }
      final boolean old = containsDescriptor(descriptor, allAvailable);
      final boolean current = containsDescriptor(descriptor, getProblemToElements().keySet());
      return calcStatus(old, current);
    }
  }
  return FileStatus.NOT_CHANGED;
}
 
Example #11
Source File: RecentLocationsAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static void removePlaces(@Nonnull Project project,
                                 @Nonnull ListWithFilter<RecentLocationItem> listWithFilter,
                                 @Nonnull JBList<RecentLocationItem> list,
                                 @Nonnull RecentLocationsDataModel data,
                                 boolean showChanged) {
  List<RecentLocationItem> selectedValue = list.getSelectedValuesList();
  if (selectedValue.isEmpty()) {
    return;
  }

  int index = list.getSelectedIndex();

  IdeDocumentHistory ideDocumentHistory = IdeDocumentHistory.getInstance(project);
  for (RecentLocationItem item : selectedValue) {
    if (showChanged) {
      ContainerUtil.filter(ideDocumentHistory.getChangePlaces(), info -> IdeDocumentHistoryImpl.isSame(info, item.getInfo())).forEach(info -> ideDocumentHistory.removeChangePlace(info));
    }
    else {
      ContainerUtil.filter(ideDocumentHistory.getBackPlaces(), info -> IdeDocumentHistoryImpl.isSame(info, item.getInfo())).forEach(info -> ideDocumentHistory.removeBackPlace(info));
    }
  }

  updateModel(listWithFilter, data, showChanged);

  if (list.getModel().getSize() > 0) ScrollingUtil.selectItem(list, index < list.getModel().getSize() ? index : index - 1);
}
 
Example #12
Source File: SystemInfo.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
protected Map<String, String> compute() {
  if (isUnix && !isMac) {
    try {
      List<String> lines = FileUtil.loadLines("/etc/os-release");
      Map<String, String> info = ContainerUtil.newHashMap();
      for (String line : lines) {
        int p = line.indexOf('=');
        if (p > 0) {
          String name = line.substring(0, p);
          String value = StringUtil.unquoteString(line.substring(p + 1));
          if (!StringUtil.isEmptyOrSpaces(name) && !StringUtil.isEmptyOrSpaces(value)) {
            info.put(name, value);
          }
        }
      }
      return info;
    }
    catch (IOException ignored) {
    }
  }

  return Collections.emptyMap();
}
 
Example #13
Source File: TwigUtil.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
/**
 * Extract template name from embed tag
 *
 * {% embed "teasers_skeleton.html.twig" %}
 */
@Nullable
private static String getTemplateNameForEmbedTag(@NotNull PsiElement embedTag) {
    if(embedTag.getNode().getElementType() == TwigElementTypes.EMBED_TAG) {
        PsiElement fileReference = ContainerUtil.find(YamlHelper.getChildrenFix(embedTag), psiElement ->
            TwigPattern.getTemplateFileReferenceTagPattern().accepts(psiElement)
        );

        if(fileReference != null && TwigUtil.isValidStringWithoutInterpolatedOrConcat(fileReference)) {
            String text = fileReference.getText();
            if(StringUtils.isNotBlank(text)) {
                return text;
            }
        }
    }

    return null;
}
 
Example #14
Source File: SymlinkHandlingTest.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void assertVisitedPaths(String... expected) {
  VirtualFile vDir = myFileSystem.findFileByIoFile(myTempDir);
  assertNotNull(vDir);

  Set<String> expectedSet = new HashSet<String>(expected.length + 1, 1);
  ContainerUtil.addAll(expectedSet, FileUtil.toSystemIndependentName(myTempDir.getPath()));
  ContainerUtil.addAll(expectedSet, ContainerUtil.map(expected, new Function<String, String>() {
    @Override
    public String fun(String path) {
      return FileUtil.toSystemIndependentName(path);
    }
  }));

  final Set<String> actualSet = new HashSet<String>();
  VfsUtilCore.visitChildrenRecursively(vDir, new VirtualFileVisitor() {
    @Override
    public boolean visitFile(@Nonnull VirtualFile file) {
      actualSet.add(file.getPath());
      return true;
    }
  });

  assertEquals(expectedSet, actualSet);
}
 
Example #15
Source File: StructureFilteringStrategy.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
private List<FilePath> getFilePathsUnder(@Nonnull ChangesBrowserNode<?> node) {
  List<FilePath> result = Collections.emptyList();
  Object userObject = node.getUserObject();

  if (userObject instanceof FilePath) {
    result = ContainerUtil.list(((FilePath)userObject));
  }
  else if (userObject instanceof Module) {
    result = Arrays.stream(ModuleRootManager.getInstance((Module)userObject).getContentRoots())
            .map(VcsUtil::getFilePath)
            .collect(Collectors.toList());
  }

  return result;
}
 
Example #16
Source File: HLint.java    From intellij-haskforce with Apache License 2.0 6 votes vote down vote up
/**
 * Parse a single problem from the old hlint output if json is not supported.
 */
@Nullable
public static Problem parseProblemFallback(String lint) {
    List<String> split = StringUtil.split(lint, ":");
    if (split.size() < 5) {
        return null;
    }
    int line = StringUtil.parseInt(split.get(1), 0);
    if (line == 0) {
        return null;
    }
    int column = StringUtil.parseInt(split.get(2), 0);
    if (column == 0) {
        return null;
    }
    String hint = StringUtil.split(split.get(4), "\n").get(0);
    split = StringUtil.split(lint, "\n");
    split = ContainerUtil.subList(split, 2);
    split = StringUtil.split(StringUtil.join(split, "\n"), "Why not:");
    if (split.size() != 2) {
        return null;
    }
    final String from = split.get(0).trim();
    final String to = split.get(1).trim();
    return Problem.forFallback("", "", hint, from, to, "", new String[]{}, "", line, column);
}
 
Example #17
Source File: InspectionManagerEx.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
public static SuppressIntentionAction[] getSuppressActions(@Nonnull InspectionToolWrapper toolWrapper) {
  final InspectionProfileEntry tool = toolWrapper.getTool();
  if (tool instanceof CustomSuppressableInspectionTool) {
    return ((CustomSuppressableInspectionTool)tool).getSuppressActions(null);
  }
  final List<LocalQuickFix> actions = new ArrayList<LocalQuickFix>(Arrays.asList(tool.getBatchSuppressActions(null)));
  if (actions.isEmpty()) {
    final Language language = Language.findLanguageByID(toolWrapper.getLanguage());
    if (language != null) {
      final List<InspectionSuppressor> suppressors = LanguageInspectionSuppressors.INSTANCE.allForLanguage(language);
      for (InspectionSuppressor suppressor : suppressors) {
        final SuppressQuickFix[] suppressActions = suppressor.getSuppressActions(null, tool.getShortName());
        Collections.addAll(actions, suppressActions);
      }
    }
  }
  return ContainerUtil.map2Array(actions, SuppressIntentionAction.class, new Function<LocalQuickFix, SuppressIntentionAction>() {
    @Override
    public SuppressIntentionAction fun(final LocalQuickFix fix) {
      return SuppressIntentionActionFromFix.convertBatchToSuppressIntentionAction((SuppressQuickFix)fix);
    }
  });
}
 
Example #18
Source File: ProjectLibraryTabContext.java    From consulo with Apache License 2.0 6 votes vote down vote up
public ProjectLibraryTabContext(final ClasspathPanel classpathPanel, StructureConfigurableContext context) {
  super(classpathPanel, context);

  StructureLibraryTableModifiableModelProvider projectLibrariesProvider = context.getProjectLibrariesProvider();
  Library[] libraries = projectLibrariesProvider.getModifiableModel().getLibraries();
  final Condition<Library> condition = LibraryEditingUtil.getNotAddedLibrariesCondition(myClasspathPanel.getRootModel());

  myItems = ContainerUtil.filter(libraries, condition);
  ContainerUtil.sort(myItems, new Comparator<Library>() {
    @Override
    public int compare(Library o1, Library o2) {
      return StringUtil.compare(o1.getName(), o2.getName(), false);
    }
  });

  myLibraryList = new JBList(myItems);
  myLibraryList.setCellRenderer(new ColoredListCellRendererWrapper<Library>() {
    @Override
    protected void doCustomize(JList list, Library value, int index, boolean selected, boolean hasFocus) {
      final CellAppearanceEx appearance = OrderEntryAppearanceService.getInstance().forLibrary(classpathPanel.getProject(), value, false);

      appearance.customize(this);
    }
  });
  new ListSpeedSearch(myLibraryList);
}
 
Example #19
Source File: VcsRepositoryManager.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
private Map<VirtualFile, Repository> findNewRoots(@Nonnull Set<VirtualFile> knownRoots) {
  Map<VirtualFile, Repository> newRootsMap = ContainerUtil.newHashMap();
  for (VcsRoot root : myVcsManager.getAllVcsRoots()) {
    VirtualFile rootPath = root.getPath();
    if (rootPath != null && !knownRoots.contains(rootPath)) {
      AbstractVcs vcs = root.getVcs();
      VcsRepositoryCreator repositoryCreator = getRepositoryCreator(vcs);
      if (repositoryCreator == null) continue;
      Repository repository = repositoryCreator.createRepositoryIfValid(rootPath);
      if (repository != null) {
        newRootsMap.put(rootPath, repository);
      }
    }
  }
  return newRootsMap;
}
 
Example #20
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 #21
Source File: FragmentGenerator.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
public GreenFragment getGreenFragmentForCollapse(int startNode, int maxWalkSize) {
  if (myRedNodes.value(startNode)) return new GreenFragment(null, null, Collections.<Integer>emptySet());
  Integer upRedNode = getNearRedNode(startNode, maxWalkSize, true);
  Integer downRedNode = getNearRedNode(startNode, maxWalkSize, false);

  Set<Integer> upPart =
    upRedNode != null ? getMiddleNodes(upRedNode, startNode, false) : getWalkNodes(startNode, true, createStopFunction(maxWalkSize));

  Set<Integer> downPart =
    downRedNode != null ? getMiddleNodes(startNode, downRedNode, false) : getWalkNodes(startNode, false, createStopFunction(maxWalkSize));

  Set<Integer> middleNodes = ContainerUtil.union(upPart, downPart);
  if (upRedNode != null) middleNodes.remove(upRedNode);
  if (downRedNode != null) middleNodes.remove(downRedNode);

  return new GreenFragment(upRedNode, downRedNode, middleNodes);
}
 
Example #22
Source File: AbstractServiceReference.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public Object[] getVariants() {

    ContainerCollectionResolver.ServiceCollector collector = ContainerCollectionResolver
        .ServiceCollector.create(getElement().getProject());

    Collection<ContainerService> values = collector.getServices().values();

    if(!usePrivateServices) {
        values = ContainerUtil.filter(values, service -> !service.isPrivate());
    }

    List<LookupElement> results = new ArrayList<>(ServiceCompletionProvider.getLookupElements(null, values).getLookupElements());
    return results.toArray();
}
 
Example #23
Source File: ServiceArgumentParameterHintsProviderTest.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
public void testYamlParameterTypeForCallMethodParameter() {
    List<InlayInfo> parameterHints = getInlayInfo(YAMLFileType.YML,"" +
        "services:\n" +
        "    foobar:\n" +
        "        class: Foobar\\MyFoobar\n" +
        "        calls:\n" +
        "           - [setFoo, [@fo<caret>obar]]\n"
    );

    assertNotNull(ContainerUtil.find(parameterHints, inlayInfo -> "FooInterface".equals(inlayInfo.getText())));
}
 
Example #24
Source File: DefaultArrangementEntryMatcherSerializer.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void visit(@Nonnull ArrangementCompositeMatchCondition condition) {
  Element composite = new Element(COMPOSITE_CONDITION_NAME);
  register(composite);
  parent = composite;
  List<ArrangementMatchCondition> operands = ContainerUtilRt.newArrayList(condition.getOperands());
  ContainerUtil.sort(operands, CONDITION_COMPARATOR);
  for (ArrangementMatchCondition c : operands) {
    c.invite(this);
  }
}
 
Example #25
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 #26
Source File: TypePresentationServiceImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void walkSupers(Class aClass, Set<Class> classes, Set<PresentationTemplate> templates) {
  if (!classes.add(aClass)) {
    return;
  }
  ContainerUtil.addIfNotNull(templates, createPresentationTemplate(aClass));
  final Class superClass = aClass.getSuperclass();
  if (superClass != null) {
    walkSupers(superClass, classes, templates);
  }

  for (Class intf : aClass.getInterfaces()) {
    walkSupers(intf, classes, templates);
  }
}
 
Example #27
Source File: GlobalSearchScope.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isSearchInLibraries() {
  return ContainerUtil.find(myScopes, new Condition<GlobalSearchScope>() {
    @Override
    public boolean value(GlobalSearchScope scope) {
      return scope.isSearchInLibraries();
    }
  }) != null;
}
 
Example #28
Source File: RollbackAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static boolean hasReversibleFiles(@Nonnull AnActionEvent e) {
  ChangeListManager manager = ChangeListManager.getInstance(e.getRequiredData(CommonDataKeys.PROJECT));
  Set<VirtualFile> modifiedWithoutEditing = ContainerUtil.newHashSet(manager.getModifiedWithoutEditing());

  return notNullize(e.getData(VcsDataKeys.VIRTUAL_FILE_STREAM)).anyMatch(
          file -> manager.haveChangesUnder(file) != ThreeState.NO || manager.isFileAffected(file) || modifiedWithoutEditing.contains(file));
}
 
Example #29
Source File: TreeFileChooserDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
public String[] getNames(final boolean checkBoxState) {
  final String[] fileNames;
  if (myFileType != null && myProject != null) {
    GlobalSearchScope scope = myShowLibraryContents ? GlobalSearchScope.allScope(myProject) : GlobalSearchScope.projectScope(myProject);
    Collection<VirtualFile> virtualFiles = FileTypeIndex.getFiles(myFileType, scope);
    fileNames = ContainerUtil.map2Array(virtualFiles, String.class, new Function<VirtualFile, String>() {
      @Override
      public String fun(VirtualFile file) {
        return file.getName();
      }
    });
  }
  else {
    fileNames = FilenameIndex.getAllFilenames(myProject);
  }
  final Set<String> array = new THashSet<String>();
  for (String fileName : fileNames) {
    if (!array.contains(fileName)) {
      array.add(fileName);
    }
  }

  final String[] result = ArrayUtil.toStringArray(array);
  Arrays.sort(result);
  return result;
}
 
Example #30
Source File: PsiFileNode.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<AbstractTreeNode> getChildrenImpl() {
  Project project = getProject();
  VirtualFile jarRoot = getArchiveRoot();
  if (project != null && jarRoot != null) {
    PsiDirectory psiDirectory = PsiManager.getInstance(project).findDirectory(jarRoot);
    if (psiDirectory != null) {
      return BaseProjectViewDirectoryHelper.getDirectoryChildren(psiDirectory, getSettings(), true);
    }
  }

  return ContainerUtil.emptyList();
}