I would like to insert line comments in my code, programmatically. I am visiting a method declaration and i want to insert a line comment (or more) above it, using the AST of the method. Could anyone please give me a code example of how to do that? I have been searching for a long time and no success yet. Thanks in advance.
A:
The only way I can think of, to insert code programmatically, is to open a Filestream and write to the text file at a specific pointer location.
Jon
2009-02-17 14:25:46
A:
Here's how I would do it:
void insertComment(String comment, OutputStream fos) throws IOException {
String commentKeyword = "//";
fos.write(commentKeyword.getBytes());
fos.write(comment.getBytes());
fos.write("\r\n".getBytes());
}
I don't think there is a native way to do this...
OTisler
2009-02-17 21:55:08