aboutsummaryrefslogtreecommitdiff
path: root/src/PsiAPI.kt
blob: 9f43730bfd53489bbd6582d7cc228f164a19cdf6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package com.jetbrains.dokka

import com.intellij.psi.PsiElement
import kotlin.support.AbstractIterator

fun PsiElement.previousSiblings(): Stream<PsiElement> {
    var element: PsiElement? = this
    return object : Stream<PsiElement> {
        override fun iterator(): Iterator<PsiElement> = object : AbstractIterator<PsiElement>() {
            override fun computeNext() {
                element = element?.getPrevSibling()
                if (element == null)
                    done()
                else
                    setNext(element!!)
            }
        }
    }
}