Code generator for dart

痞子三分冷 提交于 2019-12-23 19:05:19

问题


I need to do mapper between dart and JS object. I don't like to write "unncessary' code so I would like DartEditor wrote it for me :)

What i would like to write:

DartInvoice extends jsw.TypedProxy {
     @Parser(attributName="invoice")
     String number;
     @Parser(attributName=amount)
     Number sum;
}

What i would like to achieve:

DartInvoice extends jsw.TypedProxy {
     set number(String number) => toJs.set('invoice' : number);
     String number => toJs.get(invoice);
     set sum(Number sum) => toJs.set('amount' : sum);
     Number get sum => toJs.get(amount);
}

The question is :) how dart or dart editor can help me? Tell me what i should read. :)


回答1:


I started the js_wrapping_generator project to do something like that but its not quite ready for prime time. I used the analyzer package to parse dart files an generate other files.

You can have a look at dart_generator.dart to have a sample.

The current version is based on a simple AST and I'm working on a new version based on a resolved AST to simplify templating even more.



来源:https://stackoverflow.com/questions/19991745/code-generator-for-dart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!