Reputation: 5329
Assuming that I have an instance of ASTRewrite of which I can not make assumptions (ie returned by a overridable method). I would like to test if the rewrite actually stores any modifications to the compilation unit or otherwise it is merely the "identity" change. How is it possible do this?
I went over the methods of ASTRewrite but was not able to find anything that would help. So I guess the correct way to do it is not straightforward.
Upvotes: 1
Views: 89
Reputation: 3095
You can determine the edits applied on the AST using TextEdit.
TextEdit edits = rewrite.rewriteAST(document, compUnit.getJavaProject().getOptions(true));
The edits will be empty if no changes are done on the AST. Else it will contain the aditions and deletions to the AST with offset.
You can check whether the TextEdit is empty using the getLength()
method.
// If edits available, write them to the file.
if (edits.getLength() != 0) {
// do something
}
More help can be found from the below link :
Upvotes: 1