[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.tools] Re: How to get AST for an IMethod (again)

Simon Giesecke wrote:
Hi,

I know that the question has already been posted here, but I need some
clarification.

It is clear to me that I need to parse the method's compilation unit by

AST.parseCompilationUnit(method.getCompilationUnit())

Then, of course, I have the AST for the whole compilation unit, but how do
I easily find the subtree refering to my method?

At the moment I use an ASTVisitor to search the tree and compare the
IMethod.getSourceRange with MethodDeclaration.getStartPosition/getLength

First, this doesn't look very efficient to me, but what is more severe, it
doesn't work in at least one case: If there is a Non-JavaDoc-comment
preceding the method declaration, IMethod.getSourceRange contains the
comment and MethodDeclaration.getStartPosition/getLength does NOT.

If this is the only deviance between the two notions of source range, I
could of cause catch this case, but I have not found any specification of
what the ISourceRange of an ISourceReference implementor exactly is.

Kind regards,
Simon

This newsgroup is deprecated. Please find another newsgroup on this sever to post to.