com.intellij.openapi.util.Condition Java Examples
The following examples show how to use
com.intellij.openapi.util.Condition.
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: ScheduleForAdditionAction.java From consulo with Apache License 2.0 | 6 votes |
public static boolean addUnversioned(@Nonnull Project project, @Nonnull List<VirtualFile> files, @Nonnull Condition<FileStatus> unversionedFileCondition, @Nullable ChangesBrowserBase browser) { boolean result = true; if (!files.isEmpty()) { FileDocumentManager.getInstance().saveAllDocuments(); @SuppressWarnings("unchecked") Consumer<List<Change>> consumer = browser == null ? null : changes -> { browser.rebuildList(); browser.getViewer().excludeChanges((List)files); browser.getViewer().includeChanges((List)changes); }; ChangeListManagerImpl manager = ChangeListManagerImpl.getInstanceImpl(project); LocalChangeList targetChangeList = browser == null ? manager.getDefaultChangeList() : (LocalChangeList)browser.getSelectedChangeList(); List<VcsException> exceptions = manager.addUnversionedFiles(targetChangeList, files, unversionedFileCondition, consumer); result = exceptions.isEmpty(); } return result; }
Example #2
Source File: CurrentBranchHighlighter.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull @Override public VcsCommitStyle getStyle(@Nonnull VcsShortCommitDetails details, boolean isSelected) { if (isSelected || !myLogUi.isHighlighterEnabled(Factory.ID)) return VcsCommitStyle.DEFAULT; Condition<CommitId> condition = myConditions.get(details.getRoot()); if (condition == null) { VcsLogProvider provider = myLogData.getLogProvider(details.getRoot()); String currentBranch = provider.getCurrentBranch(details.getRoot()); if (!HEAD.equals(mySingleFilteredBranch) && currentBranch != null && !(currentBranch.equals(mySingleFilteredBranch))) { condition = myLogData.getContainingBranchesGetter().getContainedInBranchCondition(currentBranch, details.getRoot()); myConditions.put(details.getRoot(), condition); } else { condition = Conditions.alwaysFalse(); } } if (condition != null && condition.value(new CommitId(details.getId(), details.getRoot()))) { return VcsCommitStyleFactory.background(CURRENT_BRANCH_BG); } return VcsCommitStyle.DEFAULT; }
Example #3
Source File: PathsVerifier.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull public Collection<FilePatch> filterBadFileTypePatches() { List<Pair<VirtualFile, ApplyTextFilePatch>> failedTextPatches = ContainerUtil.findAll(myTextPatches, new Condition<Pair<VirtualFile, ApplyTextFilePatch>>() { @Override public boolean value(Pair<VirtualFile, ApplyTextFilePatch> textPatch) { final VirtualFile file = textPatch.getFirst(); if (file.isDirectory()) return false; return !isFileTypeOk(file); } }); myTextPatches.removeAll(failedTextPatches); return ContainerUtil.map(failedTextPatches, new Function<Pair<VirtualFile, ApplyTextFilePatch>, FilePatch>() { @Override public FilePatch fun(Pair<VirtualFile, ApplyTextFilePatch> patchInfo) { return patchInfo.getSecond().getPatch(); } }); }
Example #4
Source File: PhpElementsUtil.java From Thinkphp5-Plugin with MIT License | 6 votes |
/** * Get array string values mapped with their PsiElements * * ["value", "value2"] */ @NotNull static public Map<String, PsiElement> getArrayValuesAsMap(@NotNull ArrayCreationExpression arrayCreationExpression) { List<PsiElement> arrayValues = PhpPsiUtil.getChildren(arrayCreationExpression, new Condition<PsiElement>() { @Override public boolean value(PsiElement psiElement) { return psiElement.getNode().getElementType() == PhpElementTypes.ARRAY_VALUE; } }); Map<String, PsiElement> keys = new HashMap<String, PsiElement>(); for (PsiElement child : arrayValues) { String stringValue = PhpElementsUtil.getStringValue(child.getFirstChild()); if(stringValue != null && StringUtils.isNotBlank(stringValue)) { keys.put(stringValue, child); } } return keys; }
Example #5
Source File: DvcsTaskHandler.java From consulo with Apache License 2.0 | 6 votes |
@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: FilteredTraverserBase.java From consulo with Apache License 2.0 | 6 votes |
private Condition<? super T> buildExpandConditionForChildren(T parent) { // implements: or2(forceExpandAndSkip, not(childFilter)); // and handles JBIterable.StatefulTransform and EdgeFilter conditions Cond copy = null; boolean invert = true; Cond c = regard; while (c != null) { Condition impl = JBIterable.Stateful.copy(c.impl); if (impl != (invert ? Condition.TRUE : Condition.FALSE)) { copy = new Cond<Object>(invert ? not(impl) : impl, copy); if (impl instanceof EdgeFilter) { ((EdgeFilter)impl).edgeSource = parent; } } if (c.next == null) { c = invert ? forceDisregard : null; invert = false; } else { c = c.next; } } return copy == null ? Condition.FALSE : copy.OR; }
Example #7
Source File: HaxeGotoSuperHandler.java From intellij-haxe with Apache License 2.0 | 6 votes |
private static void tryNavigateToSuperMethod(Editor editor, HaxeMethod methodDeclaration, List<HaxeNamedComponent> superItems) { final String methodName = methodDeclaration.getName(); if (methodName == null) { return; } final List<HaxeNamedComponent> filteredSuperItems = ContainerUtil.filter(superItems, new Condition<HaxeNamedComponent>() { @Override public boolean value(HaxeNamedComponent component) { return methodName.equals(component.getName()); } }); if (!filteredSuperItems.isEmpty()) { PsiElementListNavigator.openTargets(editor, HaxeResolveUtil.getComponentNames(filteredSuperItems) .toArray(new NavigatablePsiElement[filteredSuperItems.size()]), DaemonBundle.message("navigation.title.super.method", methodName), null, new DefaultPsiElementCellRenderer()); } }
Example #8
Source File: VcsHelper.java From azure-devops-intellij with MIT License | 6 votes |
/** * Use this method to check if the given project is a VSTS/TFS project * * @param project * @return */ public static boolean isVstsRepo(final Project project) { if (project != null) { if (isTfVcs(project)) { return true; } if (!isGitVcs(project)) { return false; } return ContainerUtil.exists(GitUtil.getRepositoryManager(project).getRepositories(), new Condition<GitRepository>() { @Override public boolean value(GitRepository gitRepository) { return TfGitHelper.isTfGitRepository(gitRepository); } }); } return false; }
Example #9
Source File: QuickEditAction.java From consulo with Apache License 2.0 | 6 votes |
@Nullable protected Pair<PsiElement, TextRange> getRangePair(final PsiFile file, final Editor editor) { final int offset = editor.getCaretModel().getOffset(); final PsiLanguageInjectionHost host = PsiTreeUtil.getParentOfType(file.findElementAt(offset), PsiLanguageInjectionHost.class, false); if (host == null || ElementManipulators.getManipulator(host) == null) return null; final List<Pair<PsiElement, TextRange>> injections = InjectedLanguageManager.getInstance(host.getProject()).getInjectedPsiFiles(host); if (injections == null || injections.isEmpty()) return null; final int offsetInElement = offset - host.getTextRange().getStartOffset(); final Pair<PsiElement, TextRange> rangePair = ContainerUtil.find(injections, new Condition<Pair<PsiElement, TextRange>>() { @Override public boolean value(final Pair<PsiElement, TextRange> pair) { return pair.second.containsRange(offsetInElement, offsetInElement); } }); if (rangePair != null) { final Language language = rangePair.first.getContainingFile().getLanguage(); final Object action = language.getUserData(EDIT_ACTION_AVAILABLE); if (action != null && action.equals(false)) return null; myLastLanguageName = language.getDisplayName(); } return rangePair; }
Example #10
Source File: AbstractHaxePsiClass.java From intellij-haxe with Apache License 2.0 | 6 votes |
@Nullable @Override public HaxeNamedComponent findArrayAccessGetter() { HaxeNamedComponent accessor = ContainerUtil.find(getHaxeMethods(), new Condition<HaxeNamedComponent>() { @Override public boolean value(HaxeNamedComponent component) { if (component instanceof HaxeMethod) { HaxeMethodModel model = ((HaxeMethod)component).getModel(); return model != null && model.isArrayAccessor() && model.getParameterCount() == 1; } return false; } }); // Maybe old style getter? if (null == accessor) { accessor = findHaxeMethodByName("__get"); } return accessor; }
Example #11
Source File: PopupFactoryImpl.java From consulo with Apache License 2.0 | 6 votes |
public ActionGroupPopup(String title, @Nonnull ActionGroup actionGroup, @Nonnull DataContext dataContext, boolean showNumbers, boolean useAlphaAsNumbers, boolean showDisabledActions, boolean honorActionMnemonics, Runnable disposeCallback, int maxRowCount, Condition<? super AnAction> preselectActionCondition, @Nullable final String actionPlace, @Nullable PresentationFactory presentationFactory, boolean autoSelection) { this(null, createStep(title, actionGroup, dataContext, showNumbers, useAlphaAsNumbers, showDisabledActions, honorActionMnemonics, preselectActionCondition, actionPlace, presentationFactory, autoSelection), disposeCallback, dataContext, actionPlace, maxRowCount); }
Example #12
Source File: ActionPopupStep.java From consulo with Apache License 2.0 | 6 votes |
public ActionPopupStep(@Nonnull List<PopupFactoryImpl.ActionItem> items, String title, @Nonnull Supplier<? extends DataContext> context, @Nullable String actionPlace, boolean enableMnemonics, @Nullable Condition<? super AnAction> preselectActionCondition, boolean autoSelection, boolean showDisabledActions, @Nullable PresentationFactory presentationFactory) { myItems = items; myTitle = title; myContext = context; myActionPlace = ObjectUtils.notNull(actionPlace, ActionPlaces.UNKNOWN); myEnableMnemonics = enableMnemonics; myPresentationFactory = presentationFactory; myDefaultOptionIndex = getDefaultOptionIndexFromSelectCondition(preselectActionCondition, items); myPreselectActionCondition = preselectActionCondition; myAutoSelectionEnabled = autoSelection; myShowDisabledActions = showDisabledActions; }
Example #13
Source File: ActionPopupStep.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull public static ListPopupStep<PopupFactoryImpl.ActionItem> createActionsStep(@Nonnull ActionGroup actionGroup, @Nonnull DataContext dataContext, boolean showNumbers, boolean useAlphaAsNumbers, boolean showDisabledActions, String title, boolean honorActionMnemonics, boolean autoSelectionEnabled, Supplier<? extends DataContext> contextSupplier, @Nullable String actionPlace, Condition<? super AnAction> preselectCondition, int defaultOptionIndex, @Nullable PresentationFactory presentationFactory) { List<PopupFactoryImpl.ActionItem> items = createActionItems(actionGroup, dataContext, showNumbers, useAlphaAsNumbers, showDisabledActions, honorActionMnemonics, actionPlace, presentationFactory); boolean enableMnemonics = showNumbers || honorActionMnemonics && items.stream().anyMatch(actionItem -> actionItem.getAction().getTemplatePresentation().getMnemonic() != 0); return new ActionPopupStep(items, title, contextSupplier, actionPlace, enableMnemonics, preselectCondition != null ? preselectCondition : action -> defaultOptionIndex >= 0 && defaultOptionIndex < items.size() && items.get(defaultOptionIndex).getAction().equals(action), autoSelectionEnabled, showDisabledActions, presentationFactory); }
Example #14
Source File: DustTypedHandler.java From Intellij-Dust with MIT License | 6 votes |
/** * When appropriate, automatically reduce the indentation for else tags "{:else}" */ private void adjustFormatting(Project project, int offset, Editor editor, PsiFile file, FileViewProvider provider) { PsiElement elementAtCaret = provider.findElementAt(offset - 1, DustLanguage.class); PsiElement elseParent = PsiTreeUtil.findFirstParent(elementAtCaret, true, new Condition<PsiElement>() { @Override public boolean value(PsiElement element) { return element != null && (element instanceof DustElseTag); } }); // run the formatter if the user just completed typing a SIMPLE_INVERSE or a CLOSE_BLOCK_STACHE if (elseParent != null) { // grab the current caret position (AutoIndentLinesHandler is about to mess with it) PsiDocumentManager.getInstance(project).commitAllDocuments(); CaretModel caretModel = editor.getCaretModel(); CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(project); codeStyleManager.adjustLineIndent(file, editor.getDocument().getLineStartOffset(caretModel.getLogicalPosition().line)); } }
Example #15
Source File: VcsLogStorageImpl.java From consulo with Apache License 2.0 | 6 votes |
@Override @Nullable public CommitId findCommitId(@Nonnull final Condition<CommitId> condition) { checkDisposed(); try { final Ref<CommitId> hashRef = Ref.create(); myCommitIdEnumerator.iterateData(new CommonProcessors.FindProcessor<CommitId>() { @Override protected boolean accept(CommitId commitId) { boolean matches = condition.value(commitId); if (matches) { hashRef.set(commitId); } return matches; } }); return hashRef.get(); } catch (IOException e) { myExceptionReporter.consume(this, e); return null; } }
Example #16
Source File: ToolWindowEP.java From consulo with Apache License 2.0 | 5 votes |
@Nullable public Condition<Project> getCondition() { if (conditionClass != null) { try { return instantiate(conditionClass, Application.get().getInjectingContainer()); } catch (Exception e) { LOG.error(e); } } return null; }
Example #17
Source File: HaxeParameterInfoHandler.java From intellij-haxe with Apache License 2.0 | 5 votes |
private HaxeExpression getExpressionAtPlace(@NotNull PsiElement place, final List<HaxeExpression> expressionList) { return (HaxeExpression)PsiTreeUtil.findFirstParent(place, new Condition<PsiElement>() { @Override public boolean value(PsiElement element) { return element instanceof HaxeExpression && expressionList.indexOf(element) >= 0; } }); }
Example #18
Source File: Determiner.java From intellij-xquery with Apache License 2.0 | 5 votes |
public boolean hasDuplicateDeclarationInTheSameFile(XQueryFunctionName functionName, XQueryFile file) { boolean result = false; if (functionName.getParent() instanceof XQueryFunctionDecl) { final XQueryFunctionDecl functionDeclaration = (XQueryFunctionDecl) functionName.getParent(); Collection<XQueryFunctionDecl> filteredDeclarations = filter(file.getFunctionDeclarations(), new Condition<XQueryFunctionDecl>() { @Override public boolean value(XQueryFunctionDecl otherFunctionDeclaration) { return functionDeclaration != otherFunctionDeclaration; } }); result = hasDuplicate(functionName, filteredDeclarations); } return result; }
Example #19
Source File: DvcsUtil.java From consulo with Apache License 2.0 | 5 votes |
@javax.annotation.Nullable public static PushSupport getPushSupport(@Nonnull final AbstractVcs vcs) { return ContainerUtil.find(Extensions.getExtensions(PushSupport.PUSH_SUPPORT_EP, vcs.getProject()), new Condition<PushSupport>() { @Override public boolean value(final PushSupport support) { return support.getVcs().equals(vcs); } }); }
Example #20
Source File: ShowDiffAction.java From consulo with Apache License 2.0 | 5 votes |
public static void showDiffForChange(@Nullable Project project, @Nonnull Iterable<Change> changes, @Nonnull Condition<Change> condition, @Nonnull ShowDiffContext context) { int index = 0; List<ChangeDiffRequestProducer> presentables = new ArrayList<>(); for (Change change : changes) { if (condition.value(change)) index = presentables.size(); ChangeDiffRequestProducer presentable = ChangeDiffRequestProducer.create(project, change, context.getChangeContext(change)); if (presentable != null) presentables.add(presentable); } showDiffForChange(project, presentables, index, context); }
Example #21
Source File: CollapsedActionManager.java From consulo with Apache License 2.0 | 5 votes |
private FragmentGenerators(@Nonnull final LinearGraph linearGraph, @Nonnull PermanentGraphInfo<?> permanentGraphInfo, @Nonnull final UnsignedBitSet matchedNodeId) { fragmentGenerator = new FragmentGenerator(LinearGraphUtils.asLiteLinearGraph(linearGraph), new Condition<Integer>() { @Override public boolean value(Integer nodeIndex) { return matchedNodeId.get(linearGraph.getNodeId(nodeIndex)); } }); Set<Integer> branchNodeIndexes = LinearGraphUtils.convertIdsToNodeIndexes(linearGraph, permanentGraphInfo.getBranchNodeIds()); linearFragmentGenerator = new LinearFragmentGenerator(LinearGraphUtils.asLiteLinearGraph(linearGraph), branchNodeIndexes); }
Example #22
Source File: PushController.java From consulo with Apache License 2.0 | 5 votes |
private boolean isSyncStrategiesAllowed() { return !mySingleRepoProject && ContainerUtil.and(getAffectedSupports(), new Condition<PushSupport<Repository, PushSource, PushTarget>>() { @Override public boolean value(PushSupport<Repository, PushSource, PushTarget> support) { return support.mayChangeTargetsSync(); } }); }
Example #23
Source File: BaseProjectTreeBuilder.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull private Promise<Object> _select(final Object element, final VirtualFile file, final boolean requestFocus, final Condition<? super AbstractTreeNode> nonStopCondition) { AbstractTreeUpdater updater = getUpdater(); if (updater == null) { return Promises.rejectedPromise(); } final AsyncPromise<Object> result = new AsyncPromise<>(); UiActivityMonitor.getInstance().addActivity(myProject, new UiActivity.AsyncBgOperation("projectViewSelect"), updater.getModalityState()); batch(indicator -> { _select(element, file, requestFocus, nonStopCondition, result, indicator, null, null, false); UiActivityMonitor.getInstance().removeActivity(myProject, new UiActivity.AsyncBgOperation("projectViewSelect")); }); return result; }
Example #24
Source File: WeaksTestCase.java From consulo with Apache License 2.0 | 5 votes |
private static void waitFor(final Condition<Void> condition) { new WaitFor(10000) { @Override protected boolean condition() { gc(); return condition.value(null); } }.assertCompleted(condition.toString()); }
Example #25
Source File: AnnotateVcsVirtualFileAction.java From consulo with Apache License 2.0 | 5 votes |
private static boolean isAnnotated(AnActionEvent e) { Project project = e.getRequiredData(CommonDataKeys.PROJECT); VirtualFile file = e.getRequiredData(CommonDataKeys.VIRTUAL_FILE_ARRAY)[0]; List<Editor> editors = VcsAnnotateUtil.getEditors(project, file); return ContainerUtil.exists(editors, new Condition<Editor>() { @Override public boolean value(Editor editor) { return editor.getGutter().isAnnotationsShown(); } }); }
Example #26
Source File: PushSettings.java From consulo with Apache License 2.0 | 5 votes |
public boolean containsForcePushTarget(@Nonnull final String remote, @Nonnull final String branch) { return ContainerUtil.exists(myState.FORCE_PUSH_TARGETS, new Condition<ForcePushTargetInfo>() { @Override public boolean value(ForcePushTargetInfo info) { return info.targetRemoteName.equals(remote) && info.targetBranchName.equals(branch); } }); }
Example #27
Source File: JSBinaryExpressionUtil.java From eslint-plugin with MIT License | 5 votes |
public static ASTNode getOperator(PsiElement element) { PsiElement binary = PsiTreeUtil.findFirstParent(element, new Condition<PsiElement>() { @Override public boolean value(PsiElement psiElement) { return psiElement instanceof JSBinaryExpression; } }); return binary == null ? null : binary.getNode().getChildren(BINARY_OPERATIONS)[0]; }
Example #28
Source File: PantsUtil.java From intellij-pants-plugin with Apache License 2.0 | 5 votes |
public static <K, V> Map<K, V> filterByValue(Map<K, V> map, Condition<V> condition) { final Map<K, V> result = new HashMap<>(map.size()); for (Map.Entry<K, V> entry : map.entrySet()) { final K key = entry.getKey(); final V value = entry.getValue(); if (condition.value(value)) { result.put(key, value); } } return result; }
Example #29
Source File: PantsUtil.java From intellij-pants-plugin with Apache License 2.0 | 5 votes |
public static Optional<VirtualFile> findPexVersionFile(@NotNull VirtualFile folderWithPex, @NotNull String pantsVersion) { final String filePrefix = "pants-" + pantsVersion; return Optional.ofNullable(ContainerUtil.find( folderWithPex.getChildren(), new Condition<VirtualFile>() { @Override public boolean value(VirtualFile virtualFile) { return "pex".equalsIgnoreCase(virtualFile.getExtension()) && virtualFile.getName().startsWith(filePrefix); } } )); }
Example #30
Source File: NMEBuildDirectoryInspection.java From intellij-haxe with Apache License 2.0 | 5 votes |
@Override public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) { final boolean isNmml = FileUtilRt.extensionEquals(file.getName(), NMMLFileType.DEFAULT_EXTENSION); if (!isNmml || !(file instanceof XmlFile)) { return ProblemDescriptor.EMPTY_ARRAY; } MyVisitor visitor = new MyVisitor(); file.accept(visitor); if (ContainerUtil.exists(visitor.getResult(), new Condition<XmlTag>() { @Override public boolean value(XmlTag tag) { final XmlAttribute ifAttribute = tag.getAttribute("if"); return "debug".equals(ifAttribute != null ? ifAttribute.getValue() : null); } })) { // all good return ProblemDescriptor.EMPTY_ARRAY; } final XmlTag lastTag = ContainerUtil.iterateAndGetLastItem(visitor.getResult()); if (lastTag == null) { return ProblemDescriptor.EMPTY_ARRAY; } final ProblemDescriptor descriptor = manager.createProblemDescriptor( lastTag, HaxeBundle.message("haxe.inspections.nme.build.directory.descriptor"), new AddTagFix(), ProblemHighlightType.GENERIC_ERROR_OR_WARNING, isOnTheFly ); return new ProblemDescriptor[]{descriptor}; }