Search code examples
javaeclipseemf

How to generate private/protected methods & variables using EMF?


I wish to generate Java code using genmodel based on a UML model.

I am working on Eclipse Oxygen, UML model from Papyrus (with some usage of the Ecore profile) in order to generate the Ecore using GenModel wizard to finally generate the model Java code (standard Eclipse plugin).

I have separated my generated source from handwritten ones so a @Generated NOT + manual modification solution is to be avoided :)

Whether I change the UML visibility parameter of my attributes, nothing change in the generated model code (everything is public).

I have not found info about the possibility to do so in the doc I have read (EMF help, Vogella blog, opCoach blog, Google...)

My questions are these:

  • Is it possible to have visibility of UML objects be taken into account by GenModel processing?
  • Is this possible to setup UML Ecore profile to force visibility on generated code? (I have tried without succeed so far)

Solution

  • Thanks to @Kapep, the solution is to look at the visibility attribute of EReference (or EAttribute if needed) stereotype applied to the corresponding Property of UML Model. Changes made there do not impact the generation of the Implementation but changes what appear in the generated interface :

    • Unspecified (default): setter & getter methods are present
    • None: setter & getter methods are not present
    • ReadOnly: only getter present

    Then you are free in your man-made code that extend the generated one to use/show the way you want for getter and setter!