AST matcher for innermost and outermost loops


Is there any way to use statement matcher that can directly result nodes which are innermost loops? Basically I want to add a piece of code inside the inner most loops and outside of the outermost loops(loops which have no forstmt descendent and loops which have no forstmt ancestor.) Is any StatementMatcher that can result any of them?

Thank you,


There is not, but it is very easy to do one, the same way as you said:

forStmt(unless(hasDescendant(forStmt()))) and forStmt(unless(hasAncestor(forStmt()))) should do the work