Refactor migrational intentions

- Make them independent on element
- Extract common parts into JetWholeProjectModalByTaskCollectionAction class
This commit is contained in:
Denis Zharkov
2015-04-21 17:38:01 +03:00
parent ef79b260f4
commit fef568dbf0
9 changed files with 188 additions and 159 deletions
@@ -512,3 +512,22 @@ public fun PsiElement.getElementTextWithContext(): String {
.insert(0, "File name: ${getContainingFile().getName()}\n")
.toString()
}
// Calls `block` on each descendant of T type
// Note, that calls happen in order of DFS-exit, so deeper nodes are applied earlier
inline fun <reified T : JetElement> forEachDescendantOfTypeVisitor(
inlineOptions(InlineOption.ONLY_LOCAL_RETURN) block: (T) -> Unit
): JetVisitorVoid =
object : JetTreeVisitorVoid() {
override fun visitJetElement(element: JetElement) {
super.visitJetElement(element)
if (element is T) {
block(element)
}
}
}
inline fun <reified T : JetElement, R> flatMapDescendantsOfTypeVisitor(
accumulator: MutableCollection<R>,
inlineOptions(InlineOption.ONLY_LOCAL_RETURN) map: (T) -> Collection<R>
): JetVisitorVoid = forEachDescendantOfTypeVisitor<T> { accumulator.addAll(map(it)) }