EMF provides a way of dealing with dedicated implementation for EOperation
and derived EAttribute
using "invocation delegate". This functionality allows you to put some implementation directly in your ecore
metamodel in a string format (as soon as the used language can be "handled" by EMF, i.e, an invocation delegate exists).
As far as I know, OCL is well supported: https://wiki.eclipse.org/OCL/OCLinEcore#Invocation_Delegate
The registration of the invocation delegate is performed either by plugin registration or by hand (for standalone usage), and the mechanism works with the EMF reflection layer (dynamic EMF): https://wiki.eclipse.org/EMF/New_and_Noteworthy/Helios#Registering_an_Invocation_Delegate
(Please note that I never experienced this mechanism. I know it exists, but I never played with it.)
EDIT>
It seems that the question was not related to dynamic code execution for derived attribute, but to code injection (I misunderstood the "Is there a way to take a String and specify this String as the implementation for the computation of the derived feature?").
EMF provides a way of injecting code placed on the ecore
metamodel directly into the generated code.
Here is the way for EAttribute
with derived
property. The EAttribute
should have the following properties set to true
: {derived volatile}
(you can also add transient
). If you only want a getter and no setter for your EAttribute
, you can also set the property changeable
to false
.
Once your EAttribute
is well "configured", you have to add a new EAnnotation
with the source set to http://www.eclipse.org/emf/2002/GenModel
and an entry with the key
set to get
and value
set to your code that will be injected (see image below).

And voilà, your code will be generated with the value
value injected in your getter.
You can add the same process for EOperation
using body
instead of get
.