@NotNull public static <T extends PsiElement> List<T> getStubChildrenOfTypeAsList(@Nullable PsiElement element, @NotNull Class<T> aClass) { if (element == null) return Collections.emptyList(); StubElement<?> stub = element instanceof StubBasedPsiElement ? ((StubBasedPsiElement)element).getStub() : null; if (stub == null) { return getChildrenOfTypeAsList(element, aClass); } List<T> result = new SmartList<T>(); for (StubElement childStub : stub.getChildrenStubs()) { PsiElement child = childStub.getPsi(); if (aClass.isInstance(child)) { //noinspection unchecked result.add((T)child); } } return result; }
void addChild(@NotNull ObjectNode<T> child) { List<ObjectNode<T>> children = myChildren; if (children == null) { myChildren = new SmartList<ObjectNode<T>>(child); } else { children.add(child); } child.myParent = this; }
@NotNull @Contract(pure=true) public static <T> List<T> newSmartList(@NotNull T... elements) { return new SmartList<T>(elements); }
@NotNull @Contract(pure=true) public static <T> List<T> newSmartList() { return new SmartList<T>(); }
@NotNull @Contract(pure=true) public static <T, V> List<V> findAll(@NotNull Collection<? extends T> collection, @NotNull Class<V> instanceOf) { final List<V> result = new SmartList<V>(); for (final T t : collection) { if (instanceOf.isInstance(t)) { @SuppressWarnings("unchecked") V v = (V)t; result.add(v); } } return result; }
@NotNull @Contract(pure=true) public static <T> List<T> newSmartList(T element) { return new SmartList<T>(element); }
@NotNull @Contract(pure=true) public static <T> List<T> findAll(@NotNull T[] collection, @NotNull Condition<? super T> condition) { final List<T> result = new SmartList<T>(); for (T t : collection) { if (condition.value(t)) { result.add(t); } } return result; }
@NotNull public static PsiClass[] filterByName(@NotNull String className, @NotNull PsiClass[] classes) { if (classes.length == 0) return PsiClass.EMPTY_ARRAY; if (classes.length == 1) { return className.equals(classes[0].getName()) ? classes : PsiClass.EMPTY_ARRAY; } List<PsiClass> foundClasses = new SmartList<PsiClass>(); for (PsiClass psiClass : classes) { if (className.equals(psiClass.getName())) { foundClasses.add(psiClass); } } return foundClasses.isEmpty() ? PsiClass.EMPTY_ARRAY : foundClasses.toArray(new PsiClass[foundClasses.size()]); }
@Override public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) { if (!(file instanceof SoyFile) || file.getVirtualFile() == null) { return null; } List<ProblemDescriptor> problems = new SmartList<ProblemDescriptor>(); findProblems((SoyFile)file, manager, isOnTheFly, problems); if (problems.isEmpty()) { return ProblemDescriptor.EMPTY_ARRAY; } return problems.toArray(new ProblemDescriptor[problems.size()]); }
@NotNull @Contract(pure=true) public static <T> List<T> findAll(@NotNull Collection<? extends T> collection, @NotNull Condition<? super T> condition) { if (collection.isEmpty()) return emptyList(); final List<T> result = new SmartList<T>(); for (final T t : collection) { if (condition.value(t)) { result.add(t); } } return result; }
void doWhenExecuted(@NotNull final Runnable runnable) { Runnable toRun; synchronized (this) { if (isExecuted()) { if (myRunnables == null) { toRun = runnable; } else { CompositeRunnable composite = new CompositeRunnable(myRunnables); composite.add(runnable); toRun = composite; myRunnables = null; } } else { if (myRunnables == null) { myRunnables = new SmartList<Runnable>(); } myRunnables.add(runnable); return; } } toRun.run(); }
List<FoldingDescriptor> results = new SmartList<>(); jspFile.accept(new XmlRecursiveElementVisitor(true) {
@Nullable private static IProperty getResolvedProperty(@NotNull final XmlAttributeValue codeValue) { return CachedValuesManager.getCachedValue(codeValue, KEY, () -> { List<IProperty> allProperties = new SmartList<>(); for (PsiReference nextRef : codeValue.getReferences()) { if (nextRef instanceof PsiPolyVariantReference) { Arrays.stream(((PsiPolyVariantReference) nextRef).multiResolve(false)) .filter(ResolveResult::isValidResult) .map(ResolveResult::getElement) .map(o -> ObjectUtils.tryCast(o, IProperty.class)) .filter(Objects::nonNull) .forEach(allProperties::add); } else { Optional.ofNullable(nextRef.resolve()) .map(o -> ObjectUtils.tryCast(o, IProperty.class)) .ifPresent(allProperties::add); } } IProperty theChosenOne = chooseForLocale(allProperties); return new CachedValueProvider.Result<>(theChosenOne, PsiModificationTracker.MODIFICATION_COUNT); }); }
@TestOnly public void flush() { List<Pair<Request, Runnable>> requests; synchronized (LOCK) { if (myRequests.isEmpty()) { return; } requests = new SmartList<>(); for (Request request : myRequests) { Runnable existingTask = request.cancel(); if (existingTask != null) { requests.add(Pair.create(request, existingTask)); } } myRequests.clear(); } for (Pair<Request, Runnable> request : requests) { synchronized (LOCK) { request.first.myTask = request.second; } request.first.run(); } UIUtil.dispatchAllInvocationEvents(); }
List<Pattern> otherPatterns = new SmartList<>(); if (knownAttribute != null && !(knownAttribute.getDefaultValue() instanceof KnownAttribute.ListValue)) { for (BnfAttr attr : thisAttrs.getAttrList()) {