Code insertion: AST vs. document view [message #242977] |
Thu, 19 April 2007 14:17 |
Eclipse User |
|
|
|
Originally posted by: myawn.ebay.com
I'm hoping someone can give me some advice here, or (better yet) point
me to code that might serve as a model for what I'm trying to do.
I need to generate Java classes that are based on a template. So far,
my efforts have been based on having an AST parse of the template file,
and adding in new nodes, then saving the modified AST to a target location.
I'm wondering if this is really the best approach. For one thing, it
seems that I won't be able to insert (non-Javadoc) comments into the
generated code this way. (And even if I have the comments already in
the template, it doesn't seem like I can insert nodes so that they fall
in the right place relative to the existing comments) For another
thing, there are places where I need to insert chunks of code that are
constant, and the amount of code needed to reproduce the lines via AST
is far greater than just printf-like output to a text document.
So I'm wondering about a combination of using AST for some things, and
some sort of document/text view for others. I'm not sure from what I
have now how best to obtain a view of my code as just a stream of bytes,
and what steps I need to take to synchronize changes made to the AST
with changes made to the text view. Or if I'd be better off just
abandoning the AST approach and treat the entire file as just text.
I guess a broader question might be, what is AST really well-suited for,
and what is it not intended to be used for?
Mike
|
|
|
|
Powered by
FUDForum. Page generated in 0.05096 seconds