Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
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? 

Markus.


-sergey 

 

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

 

class A {

public:

  A();

  virtual ~A();

  int foo();

 

private:

  int x_;

  int y_;

};

 

result CCompositeChange  (id=139)

desc null

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)

[0] ReplaceEdit  (id=183)

fChildren null

fDelta 0

fLength 1

fOffset 52

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)

[1] null

modCount 1

size 1

                                        ...

                                ...

[1] null

modCount 1

size 1

 

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:

InsertEdit

fOffset 54

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?

 

-sergey

 


_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev



Back to the top