Skip to content
Johannes Coetzee edited this page Jun 4, 2024 · 2 revisions

Loosely based on https://javaparser.org/code-generation-and-maven-in-javaparser/

See https://github.com/javaparser/javaparser/wiki/A-Detailed-Guide-to-Adding-New-Nodes-and-Fields for a detailed walkthrough to adding new nodes and fields.

JavaParser uses JavaParser to build parts of JavaParser! ;)

Each of the stages is as follows:

  1. JavaCC is run to be able to compile/parse Java .

  2. JavaParser core (incl. the JavaCC output) is used to (re-)build the meta-model.

    • The meta-model contains a static field, holding a list of node classes.
    • This list is manually curated to ensure that "parent" node classes are processed prior to the "child" node classes (e.g. a LiteralExpr.class appears before LiteralStringExpr.class).
  3. Based on the annotations within each of the node classes (e.g. @OptionalProperty and @AllFieldsConstructor), an in-memory meta-model is generated then used to persist details about the attributes/properties/constructor arguments into JavaParserMetaModel.

  4. Using the meta-model produced within in the previous step, the core-generator is then run to embellish each of the ast-nodes with getter/setter methods

    • e.g. PropertyGenerator / AcceptGenerator / CloneGenerator, ReplaceMethodGenerator
  5. Finally, the bnd-generator produces the file bnd.bnd, which reports to external modules which packages are available for consumption.

  6. Finally, now that the generation is complete, build the "final" / "current" version of JavaParser. It is this version that gets used and released (Release Process).

Clone this wiki locally