public static String getFileChooserDescription(final Project project) { ProjectImportProvider[] providers = ProjectImportProvider.PROJECT_IMPORT_PROVIDER.getExtensions(); List<ProjectImportProvider> list = ContainerUtil.filter( providers, new Condition<ProjectImportProvider>() { @Override public boolean value(ProjectImportProvider provider) { return project != null || provider.canCreateNewProject(); } }); StringBuilder builder = new StringBuilder("<html>Select "); boolean first = true; if (list.size() > 1) { for (ProjectImportProvider provider : list) { String sample = provider.getFileSample(); if (sample != null) { if (!first) { builder.append(", <br>"); } else { first = false; } builder.append(sample); } } } builder.append(".</html>"); return builder.toString(); }
public void switchSubtask(@NotNull Document document, int fromSubtask, int toSubtask) { Set<Integer> indexes = mySubtaskInfos.keySet(); int visibleLength = getVisibleLength(fromSubtask); if (indexes.contains(toSubtask)) { if (!myUseLength) { String replacementText = mySubtaskInfos.get(toSubtask).getPossibleAnswer(); EduUtils.replaceAnswerPlaceholder(document, this, visibleLength, replacementText); return; } } Integer minIndex = Collections.min(indexes); if (fromSubtask < toSubtask) { if (minIndex > fromSubtask && minIndex <= toSubtask) { Integer maxIndex = Collections.max(ContainerUtil.filter(indexes, integer -> integer <= toSubtask)); AnswerPlaceholderSubtaskInfo maxInfo = mySubtaskInfos.get(maxIndex); String replacementText = myUseLength ? maxInfo.getPlaceholderText() : maxInfo.getPossibleAnswer(); EduUtils.replaceAnswerPlaceholder(document, this, visibleLength, replacementText); return; } } if (fromSubtask > toSubtask) { if (minIndex > toSubtask && minIndex <= fromSubtask) { AnswerPlaceholderSubtaskInfo minInfo = mySubtaskInfos.get(minIndex); if (minInfo.isNeedInsertText()) { EduUtils.replaceAnswerPlaceholder(document, this, visibleLength, ""); } else { String replacementText = minInfo.getPlaceholderText(); EduUtils.replaceAnswerPlaceholder(document, this, visibleLength, replacementText); } return; } if (indexes.contains(fromSubtask)) { List<Integer> filtered = ContainerUtil.filter(indexes, index -> index < fromSubtask); if (filtered.isEmpty()) { return; } Integer maxIndex = Collections.max(filtered); AnswerPlaceholderSubtaskInfo maxInfo = mySubtaskInfos.get(maxIndex); if (maxInfo.isNeedInsertText()) { EduUtils.replaceAnswerPlaceholder(document, this, visibleLength, ""); } else { String replacementText = myUseLength ? maxInfo.getPlaceholderText() : maxInfo.getPossibleAnswer(); EduUtils.replaceAnswerPlaceholder(document, this, visibleLength, replacementText); } } } }
@Nullable public static AddModuleWizard createImportWizard( final Project project, @Nullable Component dialogParent, final VirtualFile file, ProjectImportProvider... providers) { List<ProjectImportProvider> available = ContainerUtil.filter( providers, new Condition<ProjectImportProvider>() { @Override public boolean value(ProjectImportProvider provider) { return provider.canImport(file, project); } }); if (available.isEmpty()) { Messages.showInfoMessage( project, "Cannot import anything from " + file.getPath(), "Cannot Import"); return null; } String path; if (available.size() == 1) { path = available.get(0).getPathToBeImported(file); } else { path = ProjectImportProvider.getDefaultPath(file); } ProjectImportProvider[] availableProviders = available.toArray(new ProjectImportProvider[available.size()]); return dialogParent == null ? new AddModuleWizard(project, path, availableProviders) : new AddModuleWizard(project, dialogParent, path, availableProviders); }
private static void process( PsiField psiField, Collection<? super RelatedItemLineMarkerInfo> result) { if (!isExtensionPointNameDeclarationField(psiField)) return; final PsiClass epClass = resolveExtensionPointClass(psiField); if (epClass == null) return; final String epName = resolveEpName(psiField); if (epName == null) return; ExtensionPointLocator locator = new ExtensionPointLocator(epClass); List<ExtensionPointCandidate> targets = ContainerUtil.filter( locator.findDirectCandidates(), new Condition<ExtensionPointCandidate>() { @Override public boolean value(ExtensionPointCandidate candidate) { return epName.equals(candidate.epName); } }); final RelatedItemLineMarkerInfo<PsiElement> info = NavigationGutterIconBuilder.create(AllIcons.Nodes.Plugin, CONVERTER, RELATED_ITEM_PROVIDER) .setTargets(targets) .setPopupTitle("Choose Extension Point") .setTooltipText("Extension Point Declaration") .setAlignment(GutterIconRenderer.Alignment.RIGHT) .createLineMarkerInfo(psiField.getNameIdentifier()); result.add(info); }
@Override public void directoryMappingChanged() { GitVcs vcs = GitVcs.getInstance(myProject); if (vcs == null) { return; } final VirtualFile[] roots = myVcsManager.getRootsUnderVcs(vcs); final Collection<VirtualFile> rootsToCheck = ContainerUtil.filter( roots, new Condition<VirtualFile>() { @Override public boolean value(VirtualFile root) { return getUser(root) == null; } }); if (!rootsToCheck.isEmpty()) { ApplicationManager.getApplication() .executeOnPooledThread( new Runnable() { public void run() { for (VirtualFile root : rootsToCheck) { getOrReadUser(root); } } }); } }
public TransferableFileEditorStateSupport( @NotNull DiffSettingsHolder.DiffSettings settings, @NotNull List<BinaryEditorHolder> holders, @NotNull Disposable disposable) { mySettings = settings; myHolders = holders; mySupported = ContainerUtil.or(myHolders, IS_SUPPORTED); new MySynchronizer(ContainerUtil.filter(myHolders, IS_SUPPORTED)).install(disposable); }
private static List<PsiElement> toResult(List<? extends PsiElement> elements) { return ContainerUtil.filter( elements, new Condition<PsiElement>() { @Override public boolean value(PsiElement element) { return element != null; } }); }
@Override public List<Task> getCachedIssues(final boolean withClosed) { return ContainerUtil.filter( myIssueCache.values(), new Condition<Task>() { @Override public boolean value(final Task task) { return withClosed || !task.isClosed(); } }); }
private List<VcsRef> getMatched(@NotNull Collection<VcsRef> refs, @NotNull String prefix) { final PlainPrefixMatcher prefixMatcher = new PlainPrefixMatcher(prefix); return ContainerUtil.filter( refs, new Condition<VcsRef>() { @Override public boolean value(VcsRef vcsRef) { return prefixMatcher.prefixMatches(vcsRef.getName()); } }); }
private static List<MethodContract> filterReturning( List<MethodContract> values, final ValueConstraint result) { return ContainerUtil.filter( values, new Condition<MethodContract>() { @Override public boolean value(MethodContract contract) { return contract.returnValue == result; } }); }
@NotNull private static Collection<CallableMemberDescriptor> retainNonOverridableMembers( @NotNull Collection<? extends CallableMemberDescriptor> callableMemberDescriptors) { return ContainerUtil.filter( callableMemberDescriptors, new Condition<CallableMemberDescriptor>() { @Override public boolean value(CallableMemberDescriptor descriptor) { return !descriptor.getModality().isOverridable(); } }); }
@NotNull private List<VcsRootError> getImportantUnregisteredMappings( @NotNull Collection<VcsRootError> errors) { return ContainerUtil.filter( errors, error -> { String mapping = error.getMapping(); return error.getType() == VcsRootError.Type.UNREGISTERED_ROOT && isUnderOrAboveProjectDir(mapping) && !isIgnoredOrExcluded(mapping); }); }
@NotNull private static List<VcsRef> getUnmatchedHeads( @NotNull final Set<Hash> firstBlockHashes, @NotNull Collection<VcsRef> refs) { return ContainerUtil.filter( refs, new Condition<VcsRef>() { @Override public boolean value(VcsRef ref) { return !firstBlockHashes.contains(ref.getCommitHash()); } }); }
@NotNull private static Collection<VcsRef> getNewTags( @NotNull Set<VcsRef> currentRefs, @NotNull final Set<VcsRef> previousRefs) { return ContainerUtil.filter( currentRefs, new Condition<VcsRef>() { @Override public boolean value(VcsRef ref) { return !ref.getType().isBranch() && !previousRefs.contains(ref); } }); }
public int getVisibleLength(int subtaskIndex) { int minIndex = Collections.min(mySubtaskInfos.keySet()); AnswerPlaceholderSubtaskInfo minInfo = mySubtaskInfos.get(minIndex); if (minIndex == subtaskIndex) { return getUseLength() ? myLength : minInfo.getPossibleAnswer().length(); } if (minIndex > subtaskIndex) { return minInfo.isNeedInsertText() ? 0 : minInfo.getPlaceholderText().length(); } int maxIndex = Collections.max(ContainerUtil.filter(mySubtaskInfos.keySet(), i -> i <= subtaskIndex)); return getUseLength() ? myLength : mySubtaskInfos.get(maxIndex).getPossibleAnswer().length(); }
@NotNull public static List<JetType> getSupertypesWithoutFakes(ClassDescriptor descriptor) { Collection<JetType> supertypes = descriptor.getTypeConstructor().getSupertypes(); return ContainerUtil.filter( supertypes, new Condition<JetType>() { @Override public boolean value(JetType type) { ClassDescriptor classDescriptor = getClassDescriptorForType(type); return !FAKE_CLASSES.contains(getFqNameSafe(classDescriptor).asString()); } }); }
@Override public List<LocalTask> getLocalTasks(final boolean withClosed) { synchronized (myTasks) { return ContainerUtil.filter( myTasks.values(), new Condition<LocalTask>() { @Override public boolean value(final LocalTask task) { return withClosed || !isLocallyClosed(task); } }); } }
@NotNull private static Collection<VcsCommitMetadata> getUnmatchedCommits( @NotNull final Set<Hash> firstBlockHashes, @NotNull List<VcsCommitMetadata> detailsFromTaggedBranches) { return ContainerUtil.filter( detailsFromTaggedBranches, new Condition<VcsCommitMetadata>() { @Override public boolean value(VcsCommitMetadata metadata) { return !firstBlockHashes.contains(metadata.getHash()); } }); }
@NotNull private static Collection<VirtualFile> filterOutIgnored( @NotNull Project project, @NotNull Collection<VirtualFile> files) { final ChangeListManager changeListManager = ChangeListManager.getInstance(project); final FileIndexFacade fileIndex = FileIndexFacade.getInstance(project); return ContainerUtil.filter( files, new Condition<VirtualFile>() { @Override public boolean value(VirtualFile file) { return !changeListManager.isIgnoredFile(file) && !fileIndex.isExcludedFile(file); } }); }
@Nullable private static SearchScope getSelectedFilesScope( final Project project, @Nullable DataContext dataContext) { final VirtualFile[] filesOrDirs = dataContext == null ? null : CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(dataContext); if (filesOrDirs != null) { final List<VirtualFile> selectedFiles = ContainerUtil.filter(filesOrDirs, file -> !file.isDirectory()); if (!selectedFiles.isEmpty()) { return GlobalSearchScope.filesScope(project, selectedFiles, "Selected Files"); } } return null; }
public static void excludePackagesFolders( final Module module, final VirtualFile pubspecYamlFile) { final VirtualFile root = pubspecYamlFile.getParent(); final VirtualFile contentRoot = root == null ? null : ProjectRootManager.getInstance(module.getProject()) .getFileIndex() .getContentRootForFile(root); if (contentRoot == null) return; // http://pub.dartlang.org/doc/glossary.html#entrypoint-directory // Entrypoint directory: A directory inside your package that is allowed to contain Dart // entrypoints. // Pub will ensure all of these directories get a “packages” directory, which is needed for // “package:” imports to work. // Pub has a whitelist of these directories: benchmark, bin, example, test, tool, and web. // Any subdirectories of those (except bin) may also contain entrypoints. // // the same can be seen in the pub tool source code: [repo // root]/sdk/lib/_internal/pub/lib/src/entrypoint.dart final Collection<String> oldExcludedPackagesUrls = ContainerUtil.filter( ModuleRootManager.getInstance(module).getExcludeRootUrls(), new Condition<String>() { final String rootUrlPrefix = root.getUrl() + '/'; public boolean value(final String url) { if (!url.startsWith(rootUrlPrefix)) return false; if (url.endsWith("/packages")) return true; // excluded subfolder of 'packages' folder final int lastSlashIndex = url.lastIndexOf('/'); if (lastSlashIndex > 0 && url.substring(0, lastSlashIndex).endsWith("/packages")) return true; return false; } }); final THashSet<String> newExcludedPackagesUrls = collectFoldersToExclude(module, pubspecYamlFile); if (oldExcludedPackagesUrls.size() != newExcludedPackagesUrls.size() || !newExcludedPackagesUrls.containsAll(oldExcludedPackagesUrls)) { updateExcludedFolders(module, contentRoot, oldExcludedPackagesUrls, newExcludedPackagesUrls); } }
public static <T extends Repository> List<T> sortRepositories( @NotNull Collection<T> repositories) { List<T> validRepositories = ContainerUtil.filter( repositories, new Condition<T>() { @Override public boolean value(T t) { return t.getRoot().isValid(); } }); Collections.sort(validRepositories, REPOSITORY_COMPARATOR); return validRepositories; }
public static List<MavenImporter> getSuitableImporters(MavenProject p) { List<MavenImporter> result = null; Set<ModuleType> moduleTypes = null; for (MavenImporter importer : EXTENSION_POINT_NAME.getExtensions()) { if (importer.isApplicable(p)) { if (result == null) { result = new ArrayList<MavenImporter>(); moduleTypes = new THashSet<ModuleType>(); } result.add(importer); moduleTypes.add(importer.getModuleType()); } } if (result == null) { return Collections.emptyList(); } if (moduleTypes.size() <= 1) { return result; } // This code is reached when several importers say that they are applicable but they want to // have different module types. // Now we select one module type and return only those importers that are ok with it. // If possible - return at least one importer that explicitly supports packaging of the given // maven project. ModuleType moduleType = result.get(0).getModuleType(); List<String> supportedPackagings = new ArrayList<String>(); for (MavenImporter importer : result) { supportedPackagings.clear(); importer.getSupportedPackagings(supportedPackagings); if (supportedPackagings.contains(p.getPackaging())) { moduleType = importer.getModuleType(); break; } } final ModuleType finalModuleType = moduleType; return ContainerUtil.filter( result, new Condition<MavenImporter>() { public boolean value(final MavenImporter importer) { return importer.getModuleType() == finalModuleType; } }); }
public void setUp() throws Exception { super.setUp(); List<VcsLogProvider> providers = ContainerUtil.filter( Extensions.getExtensions(VcsLogManager.LOG_PROVIDER_EP, myProject), new Condition<VcsLogProvider>() { @Override public boolean value(VcsLogProvider provider) { return provider.getSupportedVcs().equals(GitVcs.getKey()); } }); assertEquals("Incorrect number of GitLogProviders", 1, providers.size()); myLogProvider = (GitLogProvider) providers.get(0); myObjectsFactory = ServiceManager.getService(myProject, VcsLogObjectsFactory.class); }
public void testReexportedDependency() { initProject(); addKotlinRuntimeDependency( JpsJavaDependencyScope.COMPILE, ContainerUtil.filter( myProject.getModules(), new Condition<JpsModule>() { @Override public boolean value(JpsModule module) { return module.getName().equals("module2"); } }), true); makeAll().assertSuccessful(); }
Collection<PsiElement> getProblems(final NullabilityProblem kind) { return ContainerUtil.filter( myProblems.get(kind), new Condition<PsiElement>() { @Override public boolean value(PsiElement psiElement) { StateInfo info = myStateInfos.get(Pair.create(kind, psiElement)); // non-ephemeral NPE should be reported // ephemeral NPE should also be reported if only ephemeral states have reached a // particular problematic instruction // (e.g. if it's inside "if (var == null)" check after contract method invocation return info.normalNpe || info.ephemeralNpe && !info.normalOk; } }); }
protected Collection<HighlightInfo> doDoTest( final boolean checkWarnings, final boolean checkInfos, final boolean checkWeakWarnings) { return ContainerUtil.filter( checkHighlighting( new ExpectedHighlightingData( myEditor.getDocument(), checkWarnings, checkWeakWarnings, checkInfos, myFile)), new Condition<HighlightInfo>() { @Override public boolean value(HighlightInfo info) { return info.getSeverity() == HighlightSeverity.INFORMATION && checkInfos || info.getSeverity() == HighlightSeverity.WARNING && checkWarnings || info.getSeverity() == HighlightSeverity.WEAK_WARNING && checkWeakWarnings || info.getSeverity().compareTo(HighlightSeverity.WARNING) > 0; } }); }
static List<? extends LookupElement> wrap( @NotNull LookupElement classItem, @NotNull PsiClass psiClass, @NotNull PsiElement position, @NotNull Supplier<PsiClassType> type) { if (Registry.is("java.completion.show.constructors") && isConstructorCallPlace(position)) { List<PsiMethod> constructors = ContainerUtil.filter( psiClass.getConstructors(), c -> shouldSuggestConstructor(psiClass, position, c)); if (!constructors.isEmpty()) { return ContainerUtil.map( constructors, c -> new JavaConstructorCallElement(classItem, c, type)); } } return Collections.singletonList(classItem); }
@NotNull @Override public Module[] getModules(@NotNull final ProjectData projectData) { final List<Module> modules = ContainerUtil.filter( getModules(), new Condition<Module>() { @Override public boolean value(Module module) { return isExternalSystemAwareModule(projectData.getOwner(), module) && StringUtil.equals( projectData.getLinkedExternalProjectPath(), getExternalRootProjectPath(module)); } }); return ContainerUtil.toArray(modules, new Module[modules.size()]); }
@Nullable public static JetClassOrObject getMainClass(@NotNull JetFile file) { List<JetDeclaration> classes = ContainerUtil.filter( file.getDeclarations(), new Condition<JetDeclaration>() { @Override public boolean value(JetDeclaration jetDeclaration) { return jetDeclaration instanceof JetClassOrObject; } }); if (classes.size() == 1) { if (StringUtil.getPackageName(file.getName()).equals(classes.get(0).getName())) { return (JetClassOrObject) classes.get(0); } } return null; }