Java Code Examples for com.intellij.util.Function#fun()
The following examples show how to use
com.intellij.util.Function#fun() .
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: DesktopIconDeferrerImpl.java From consulo with Apache License 2.0 | 6 votes |
private <T> Image deferImpl(Image base, T param, @Nonnull Function<T, Image> evaluator, final boolean autoUpdatable) { if (ourEvaluationIsInProgress.get()) { return evaluator.fun(param); } synchronized (LOCK) { Image result = myIconsCache.get(param); if (result == null) { final long started = myLastClearTimestamp; result = new DesktopDeferredIconImpl<>(base, param, evaluator, (DesktopDeferredIconImpl<T> source, T key, Image r) -> { synchronized (LOCK) { // check if our results is not outdated yet if (started == myLastClearTimestamp) { myIconsCache.put(key, autoUpdatable ? source : r); } } }, autoUpdatable); myIconsCache.put(param, result); } return result; } }
Example 2
Source File: ConcurrentFactoryMap.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull public static <K, V> ConcurrentMap<K, V> create(@Nonnull Function<? super K, ? extends V> computeValue, @Nonnull Supplier<? extends ConcurrentMap<K, V>> mapCreator) { return new ConcurrentFactoryMap<K, V>() { @Nullable @Override protected V create(K key) { return computeValue.fun(key); } @Nonnull @Override protected ConcurrentMap<K, V> createMap() { return mapCreator.get(); } }; }
Example 3
Source File: FileReferenceSet.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull public Collection<PsiFileSystemItem> computeDefaultContexts() { final PsiFile file = getContainingFile(); if (file == null) return Collections.emptyList(); if (myOptions != null) { final Function<PsiFile, Collection<PsiFileSystemItem>> value = DEFAULT_PATH_EVALUATOR_OPTION.getValue(myOptions); if (value != null) { final Collection<PsiFileSystemItem> roots = value.fun(file); if (roots != null) { for (PsiFileSystemItem root : roots) { if (root == null) { LOG.error("Default path evaluator " + value + " produced a null root for " + file); } } return roots; } } } if (isAbsolutePathReference()) { return getAbsoluteTopLevelDirLocations(file); } return getContextByFile(file); }
Example 4
Source File: UpdaterTreeState.java From consulo with Apache License 2.0 | 6 votes |
private void processUnsuccessfulSelections(final Object[] toSelect, Function<Object, Object> restore, Set<Object> originallySelected) { final Set<Object> selected = myUi.getSelectedElements(); boolean wasFullyRejected = false; if (toSelect.length > 0 && !selected.isEmpty() && !originallySelected.containsAll(selected)) { final Set<Object> successfulSelections = new HashSet<>(); ContainerUtil.addAll(successfulSelections, toSelect); successfulSelections.retainAll(selected); wasFullyRejected = successfulSelections.isEmpty(); } else if (selected.isEmpty() && originallySelected.isEmpty()) { wasFullyRejected = true; } if (wasFullyRejected && !selected.isEmpty()) return; for (Object eachToSelect : toSelect) { if (!selected.contains(eachToSelect)) { restore.fun(eachToSelect); } } }
Example 5
Source File: MergeUtil.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull public static String getResolveActionTitle(@Nonnull MergeResult result, @Nonnull MergeRequest request, @Nonnull MergeContext context) { Function<MergeResult, String> getter = DiffUtil.getUserData(request, context, DiffUserDataKeysEx.MERGE_ACTION_CAPTIONS); String message = getter != null ? getter.fun(result) : null; if (message != null) return message; switch (result) { case CANCEL: return "Abort"; case LEFT: return "Accept Left"; case RIGHT: return "Accept Right"; case RESOLVED: return "Apply"; default: throw new IllegalArgumentException(result.toString()); } }
Example 6
Source File: PathReference.java From consulo with Apache License 2.0 | 5 votes |
public PathReference(@Nonnull String path, final @Nonnull Function<PathReference, Icon> icon) { myPath = path; myIcon = new NullableLazyValue<Icon>() { @Override protected Icon compute() { return icon.fun(PathReference.this); } }; }
Example 7
Source File: IntelliJEditorTabsUI.java From consulo with Apache License 2.0 | 5 votes |
protected Dimension computeSize(JBTabsImpl tabs, Function<JComponent, Dimension> transform, int tabCount) { Dimension size = new Dimension(); for (TabInfo each : tabs.getVisibleInfos()) { final JComponent c = each.getComponent(); if (c != null) { final Dimension eachSize = transform.fun(c); size.width = Math.max(eachSize.width, size.width); size.height = Math.max(eachSize.height, size.height); } } addHeaderSize(tabs, size, tabCount); return size; }
Example 8
Source File: CompositeException.java From consulo with Apache License 2.0 | 5 votes |
private String processAll(Function<Throwable, String> exceptionProcessor, Processor<String> stringProcessor) { if (myExceptions.size() == 1) { Throwable throwable = myExceptions.get(0); String s = exceptionProcessor.fun(throwable); stringProcessor.process(s); return s; } StringBuilder sb = new StringBuilder(); String line = "CompositeException ("+myExceptions.size() +" nested):\n------------------------------\n"; stringProcessor.process(line); sb.append(line); for (int i = 0; i < myExceptions.size(); i++) { Throwable exception = myExceptions.get(i); line = "[" + i + "]: "; stringProcessor.process(line); sb.append(line); line = StringUtil.notNullize(exceptionProcessor.fun(exception)); if (!line.endsWith("\n")) line += '\n'; stringProcessor.process(line); sb.append(line); } line = "------------------------------\n"; stringProcessor.process(line); sb.append(line); return sb.toString(); }
Example 9
Source File: ProjectViewTestUtil.java From consulo with Apache License 2.0 | 5 votes |
public static VirtualFile[] getFiles(AbstractTreeNode kid, Function<AbstractTreeNode, VirtualFile[]> converterFunction) { if (kid instanceof BasePsiNode) { Object value = kid.getValue(); VirtualFile virtualFile = PsiUtilBase.getVirtualFile((PsiElement)value); return new VirtualFile[]{virtualFile}; } if (converterFunction != null) { final VirtualFile[] result = converterFunction.fun(kid); if (result != null) { return result; } } return new VirtualFile[0]; }
Example 10
Source File: Messages.java From consulo with Apache License 2.0 | 5 votes |
/** * Shows dialog with text area to edit long strings that don't fit in text field. */ public static void showTextAreaDialog(final JTextField textField, final String title, @NonNls final String dimensionServiceKey, final Function<String, List<String>> parser, final Function<List<String>, String> lineJoiner) { if (isApplicationInUnitTestOrHeadless()) { ourTestImplementation.show(title); } else { final JTextArea textArea = new JTextArea(10, 50); textArea.setWrapStyleWord(true); textArea.setLineWrap(true); List<String> lines = parser.fun(textField.getText()); textArea.setText(StringUtil.join(lines, "\n")); InsertPathAction.copyFromTo(textField, textArea); final DialogBuilder builder = new DialogBuilder(textField); builder.setDimensionServiceKey(dimensionServiceKey); builder.setCenterPanel(ScrollPaneFactory.createScrollPane(textArea)); builder.setPreferredFocusComponent(textArea); String rawText = title; if (StringUtil.endsWithChar(rawText, ':')) { rawText = rawText.substring(0, rawText.length() - 1); } builder.setTitle(rawText); builder.addOkAction(); builder.addCancelAction(); builder.setOkOperation(new Runnable() { @Override public void run() { textField.setText(lineJoiner.fun(Arrays.asList(StringUtil.splitByLines(textArea.getText())))); builder.getDialogWrapper().close(DialogWrapper.OK_EXIT_CODE); } }); builder.addDisposable(new TextComponentUndoProvider(textArea)); builder.show(); } }
Example 11
Source File: ConcurrentFactoryMap.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull public static <T, V> ConcurrentMap<T, V> createMap(@Nonnull final Function<? super T, ? extends V> computeValue) { return new ConcurrentFactoryMap<T, V>() { @Nullable @Override protected V create(T key) { return computeValue.fun(key); } }; }
Example 12
Source File: ExcludingTraversalPolicy.java From consulo with Apache License 2.0 | 5 votes |
private Component traverse(Container aContainer, Component aComponent, Function<Pair<Container, Component>, Component> func) { Set<Component> loopGuard = new THashSet<Component>(); do { if (!loopGuard.add(aComponent)) return null; aComponent = func.fun(Pair.create(aContainer, aComponent)); } while (aComponent != null && myExcludes.contains(aComponent)); return aComponent; }
Example 13
Source File: ExpandableTextField.java From consulo with Apache License 2.0 | 5 votes |
/** * Creates an expandable text field with the specified line parser/joiner. * * @see ParametersListUtil */ public ExpandableTextField(@Nonnull Function<? super String, ? extends List<String>> parser, @Nonnull Function<? super List<String>, String> joiner) { Function<? super String, String> onShow = text -> StringUtil.join(parser.fun(text), "\n"); Function<? super String, String> onHide = text -> joiner.fun(asList(StringUtil.splitByLines(text))); support = new IntelliJExpandableSupport<JTextComponent>(this, onShow, onHide); putClientProperty("monospaced", true); setExtensions(createExtensions()); }
Example 14
Source File: DesktopToolWindowContentUi.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull private Dimension calcSize(Container target, Function<Component, Dimension> dimensionSupplier) { synchronized (target.getTreeLock()) { Dimension dim = new Dimension(0, 0); int nmembers = target.getComponentCount(); boolean firstVisibleComponent = true; boolean useBaseline = getAlignOnBaseline(); int maxAscent = 0; int maxDescent = 0; for (int i = 0; i < nmembers; i++) { Component m = target.getComponent(i); if (m.isVisible()) { Dimension d = dimensionSupplier.fun(m); dim.height = Math.max(dim.height, d.height); if (firstVisibleComponent) { firstVisibleComponent = false; } else { dim.width += 0; } dim.width += d.width; if (useBaseline) { int baseline = m.getBaseline(d.width, d.height); if (baseline >= 0) { maxAscent = Math.max(maxAscent, baseline); maxDescent = Math.max(maxDescent, d.height - baseline); } } } } if (useBaseline) { dim.height = Math.max(maxAscent + maxDescent, dim.height); } Insets insets = target.getInsets(); dim.width += insets.left + insets.right; dim.height += insets.top + insets.bottom + 5 * 2; return dim; } }
Example 15
Source File: ExpandableTextField.java From consulo with Apache License 2.0 | 5 votes |
public ExpandableTextField(@Nonnull Function<? super String, ? extends List<String>> parser, @Nonnull Function<? super List<String>, String> joiner, SupportTextBoxWithExpandActionExtender lookAndFeel) { Function<? super String, String> onShow = text -> StringUtil.join(parser.fun(text), "\n"); Function<? super String, String> onHide = text -> joiner.fun(asList(StringUtil.splitByLines(text))); support = lookAndFeel.createExpandableSupport(this, onShow, onHide); putClientProperty("monospaced", true); setExtensions(createExtensions()); }
Example 16
Source File: LinearFragmentGenerator.java From consulo with Apache License 2.0 | 4 votes |
@Nullable private static GraphFragment getFragment(int startNode, Function<Integer, List<Integer>> getNextNodes, Function<Integer, List<Integer>> getPrevNodes, Set<Integer> thisNodeCantBeInMiddle, boolean isDown) { Set<Integer> blackNodes = new HashSet<>(); blackNodes.add(startNode); Set<Integer> grayNodes = new HashSet<>(); grayNodes.addAll(getNextNodes.fun(startNode)); int endNode = -1; while (blackNodes.size() < SHORT_FRAGMENT_MAX_SIZE) { int nextBlackNode = -1; for (int grayNode : grayNodes) { if (blackNodes.containsAll(getPrevNodes.fun(grayNode))) { nextBlackNode = grayNode; break; } } if (nextBlackNode == -1) return null; if (grayNodes.size() == 1) { endNode = nextBlackNode; break; } List<Integer> nextGrayNodes = getNextNodes.fun(nextBlackNode); if (nextGrayNodes.isEmpty() || thisNodeCantBeInMiddle.contains(nextBlackNode)) return null; blackNodes.add(nextBlackNode); grayNodes.remove(nextBlackNode); grayNodes.addAll(nextGrayNodes); } if (endNode != -1) { return isDown ? GraphFragment.create(startNode, endNode) : GraphFragment.create(endNode, startNode); } else { return null; } }
Example 17
Source File: ParameterInfoComponent.java From consulo with Apache License 2.0 | 4 votes |
private String escapeString(String line, Function<? super String, String> escapeFunction) { line = XmlStringUtil.escapeString(line); return escapeFunction == null ? line : escapeFunction.fun(line); }
Example 18
Source File: DummyIconDeferrer.java From consulo with Apache License 2.0 | 4 votes |
@Override public <T> Image defer(Image base, T param, @Nonnull Function<T, Image> f) { return f.fun(param); }
Example 19
Source File: DummyIconDeferrer.java From consulo with Apache License 2.0 | 4 votes |
@Override public <T> Image deferAutoUpdatable(Image base, T param, @Nonnull Function<T, Image> f) { return f.fun(param); }
Example 20
Source File: TreeVisitor.java From consulo with Apache License 2.0 | 4 votes |
public ByTreePath(boolean ignoreRoot, @Nonnull TreePath path, @Nonnull Function<Object, ? extends T> converter) { this.converter = currentPath -> converter.fun(currentPath.getLastPathComponent()); this.ignoreRoot = ignoreRoot; this.path = path; this.count = ignoreRoot ? path.getPathCount() + 1 : path.getPathCount(); }