Is there an easy way to find out block statements ...
# kontributors
t
Is there an easy way to find out block statements of the same type in a kt file? so far i only played around with the
KtExpression
method
nextStatement()
, using it more than once on one expression (especially when referenced) can result in null and behaviour i don’t want. e.g.: i want to iterate through a bunch of reoccurring types and save them in a list.
y
normally you’d use a visitor for this
t
ah, makes sense, thanks! 🙂
@yole so there’s like a little bit of a complicated problem i ran into. is it possible to get the parent or the whole kt file from a specific KtExpression by calling
conainingKtFile
?
it seems that i can get to the kt file but having problems reading expressions out of it even though i’m using
.accept(object: KtTreeVisitorWorld() { ... })
y
yes, you can use
containingKtFile
to get the file or
.parent
to get the direct parent
t
with
.parent
it worked 🙂 , thanks again!