List<PsiElement> (@Nullable Object node) { Object value = getValueFromNode(node); JBIterable<?> it = value instanceof PsiElement || value instanceof VirtualFile || value instanceof PsiAwareObject ? JBIterable.of(value) : value instanceof Object[] ? JBIterable.of((Object[])value) : value instanceof Iterable ? JBIterable.from((Iterable<?>)value) : JBIterable.of(TreeUtil.getUserObject(node)); return it.flatten(o -> o instanceof RootsProvider ? ((RootsProvider)o).getRoots() : Collections.singleton(o)) .map(o -> o instanceof VirtualFile ? PsiUtilCore.findFileSystemItem(myProject, (VirtualFile)o) : o instanceof PsiAwareObject ? ((PsiAwareObject)o).findElement(myProject) : o) .filter(PsiElement.class) .filter(PsiElement::isValid) .toList(); }