[PSI] Add forEachDescendantOfTypeInPreorder
- `forEachDescendantOfTypeInPreorder` is a preorder variant of `forEachDescendantOfType`, which operates in postorder.
This commit is contained in:
committed by
Space Team
parent
cd8143af7b
commit
9ac639e0d3
@@ -239,6 +239,28 @@ inline fun <reified T : PsiElement> PsiElement.forEachDescendantOfType(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline fun <reified T : PsiElement> PsiElement.forEachDescendantOfTypeInPreorder(noinline action: (T) -> Unit) {
|
||||||
|
forEachDescendantOfTypeInPreorder({ true }, action)
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun <reified T : PsiElement> PsiElement.forEachDescendantOfTypeInPreorder(
|
||||||
|
crossinline canGoInside: (PsiElement) -> Boolean,
|
||||||
|
noinline action: (T) -> Unit,
|
||||||
|
) {
|
||||||
|
checkDecompiledText()
|
||||||
|
this.accept(object : PsiRecursiveElementVisitor() {
|
||||||
|
override fun visitElement(element: PsiElement) {
|
||||||
|
if (element is T) {
|
||||||
|
action(element)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (canGoInside(element)) {
|
||||||
|
super.visitElement(element)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
inline fun <reified T : PsiElement> PsiElement.anyDescendantOfType(noinline predicate: (T) -> Boolean = { true }): Boolean {
|
inline fun <reified T : PsiElement> PsiElement.anyDescendantOfType(noinline predicate: (T) -> Boolean = { true }): Boolean {
|
||||||
return findDescendantOfType(predicate) != null
|
return findDescendantOfType(predicate) != null
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user