Skip to content

Commit

Permalink
234: example and test introducing mutual dep
Browse files Browse the repository at this point in the history
  • Loading branch information
LorenzoBettini committed Aug 5, 2020
1 parent 59f3238 commit 58edb7c
Show file tree
Hide file tree
Showing 13 changed files with 438 additions and 2 deletions.
@@ -0,0 +1,47 @@
package edelta.introducingdep.example;

import edelta.introducingdep.example.IntroducingDepOpExample;
import edelta.lib.AbstractEdelta;
import edelta.lib.EdeltaLibrary;
import java.util.function.Consumer;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.xtext.xbase.lib.Extension;
import org.eclipse.xtext.xbase.lib.IterableExtensions;

@SuppressWarnings("all")
public class IntroducingDepModifExample extends AbstractEdelta {
@Extension
private IntroducingDepOpExample operations;

public IntroducingDepModifExample() {
operations = new IntroducingDepOpExample(this);
}

public IntroducingDepModifExample(final AbstractEdelta other) {
super(other);
}

public void aModificationTest(final EPackage it) {
this.operations.setBaseClass(getEClass("anothersimple", "AnotherSimpleClass"));
final EClass referenceToSuperClass = IterableExtensions.<EClass>head(getEClass("anothersimple", "AnotherSimpleClass").getESuperTypes());
EdeltaLibrary.addNewEReference(getEClass("anothersimple", "AnotherSimpleClass"),
"aReferenceToSimpleClass", referenceToSuperClass);
final Consumer<EReference> _function = (EReference it_1) -> {
it_1.setEOpposite(getEReference("anothersimple", "AnotherSimpleClass", "aReferenceToSimpleClass"));
getEReference("anothersimple", "AnotherSimpleClass", "aReferenceToSimpleClass").setEOpposite(it_1);
};
EdeltaLibrary.addNewEReference(referenceToSuperClass, "aReferenceToAnotherSimpleClass", getEClass("anothersimple", "AnotherSimpleClass"), _function);
}

@Override
public void performSanityChecks() throws Exception {
ensureEPackageIsLoaded("anothersimple");
}

@Override
protected void doExecute() throws Exception {
aModificationTest(getEPackage("anothersimple"));
}
}
@@ -0,0 +1,26 @@
package edelta.introducingdep.example;

import edelta.lib.AbstractEdelta;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;

@SuppressWarnings("all")
public class IntroducingDepOpExample extends AbstractEdelta {
public IntroducingDepOpExample() {

}

public IntroducingDepOpExample(final AbstractEdelta other) {
super(other);
}

public void setBaseClass(final EClass c) {
EList<EClass> _eSuperTypes = c.getESuperTypes();
_eSuperTypes.add(getEClass("simple", "SimpleClass"));
}

@Override
public void performSanityChecks() throws Exception {
ensureEPackageIsLoaded("simple");
}
}
3 changes: 1 addition & 2 deletions edelta.parent/edelta.examples/edelta.examples.tests.launch
Expand Up @@ -10,9 +10,8 @@
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/>
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.m2e.launchconfig.classpathProvider"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_CLASSPATH_ONLY_JAR" value="false"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value=""/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="edelta.examples"/>
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.m2e.launchconfig.sourcepathProvider"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-ea"/>
</launchConfiguration>
5 changes: 5 additions & 0 deletions edelta.parent/edelta.examples/model/AnotherSimple.ecore
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="anothersimple" nsURI="http://www.anothersimple" nsPrefix="anothersimple">
<eClassifiers xsi:type="ecore:EClass" name="AnotherSimpleClass"/>
</ecore:EPackage>
5 changes: 5 additions & 0 deletions edelta.parent/edelta.examples/model/Simple.ecore
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="simple" nsURI="http://www.simple" nsPrefix="simple">
<eClassifiers xsi:type="ecore:EClass" name="SimpleClass"/>
</ecore:EPackage>
8 changes: 8 additions & 0 deletions edelta.parent/edelta.examples/modified/AnotherSimple.ecore
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="anothersimple" nsURI="http://www.anothersimple" nsPrefix="anothersimple">
<eClassifiers xsi:type="ecore:EClass" name="AnotherSimpleClass" eSuperTypes="Simple.ecore#//SimpleClass">
<eStructuralFeatures xsi:type="ecore:EReference" name="aReferenceToSimpleClass"
eType="ecore:EClass Simple.ecore#//SimpleClass" eOpposite="Simple.ecore#//SimpleClass/aReferenceToAnotherSimpleClass"/>
</eClassifiers>
</ecore:EPackage>
8 changes: 8 additions & 0 deletions edelta.parent/edelta.examples/modified/Simple.ecore
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="simple" nsURI="http://www.simple" nsPrefix="simple">
<eClassifiers xsi:type="ecore:EClass" name="SimpleClass">
<eStructuralFeatures xsi:type="ecore:EReference" name="aReferenceToAnotherSimpleClass"
eType="ecore:EClass AnotherSimple.ecore#//AnotherSimpleClass" eOpposite="AnotherSimple.ecore#//AnotherSimpleClass/aReferenceToSimpleClass"/>
</eClassifiers>
</ecore:EPackage>
@@ -0,0 +1,18 @@
package edelta.introducingdep.example;

import edelta.lib.AbstractEdelta;

public class IntroducingDepExampleMain {

public static void main(String[] args) throws Exception {
// Create an instance of the generated Java class
AbstractEdelta edelta = new IntroducingDepModifExample();
// Make sure you load all the used Ecores
edelta.loadEcoreFile("model/AnotherSimple.ecore");
edelta.loadEcoreFile("model/Simple.ecore");
// Execute the actual transformations defined in the DSL
edelta.execute();
// Save the modified Ecore model into a new path
edelta.saveModifiedEcores("modified");
}
}
@@ -0,0 +1,30 @@
package edelta.introducingdep.example

metamodel "anothersimple"

use IntroducingDepOpExample as extension operations

modifyEcore aModificationTest epackage anothersimple {
// the other file's operation will set the
// base class of this package class to another package class
ecoreref(AnotherSimpleClass).setBaseClass
// now anothersimple refers to simple (created dependency)

val referenceToSuperClass = ecoreref(AnotherSimpleClass).ESuperTypes.head

// also add a reference to the other epackage
ecoreref(AnotherSimpleClass)
.addNewEReference(
"aReferenceToSimpleClass",
referenceToSuperClass
)

// now modify the superclass in the other package
// introducing a mutual dependency
referenceToSuperClass
.addNewEReference("aReferenceToAnotherSimpleClass", ecoreref(AnotherSimpleClass)) [
// also make the references bidirectional
EOpposite = ecoreref(aReferenceToSimpleClass)
ecoreref(aReferenceToSimpleClass).EOpposite = it
]
}
@@ -0,0 +1,9 @@
import org.eclipse.emf.ecore.EClass

package edelta.introducingdep.example

metamodel "simple"

def setBaseClass(EClass c) : void {
c.getESuperTypes += ecoreref(SimpleClass)
}
@@ -0,0 +1,48 @@
package edelta.introducingdep.example.tests

import edelta.introducingdep.example.IntroducingDepModifExample
import edelta.testutils.EdeltaTestUtils
import org.junit.Test

class IntroducingDepExampleTest {

@Test
def void testIntroducingDep() {
// Create an instance of the generated Java class
val edelta = new IntroducingDepModifExample();
// Make sure you load all the used Ecores
edelta.loadEcoreFile("model/AnotherSimple.ecore");
edelta.loadEcoreFile("model/Simple.ecore");
// Execute the actual transformations defined in the DSL
edelta.execute();
// Save the modified Ecore model into a new path
edelta.saveModifiedEcores("modified");

EdeltaTestUtils.compareSingleFileContents(
"modified/Simple.ecore",
'''
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="simple" nsURI="http://www.simple" nsPrefix="simple">
<eClassifiers xsi:type="ecore:EClass" name="SimpleClass">
<eStructuralFeatures xsi:type="ecore:EReference" name="aReferenceToAnotherSimpleClass"
eType="ecore:EClass AnotherSimple.ecore#//AnotherSimpleClass" eOpposite="AnotherSimple.ecore#//AnotherSimpleClass/aReferenceToSimpleClass"/>
</eClassifiers>
</ecore:EPackage>
'''
)
EdeltaTestUtils.compareSingleFileContents(
"modified/AnotherSimple.ecore",
'''
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="anothersimple" nsURI="http://www.anothersimple" nsPrefix="anothersimple">
<eClassifiers xsi:type="ecore:EClass" name="AnotherSimpleClass" eSuperTypes="Simple.ecore#//SimpleClass">
<eStructuralFeatures xsi:type="ecore:EReference" name="aReferenceToSimpleClass"
eType="ecore:EClass Simple.ecore#//SimpleClass" eOpposite="Simple.ecore#//SimpleClass/aReferenceToAnotherSimpleClass"/>
</eClassifiers>
</ecore:EPackage>
'''
)
}
}
Expand Up @@ -1366,6 +1366,87 @@ class EdeltaCompilerTest extends EdeltaAbstractTest {
)
}
@Test
def void testExecutionOfModificationsOfMetamodelsAcrossSeveralFilesIntroducingMutualDepOnAnotherMetamodel() {
checkCompiledCodeExecutionWithSeveralFiles(
#[SIMPLE_ECORE, ANOTHER_SIMPLE_ECORE],
#[
'''
import org.eclipse.emf.ecore.EClass

package test1

metamodel "simple"

def setBaseClass(EClass c) : void {
c.getESuperTypes += ecoreref(SimpleClass)
}
''',
'''
import org.eclipse.emf.ecore.EClass
import test1.MyFile0

package test2

metamodel "anothersimple"

use test1.MyFile0 as extension my

modifyEcore aModificationTest epackage anothersimple {
// the other file's operation will set the
// base class of this package class to another package class
ecoreref(AnotherSimpleClass).setBaseClass
// now anothersimple refers to simple (created dependency)

val referenceToSuperClass = ecoreref(AnotherSimpleClass).ESuperTypes.head

// also add a reference to the other epackage
ecoreref(AnotherSimpleClass)
.addNewEReference(
"aReferenceToSimpleClass",
referenceToSuperClass
)

// now modify the superclass in the other package
// introducing a mutual dependency
referenceToSuperClass
.addNewEReference("aReferenceToAnotherSimpleClass", ecoreref(AnotherSimpleClass)) [
// also make the references bidirectional
EOpposite = ecoreref(aReferenceToSimpleClass)
ecoreref(aReferenceToSimpleClass).EOpposite = it
]
}
'''
],
"test2.MyFile1",
#[
SIMPLE_ECORE ->
'''
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="simple" nsURI="http://www.simple" nsPrefix="simple">
<eClassifiers xsi:type="ecore:EClass" name="SimpleClass">
<eStructuralFeatures xsi:type="ecore:EReference" name="aReferenceToAnotherSimpleClass"
eType="ecore:EClass AnotherSimple.ecore#//AnotherSimpleClass" eOpposite="AnotherSimple.ecore#//AnotherSimpleClass/aReferenceToSimpleClass"/>
</eClassifiers>
</ecore:EPackage>
''',
ANOTHER_SIMPLE_ECORE ->
'''
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="anothersimple" nsURI="http://www.anothersimple" nsPrefix="anothersimple">
<eClassifiers xsi:type="ecore:EClass" name="AnotherSimpleClass" eSuperTypes="Simple.ecore#//SimpleClass">
<eStructuralFeatures xsi:type="ecore:EReference" name="aReferenceToSimpleClass"
eType="ecore:EClass Simple.ecore#//SimpleClass" eOpposite="Simple.ecore#//SimpleClass/aReferenceToAnotherSimpleClass"/>
</eClassifiers>
</ecore:EPackage>
'''
],
true
)
}
@Test
def void testExecutionOfComplexOperationsWithSubPackages() {
'''
Expand Down

0 comments on commit 58edb7c

Please sign in to comment.