Is eclipse's ecj compiler extensible?

筅森魡賤 提交于 2020-02-25 06:32:16

问题


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.

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.


回答1:


As Object Teams has been mentioned in comments:

(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:

  • 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) 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

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.



来源:https://stackoverflow.com/questions/60170365/is-eclipses-ecj-compiler-extensible

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