/** * Iterates over each navigation element for the PsiElements in {@code psiElementCollection}. * * @param psiElementCollection Collection of PsiElements that aren't guaranteed to be navigation elements, such as * the binary elements in {@code .beam} files. * @param function Return {@code false} to stop processing and abandon enumeration early * @return {@code true} if all calls to {@code function} returned {@code true} */ private static boolean forEachNavigationElement(@NotNull Collection<? extends PsiElement> psiElementCollection, @NotNull Function<PsiElement, Boolean> function) { boolean keepProcessing = true; for (PsiElement psiElement : psiElementCollection) { /* The psiElement may be a ModuleImpl from a .beam. Using #getNaviationElement() ensures a source (either true source or decompiled) is used. */ keepProcessing = function.fun(psiElement.getNavigationElement()); if (!keepProcessing) { break; } } return keepProcessing; }
/** * Creates a list of parameter presentations. For clarity we expand parameters declared as `a, b, c int` into `a int, b int, c int`. */ @NotNull public static List<String> getParameterPresentations(@NotNull GoParameters parameters, @NotNull Function<PsiElement, String> typePresentationFunction) { List<GoParameterDeclaration> paramDeclarations = parameters.getParameterDeclarationList(); List<String> paramPresentations = ContainerUtil.newArrayListWithCapacity(2 * paramDeclarations.size()); for (GoParameterDeclaration paramDeclaration : paramDeclarations) { boolean isVariadic = paramDeclaration.isVariadic(); List<GoParamDefinition> paramDefinitionList = paramDeclaration.getParamDefinitionList(); for (GoParamDefinition paramDefinition : paramDefinitionList) { String separator = isVariadic ? " ..." : " "; paramPresentations.add(paramDefinition.getText() + separator + typePresentationFunction.fun(paramDeclaration.getType())); } if (paramDefinitionList.isEmpty()) { String separator = isVariadic ? "..." : ""; paramPresentations.add(separator + typePresentationFunction.fun(paramDeclaration.getType())); } } return paramPresentations; }
@Nullable public static <T> T transformStdoutLine(@NotNull com.intellij.execution.process.ProcessOutput output, @NotNull Function<String, T> lineTransformer) { List<String> lines; if (output.getExitCode() != 0 || output.isTimeout() || output.isCancelled()) { lines = ContainerUtil.emptyList(); } else { lines = output.getStdoutLines(); } T transformed = null; for (String line : lines) { transformed = lineTransformer.fun(line); if (transformed != null) { break; } } return transformed; }
String correspondingCanonicalName = correspondingName.fun(canonicalName);
return presentationFunction.fun(element);
public void setItems(final List<T> items, @Nullable Function<T, String> converter) { clear(); for (T item : items) { String text = converter != null ? converter.fun(item) : item.toString(); addItem(item, text, false); } }
@Override public U next() { return mapper.fun(iterator.next()); }
@NotNull public static <K,V> V[] convert(@NotNull K[] from, @NotNull V[] to, @NotNull Function<K,V> fun) { if (to.length < from.length) { @SuppressWarnings("unchecked") V[] array = (V[])Array.newInstance(to.getClass().getComponentType(), from.length); to = array; } for (int i = 0; i < from.length; i++) { to[i] = fun.fun(from[i]); } return to; }
/** * @return read-only set consisting of the elements from collection converted by mapper */ @NotNull @Contract(pure=true) public static <T, V> Set<V> map2Set(@NotNull Collection<? extends T> collection, @NotNull Function<T, V> mapper) { if (collection.isEmpty()) return Collections.emptySet(); Set <V> set = new HashSet<V>(collection.size()); for (final T t : collection) { set.add(mapper.fun(t)); } return set; }
/** * @return read-only list consisting of the lists (made by listGenerator) added together */ @NotNull @Contract(pure=true) public static <T, V> List<T> concat(@NotNull Iterable<? extends V> list, @NotNull Function<V, Collection<? extends T>> listGenerator) { List<T> result = new ArrayList<T>(); for (final V v : list) { result.addAll(listGenerator.fun(v)); } return result.isEmpty() ? ContainerUtil.<T>emptyList() : result; }
/** * @return read-only list consisting of the elements from the iterable converted by mapping */ @NotNull @Contract(pure=true) public static <T,V> List<V> map(@NotNull Iterable<? extends T> iterable, @NotNull Function<T, V> mapping) { List<V> result = new ArrayList<V>(); for (T t : iterable) { result.add(mapping.fun(t)); } return result.isEmpty() ? ContainerUtil.<V>emptyList() : result; }
/** * @return read-only list consisting of the elements from the array converted by mapping */ @NotNull @Contract(pure=true) public static <T, V> List<V> map(@NotNull T[] array, @NotNull Function<T, V> mapping) { List<V> result = new ArrayList<V>(array.length); for (T t : array) { result.add(mapping.fun(t)); } return result.isEmpty() ? ContainerUtil.<V>emptyList() : result; }
/** * @return read-only list consisting of the elements from the iterable converted by mapping */ @NotNull @Contract(pure=true) public static <T,V> List<V> map(@NotNull Collection<? extends T> iterable, @NotNull Function<T, V> mapping) { if (iterable.isEmpty()) return emptyList(); List<V> result = new ArrayList<V>(iterable.size()); for (T t : iterable) { result.add(mapping.fun(t)); } return result; }
@NotNull @Contract(pure = true) public static <T, KEY, VALUE> Map<KEY, VALUE> map2MapNotNull(@NotNull Collection<? extends T> collection, @NotNull Function<T, Pair<KEY, VALUE>> mapper) { final Map<KEY, VALUE> set = new THashMap<KEY, VALUE>(collection.size()); for (T t : collection) { Pair<KEY, VALUE> pair = mapper.fun(t); if (pair != null) { set.put(pair.first, pair.second); } } return set; }
@NotNull @Contract(pure=true) public static <T, KEY, VALUE> Map<KEY, VALUE> map2Map(@NotNull Collection<? extends T> collection, @NotNull Function<T, Pair<KEY, VALUE>> mapper) { final Map<KEY, VALUE> set = new THashMap<KEY, VALUE>(collection.size()); for (T t : collection) { Pair<KEY, VALUE> pair = mapper.fun(t); set.put(pair.first, pair.second); } return set; }
/** * @return read-only list consisting of the elements from collection converted by mapper */ @NotNull @Contract(pure=true) public static <T, V> List<V> map2List(@NotNull Collection<? extends T> collection, @NotNull Function<T, V> mapper) { if (collection.isEmpty()) return emptyList(); List<V> list = new ArrayList<V>(collection.size()); for (final T t : collection) { list.add(mapper.fun(t)); } return list; }
private Dimension computeSize(Function<JComponent, Dimension> transform, int tabCount) { Dimension size = new Dimension(); for (TabInfo each : myVisibleInfos) { 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(size, tabCount); return size; }
private void showNotification(@NotNull String title, @NotNull String message, @NotNull NotificationType type, @Nullable Function<Notification, List<AnAction>> actionsProvider) { Notification notification = new Notification(PerlBundle.message("perl.deparsing.notification"), title, message, type); if (actionsProvider != null) { List<AnAction> actions = actionsProvider.fun(notification); if (actions != null) { actions.forEach(notification::addAction); } } Notifications.Bus.notify(notification, myProject); }
public static void traverse(LayoutElement element, Function<LayoutElement, Boolean> function) { boolean shouldStop = !function.fun(element); if (shouldStop) return; if (element instanceof Split) { Split split = (Split) element; traverse(split.first, function); traverse(split.second, function); } } }
@Override public PsiElement setName(@NonNls @NotNull String newBaseName) throws IncorrectOperationException { // fixme should be in com.perl5.lang.perl.psi.utils.PerlPsiUtil.renameElement() PsiElement nameIdentifier = getNameIdentifier(); ElementManipulator<PsiElement> manipulator = ElementManipulators.getManipulator(nameIdentifier); TextRange identifierRange = this instanceof PerlIdentifierRangeProvider ? ((PerlIdentifierRangeProvider)this).getRangeInIdentifier() : ElementManipulators.getValueTextRange(nameIdentifier); myNameIdentifier = manipulator.handleContentChange(nameIdentifier, identifierRange, newBaseName); myName = getNameComputation().fun(newBaseName); return this; }