Search code examples
javaeclipse-plugincode-generationeclipse-jdtsun-codemodel

Java source code generation: Eclipse JDT AST vs CodeModel


I am writing an eclipse plugin which lets the user write java code using a drag and drop kind of UI. I have came across these two java source code generation libraries. Eclipse JDT AST and Code Model.

I would like to understand the pros and cons of the two libraries. According to what I have read and understood:

  1. AST is very powerful. Looking at the code samples I have seen and the ASTView plugin, I am fully convinced that we can write any java construct using this library. Where as I could not find a lot of documentation or samples on Code Model. So, I am not very clear about its power. I would like to know if CodeModel is as powerful as AST.

  2. The amount of code required for CodeModel is much less than AST to achieve the same functionality.

  3. With AST, I can definitely re-write an existing java class. I couldn't find anything similar in case of CodeModel

I defenitely need the functionalities in 1 and 3. Having 2 also is an added advantage. I would like to know if codeModel has 1 and 3. Please let me know all the pros and cons of these two libraries. Also, let me know if there is a better library than these both.

Note: I am looking for souce code generation/manipulation and not byte code manipulation.

Thanks in advance.


Solution

  • I have used Eclipse JDT AST in my eclipse plugin for the following reason:

    1. CodeModel is not as powerful as AST. CodeModel does not have a lot of existing java constructs where AST keeps upgrading and it currently supports jdk 1.7
    2. CodeModel does not have a parser. It cannot read existing java files and edit the existing code.
    3. AST has great documentation whereas CodeModel has little or no documentation.