Java 语法预处理器
我正在寻找一种 Java 宏语言,它提供了执行闭包(编译为匿名内部类)和列表理解(编译为基本 java 循环)的便捷方法。
我正在寻找的这种东西的一个例子是 Xtend2 http://www.eclipse.org /Xtext/#xtend2
但我想要一些用于通用编程的东西(Xtend2 是 Xtext 的非常具体的 DSL,并且有大量的依赖项)。甚至可能让我在一个文件中定义多个类(然后由预处理器分成两个单独的文件)。
有这样的事情存在吗?
编辑添加: 我正在进行 Android 开发,因此任何替代方案都必须生成有效的 Java 源代码,或者字节代码必须与 dalvik 重新编译器兼容。
I'm looking for a Java macro language that provides for convenient ways of doing closures (that compile to anonymous inner classes) and list comprehension (that compiles down to basic java loops).
An example of the kind of thing I'm looking for would be Xtend2 http://www.eclipse.org/Xtext/#xtend2
But I want something for general purpose programming (Xtend2 is very specific DSL for Xtext and has a ton of dependencies). Maybe even something that would let me define multiple classes in a single file (which would then get split up into two separate files by the pre-processor).
Does anything like this exist?
Edited to add:
I'm doing Android development so any alternatives have to generate either valid Java source or the byte code has to be compatible with the dalvik recompiler.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嗯,曾经有 JSE,当时非常有趣。
米拉很酷,但在我看来,还没有准备好迎接黄金时段。
尽管您的源视图是 Java,但您可以使用智能模板做很多事情。
几天前,SO 上也有一篇关于在 Android 上使用 XTend 的帖子。
Mmm, there used to be the JSE, which was tremendous fun, back in the day.
Mirah is cool, but not ready for primetime, IMO.
You can do a lot with smart templating, although your source view is the Java.
There's a post on SO about using XTend on Android from a few days ago, too.
Frege 生成 Java 源代码。
不知道dalvik是否会喜欢。 (但我很想听听......)
当然,您还有一些运行时库代码。
话虽如此,还有许多其他项目在 java 中执行闭包等操作,例如: lambdaj< /a>
Frege produces java source code.
I do not know whether dalvik would like it. (But I would be interested to hear ...)
And, of course, you have some runtime library code.
That being said, there are a number of other projects that do closures etc. in java, for example: lambdaj