aboutsummaryrefslogtreecommitdiff
path: root/src/Analysis/PsiAPI.kt
blob: 19ac46753c6b54d396ffe2f77baac71255de88d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package org.jetbrains.dokka

import com.intellij.psi.*
import kotlin.support.*

fun PsiElement.children(): Stream<PsiElement> {
    val parent = this
    var current: PsiElement? = null
    return object : Stream<PsiElement> {
        override fun iterator(): Iterator<PsiElement> = object : AbstractIterator<PsiElement>() {
            {
                setNext(parent.getFirstChild())
            }
            override fun computeNext() {
                current = current?.getNextSibling()
                if (current == null)
                    done()
                else
                    setNext(current!!)
            }
        }
    }
}