Question

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.

Was it helpful?

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.

OTHER TIPS

I don't know anything about CodeModel, so I can't say whether or not it is a good project. However, since you are creating an eclipse plugin, I would recommend going with JDT. The reason is mostly for compatibility with other Eclipse components. The JDT AST API works out of the box with other Eclipse APIs (the resource API, the Java Model API, the refactoring API, text manipulation API, and the Editor API, just to name a few). JDT is far from simple, but it is very powerful and fits nicely into the Eclipse model.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top