Skip to content
Model centric tools for Spring development Community portal
Skyway PerspectivesModel driven delivery

Model reference

Reference Figure: Creating a New Java Class with the Annotator

The annotator adds model annotations to an existing Java class. This figure shows the class before and after annotation, and the resulting model entry.

Code assistant view showing generated Java types and model annotations
Figure 16. The annotator reads annotations and adds the class to the model.

The annotator works in the other direction from generation. Instead of writing code from a model, it reads a Java class and adds that class to the model. Teams that already have a codebase use it to bring existing types into the model without a manual rewrite.

Annotating a class

  1. Create or open the Java class.
  2. Add the model annotation that matches the role of the class, such as entity or service.
  3. Run the annotator on the class.
  4. Review the new model entry and adjust attributes or operations.

What the annotator reads

  • The class name and package, which become the type name and package.
  • Fields, which become attributes with inferred types.
  • Methods, which become operations with inferred parameters.
  • Associations, which become references between types.
Review the result. Inferred names are a starting point. Rename attributes so that they read well in the generated views, then regenerate.

Annotated classes stay in the codebase and continue to be edited by hand. The model records their shape so that recipes can generate the surrounding layers, such as views and controllers, without touching the class itself.