melange
melange copied to clipboard
MelangeResource upcast() cannot be called several times on the same resource
In scenario where we wish to mix code written on a base language and an extended language, is would be useful to be able to call the method upcast
several time according to the need.
for example:
load the model using conversion using an URL such as
melange:/file/model/myfsm.fsm?lang=fsmadaptation.XSFSM
(fsm is cloned as an xsfsm)
then a some point call a code as fsm by changing the modeltype to FSMMT melangeRes.upcast("fsmadaptation.FSMMT")
do a transformation based on FSMMT (ie. operations are not copied by melange and exists only for fsm metaclasses)
then continue to work as XSFSMMT
melangeRes.upcast("fsmadaptation.XSFSMMT")
(or melangeRes.upcast(null)
as stated in the API doc, null
is supposed to remove the adaptation)
Continue the transformation as XSFSMMT/null
In that case, I think we can maintain the model state (since we do not change the language) and only change the ModelType
However the current implementation in https://github.com/diverse-project/melange/blob/master/plugins/fr.inria.diverse.melange.resource/src/main/java/fr/inria/diverse/melange/resource/MelangeResourceImpl.xtend#L327 fully reloads the model from the wrappedResource and crashes becauses the resource already exists (https://github.com/diverse-project/melange/blob/master/plugins/fr.inria.diverse.melange.resource/src/main/java/fr/inria/diverse/melange/resource/MelangeResourceImpl.xtend#L350)
note: the extendsAs method documentation also states that null can be used to remove the adaptatoin, but in that case I don't think we can (easily) maintain the model state