Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
234: example and test introducing mutual dep
- Loading branch information
1 parent
59f3238
commit 58edb7c
Showing
13 changed files
with
438 additions
and
2 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
.../edelta.examples/edelta-gen/edelta/introducingdep/example/IntroducingDepModifExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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")); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...ent/edelta.examples/edelta-gen/edelta/introducingdep/example/IntroducingDepOpExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
18 changes: 18 additions & 0 deletions
18
...a.parent/edelta.examples/src/edelta/introducingdep/example/IntroducingDepExampleMain.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...arent/edelta.examples/src/edelta/introducingdep/example/IntroducingDepModifExample.edelta
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
] | ||
} |
9 changes: 9 additions & 0 deletions
9
...a.parent/edelta.examples/src/edelta/introducingdep/example/IntroducingDepOpExample.edelta
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
48 changes: 48 additions & 0 deletions
48
...edelta.examples/tests/edelta/introducingdep/example/tests/IntroducingDepExampleTest.xtend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> | ||
''' | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.