Generating Getters and Setters should use ASTRewrite to add declarations to the class definition and that should result in InsertEdits.
Markus.
From: sprigogin@xxxxxxxxxx [mailto:sprigogin@xxxxxxxxxx]
On Behalf Of Sergey Prigogin
Sent: Friday, July 15, 2011 09:22
To: Schorn, Markus
Cc: Emanuel Graf; cdt-dev@xxxxxxxxxxx
Subject: Re: [cdt-dev] ASTRewrite question
On Thu, Jul 14, 2011 at 11:45 PM, Schorn, Markus <Markus.Schorn@xxxxxxxxxxxxx> wrote:
Looks like a bug to me, any refactoring should leave as much code untouched as possible.
Did you mean the rewrite of the class definition, or the improper TextEdit, or both?
From:
cdt-dev-bounces@xxxxxxxxxxx [mailto:cdt-dev-bounces@xxxxxxxxxxx]
On Behalf Of Sergey Prigogin
Sent: Friday, July 15, 2011 03:21
To: Emanuel Graf; CDT General developers list.
Subject: [cdt-dev] ASTRewrite question
Importance: Low
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?
_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev