私は次のクラスを持っています
public class Booking{
public String name;
public String comment;
public String session;
public void test(){
this.name = "hi";
}
}
以下を使用して計測します。
cc.instrument(new ExprEditor(){
public void edit(FieldAccess arg) throws CannotCompileException {
if (arg.isWriter()) {
StringBuffer code = new StringBuffer();
code.append("$0.");
code.append(arg.getFieldName());
code.append("=$1.toUpperCase();");
arg.replace(code.toString());
}
}
});
これを呼び出すと:
Booking b = new Booking();
b.name = "hello";
System.out.println(b.name); // Edited correction
b.test();
System.out.println(b.name);
私に与えます
hello // Externally, doesn't.
HI // Internally, works as expected
私は何が欠けていますか?簡単に達成できるはずのことの1つに思えます。
すべてのクラスで一括「fieldAccess.replace」を実行する必要があるとは言わないでください。OO