Hello,
As mentioned in a previous mail to this list, I am new hacker on the ASTParser et al. I am trying to use ASTParser et al for a syntax highlighting project. If I am using ASTParser for entirely the wrong purposes, please bonk me on the head and point me in the right direction. =)
Question: How do I find the text offset of the "finally" keyword in a try/finally statement? (I'm actually on the hunt for all Java keywords, but I want to keep this e-mail tightly focused so as to ask a Good Question.)
So far, my code is trying to walk the text between
- the end of the try block, via TryStatement.getBody(), or last catch clause, via TryStatement.catchClauses(),
- and the start of the finally block, via TryStatement.getFinally().
This is a bit tricky as a I need to avoid comments, via CompilationUnit.getCommentList(), and catch clauses . A simple text search for "finally" won't work as the term may be embedded with comments, or even finally blocks within a catch block(!).
Imagine a slightly dreadful segment of code as this:
try {
// do stuff
}
catch (/* finally! */ Exception e) {
try {
// try this next
}
finally {
// nope
}
}
// finally
/* more and more finally!
blah, blah, blah
*/
finally { // <-- how to find this keyword's text offset?
// shutdown
}
Is there a better way?
Thanks,
Arpe