问题描述
我对修改Java语法和一些隐式范例感兴趣。由于我是使用eclipse开发的,它提供了自己的编译器,也可以独立使用,因此我想知道是否无法扩展ecj以遵守其他语法规则(并正确处理它们)。
通过从AST中删除元素并创建一些新元素,我的语法更改都可以解决,因此我认为我想做的事情是可能的,而无需深入字节码。
I am interested in modifying java syntax and some implicit paradigms. Since I develop with eclipse which provides it's own compiler, which can also be used standalone, I was wondering if it wasn't possible to extend ecj to respect additional grammar rules (and correctly handle them).My syntactical changes are all resolvable by removing elements from the AST and creating some new ones, so I assume that what I want to do is possible without diving into bytecode.
本质上,我想做的事情可以通过在实际编译之前虚拟修改源代码来完成。但是我怀疑这样做会破坏源映射,这会使调试变得麻烦。
Essentially, what I want to do could be done by 'virtually' modifying the source code before the actual compilation. However I suspect that doing so would mess up the source mapping, which would make debugging a hell.
在旁注:我知道Lombok项目,该项目可以扩展和更改类编译,但是严格来说,lombok仅使用注释,并且不修改语法。因此,我想做的是更具侵入性的语言规范。
On a sidenote: I am aware of project Lombok, which extends and alters class compilation, however lombok uses annotations only, and does not modify syntax, strictly speaking. So what I want to do is more invasive to the language specs.
推荐答案
对象团队已在评论中提到:
As Object Teams has been mentioned in comments:
(1)对象团队本身将JDT扩展为其自己的语言是Java的扩展。这是通过双重策略完成的:
(1) Object Teams itself extends JDT for its own language OT/J which is an extension of Java. This is done in a dual strategy:
- 我们维护。尽管这很繁重,但它成功地证明了JDT体系结构适合于修改。
- 我们使用我们自己的以非侵入方式 adapt IDE其他部分的行为(特别是org.eclipse.jdt.ui)来反映OT / J的语义
- We maintain a fork of org.eclipse.jdt.core. While this is quite heavy lifting it successfully demonstrates that the JDT architecture is suitable for modification.
- We use our own concepts of role objects to non-invasively adapt the behavior of other parts of the IDE (notably org.eclipse.jdt.ui) to reflect the semantics of OT/J
(2)我有几篇(较旧的)博客文章演示了如何将OT / J用于创建JDT的非侵入性变体,包括对扩展语法的支持:
(2) I have a few (oldish) blog posts that demonstrate how OT/J can be used for creating non-invasive variants of JDT including support for extended syntax:
- IDE for your own language embedded in Java? (part 1)
- IDE for your own language embedded in Java? (part 2)
- Get for free what Coin doesn’t buy you
免责声明:我是OT / J的作者,并且是OT / J的实现者,后来成为Eclipse JDT的提交者。
Disclaimer: I am author of OT/J and lead of its implementation, and later became a committer on Eclipse JDT.
对于其他问题,还有一个。
For further questions, there's a forum.
这篇关于eclipse的ecj编译器是否可扩展?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!