Skip to content

Commit

Permalink
Merge pull request #236 from LorenzoBettini/task_234-The_interpreter_…
Browse files Browse the repository at this point in the history
…should_never_use_original_elements

Task 234 the interpreter should never use original elements
  • Loading branch information
LorenzoBettini committed Aug 5, 2020
2 parents 4705ac1 + 58edb7c commit fd474c0
Show file tree
Hide file tree
Showing 29 changed files with 1,075 additions and 167 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 @@ -57,13 +57,30 @@ abstract class EdeltaAbstractTest {
protected static String PERSON_LIST_ECORE = "PersonList.ecore"
protected static String TEST1_REFS_ECORE = "TestEcoreForReferences1.ecore"
protected static String TEST2_REFS_ECORE = "TestEcoreForReferences2.ecore"
protected static String SIMPLE_ECORE = "Simple.ecore"
protected static String ANOTHER_SIMPLE_ECORE = "AnotherSimple.ecore"

/**
* Parse several input sources and returns the parsed program corresponding
* Parse several input sources using the "foo" EPackage
* and returns the parsed program corresponding
* to the last input source.
*/
def protected parseSeveralWithTestEcore(List<CharSequence> inputs) {
val rs = resourceSetWithTestEcore
parseSeveralInputs(inputs, rs)
}

/**
* Parse several input sources using the "foo" and "bar" EPackages
* and returns the parsed program corresponding
* to the last input source.
*/
def protected parseSeveralWithTestEcores(List<CharSequence> inputs) {
val rs = resourceSetWithTestEcores
parseSeveralInputs(inputs, rs)
}

protected def EdeltaProgram parseSeveralInputs(List<CharSequence> inputs, ResourceSet rs) {
var EdeltaProgram program
for (input : inputs)
program = input.parse(rs)
Expand Down

0 comments on commit fd474c0

Please sign in to comment.