[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.tools.jdt] Changing Java source in a builder; which mechanism?

I have a builder, MyBuilder, that is meant to add a method to Java source 
files automatically.  MyBuilder is inserted in the build spec prior to the 
JavaBuilder.

I have initially implemented this per 
http://www.eclipse.org/articles/article.php?file=Article-JavaCodeManipulation_AST/index.html 
by using the ASWRewrite mechanism.  In the following snippet, I get the 
TextEdit, apply it to the IDocument, and the commit using a TextFileBuffer.

// Apply the edits to the in-memory document

// Get a tree of the edits to be applied to the document

TextEdit edits = rewriteRecorder.rewriteAST(boDocument, 
cu.getJavaProject().getOptions(true));

edits.apply(boDocument);


// commit changes to underlying file

textFileBuffer.commit(monitor, true);