I've noticed a strange behavior of ASTRewrite. When getter and setter are generated for a class the whole class definition gets
rewritten instead of the definitions of the new accessor methods. The rewrite then gets trimmed down by ChangeGenerator.CodeComparer to eliminate the part surrounding the new method. That trimming process seems to be buggy and at least sometimes produces ReplaceEdit
instead of InsertEdit.
Here is a snapshot of a change obtained at the end of ModificationCollector.createFinalChange method when creating getter and setter for x_ in
result CCompositeChange (id=139)
fChanges ArrayList<E> (id=144)
elementData Object[2] (id=158)
[0] CTextFileChange (id=160)
fEdit MultiTextEdit (id=166)
fChildren ArrayList<E> (id=181)
elementData Object[2] (id=182)
fParent MultiTextEdit (id=166)
fText ";\n void setX(int varX)\n {\n x_ = varX;\n }\n\n int x() const\n {\n return x_;\n }" (id=185)
The change replaces semicolon and the line break at the end of the previous method declaration. It would be more appropriate to have an InsertEdit starting
after the end of the previous line, something like:
fText "\n void setX(int varX)\n {\n x_ = varX;\n }\n\n int x() const\n {\n return x_;\n }\n"
What is the rationale for the whole class definition to be rewritten?