eclipseemfeclipse-emf

How to return a typed list from a method with the Eclipse EMF?


I would like to generate define generically typed return parameters in an EMF model.

The current state of the model is similar as the example in the following image.

EMF Example class

Is it even possible to alter the model that it generates the interface code for our example class as depicted below? And if so, how do I do that?

/**
 * ...
 * @generated
 */
public interface Example extends EObject {
    /**
     * ...
     * @generated
     */
    List<Definition> getDefinitions();      

    /**
     * ...
     * @generated
     */
    Optional<Extension> getExtension();      

}

Btw. the classes Definition and Extension are modelled within the same diagram.

Thank you for reading!


Solution

  • You need to create a new "EData Type", e.g. "MyList", where the "Instance Type Name" is e.g. java.util.List<my.fully.qualified.name.Definition>.