eclipse / epsilon

Epsilon is a family of Java-based scripting languages for automating common model-based software engineering tasks, such as code generation, model-to-model transformation and model validation, that work out of the box with EMF (including Xtext and Sirius), UML (including Cameo/MagicDraw), Simulink, XML and other types of models.
https://eclipse.org/epsilon
Eclipse Public License 2.0
55 stars 11 forks source link

Metamodel Schizophrenia #25

Closed arcanefoam closed 1 year ago

arcanefoam commented 1 year ago

I am suffering what Ed Willink labelled "metamodel schizophrenia" using the ANT tasks (but it also happens with the run configurations). In the mwe, I have a small ETL that "lifts" a model to a metamodel. Thus the rules are of the form:

rule A2Class
    transform n : M!A
    to c : T!EClass { 
    ...

I also want to save the trace of the transformation using an ECore model. For this, I have created a metamodel that mimics the rules (this metamodel references the source metamodel):

class A2CLass extends Link {
    ref A source;
}
abstract class Link {
    ref EClass target;
}

To save the trace I add post processing in the ETL:

post {
    // Save trace
    var trace : new Trace!Trace;
    for (t in transTrace.transformations) {
        var link;
        switch(t.getRule().name) {
            case "A2Class":
                link = new Trace!A2Class;
            case "B2Class":
                link = new Trace!B2Class;
        }
        link.source = t.source;
        link.target = t.targets.first();
        trace.links.add(link);
    }
}

When running the transformation I get:


 The value of type 'org.eclipse.emf.ecore.impl.EClassImpl@a4d872b (name: A) (instanceClassName: null) (abstract: false, interface: false)' must be of type 'org.eclipse.emf.ecore.impl.EClassImpl@251e298c (name: A) (instanceClassName: null) (abstract: false, interface: false)'

which translates that the source metamodel is loaded twice as separate resources (once for the source model and once for the trace model). I suspect this has to do with how each EMF model uses its own ResourceSet, but have not taken the time yet to dig deeper into the issue. I have attached the MWE, with the ANT script that runs the ETL. mwe.zip

kolovos commented 1 year ago

Loading models using metamodelFile is bound to cause such issues. My recommendation would be to register your metamodels using epsilon.emf.register once and to load models using metamodelUri instead. This also applies to Trace.ecore: it should refer to the Meta1 metamodel through its URI (http://example.org/meta1) instead of its filename.

arcanefoam commented 1 year ago

In my actual project the meta1 metamodel is referenced by URI. I tried modifying the build to use registred uris instead with the same result.

kolovos commented 1 year ago

Could you please update all metamodel references to use URIs instead of file paths in the MWE and if the problem persists I'll have a look asap.

arcanefoam commented 1 year ago

Uploaded the mwe with the changes, also modified the source model to remove the xsd:schemaLocation

mwe.zip

kolovos commented 1 year ago

In the revised version, Trace.ecore still refers to the Meta1 metamodel by filename:

<eStructuralFeatures xsi:type="ecore:EReference" name="source" eType="ecore:EClass Meta1.ecore#//A"/>

Could you please make these references by URI too?

arcanefoam commented 1 year ago

That seem to have done the trick!