eclipse-emfeclipse-emf-ecoremetamodelmodel-driven-developmentmdsd

Can I make an Ecore metamodel that enables models to reference Java classes?


Suppose I want to design an Ecore metamodel that looks something like this, designed to be used to "run" a list of classes:

JavaClassRunnerList
   0..* JavaClass

And assume I have some Java project that has classes named PrintsHello, PrintsSeparator, and PrintsWorld.

I'd like to be able to then write models that look like this:

JavaClassRunnerList
   PrintsHello.class
   PrintsSeparator.class
   PrintsWorld.class
   PrintsSeparator.class
   PrintsSeparator.class

I want my model to be able to include a Java project and to recognize its classes as choices for the model references (possibly co-located in the same project the model is in.)

Is this possible?


Solution

  • Ed Merks said the following. See the thread for the remainder of the discussion.

    You can use Ecore's EJavaClass data type to create a multi-valued attribute. You might be better just to use class names, and use a class loader to convert therm to actual class instances.

    Same goes for wanting references to IProject; you can use a string and then resolve it to an IProject using the the workspace root.