开发者

Modifying an existing class with GWT generator

开发者 https://www.devze.com 2023-01-30 01:45 出处:网络
I have a class (for example District) that implements two Methods: public Object getAtribute(String name) {

I have a class (for example District) that implements two Methods:

public Object getAtribute(String name) {

}
public void setAtribute(String name, Object value){

}开发者_如何学C

Everything is setup to call my Generator when GWT.create(Dirstrict.class) is called.

Now How can I modify the implementation of these methods in the same class(i.e write code inside them) so that the final code in District class will be like this:

public Object getAtribute(String name) {
   //The generated code
}
public void setAtribute(String name, Object value){
   //The generated code
}

Thanks,


Your generator won't be rewriting the implementation of the District class, it will be generating a subclass of District with a different implementation. That generated subclass is what will be returned by GWT.create(District.class).

Once your generated subclass is written, it will be compiled down to JavaScript and your original superclass implementation may be completely stripped out if it's never used, so the effect will be the same.


You have to create a generator class that extends com.google.gwt.core.ext.Generator and tell the gwt compiler to use your generator to generate the District class.

your.gwt.xml

<generate-with class="my.package.DistrictGenerator">
    <when-type-assignable
    class="my.package.District"/>
</generate-with>

But first you should think about if you really need to use a generator because it makes the code more complicated.

0

精彩评论

暂无评论...
验证码 换一张
取 消