Uast: support beforeVisit() and afterVisit() in visitor

This commit is contained in:
Yan Zhulanow
2016-03-22 16:25:29 +03:00
parent 3a7f29bfc5
commit 06a88f417c
@@ -54,8 +54,12 @@ abstract class UastVisitor {
open fun visitThisExpression(node: UThisExpression): Boolean = false
open fun visitSuperExpression(node: USuperExpression): Boolean = false
open fun beforeVisit(node: UElement) {}
open fun afterVisit(node: UElement) {}
fun handle(node: UElement): Boolean {
return when (node) {
beforeVisit(node)
val result = when (node) {
is UFile -> visitFile(node)
is UClass -> visitClass(node)
@@ -91,6 +95,8 @@ abstract class UastVisitor {
is USuperExpression -> visitSuperExpression(node)
else -> true
}
afterVisit(node)
return result
}
open fun process(element: UElement) {