Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-dev] ASTRewrite question

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


Back to the top