Skip to content

Commit

Permalink
tests for personlist with modifyEcore
Browse files Browse the repository at this point in the history
  • Loading branch information
LorenzoBettini committed Dec 7, 2019
1 parent 51e18e3 commit e33d408
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 0 deletions.
107 changes: 107 additions & 0 deletions edelta.parent/edelta.tests/src/edelta/tests/EdeltaCompilerTest.xtend
Original file line number Diff line number Diff line change
Expand Up @@ -1222,6 +1222,113 @@ class EdeltaCompilerTest extends EdeltaAbstractTest {
)
}

@Test
def void testCompilationOfPersonListExampleModifyEcore() {
val rs = createResourceSetWithEcore(
PERSON_LIST_ECORE, PERSON_LIST_ECORE_PATH,
personListExampleModifyEcore
)
rs.
checkCompilation(
'''
package edelta;
import edelta.lib.AbstractEdelta;
import gssi.refactorings.MMrefactorings;
import java.util.Collections;
import java.util.function.Consumer;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
@SuppressWarnings("all")
public class Example extends AbstractEdelta {
private MMrefactorings refactorings;
public Example() {
refactorings = new MMrefactorings(this);
}
public Example(final AbstractEdelta other) {
super(other);
}
public void improvePerson(final EPackage it) {
final Procedure1<EClass> _function = (EClass it_1) -> {
this.refactorings.introduceSubclasses(
getEAttribute("PersonList", "Person", "gender"),
getEEnum("PersonList", "Gender"), it_1);
EList<EStructuralFeature> _eStructuralFeatures = it_1.getEStructuralFeatures();
EAttribute _mergeAttributes = this.refactorings.mergeAttributes("name",
getEAttribute("PersonList", "Person", "firstname").getEType(),
Collections.<EAttribute>unmodifiableList(CollectionLiterals.<EAttribute>newArrayList(getEAttribute("PersonList", "Person", "firstname"), getEAttribute("PersonList", "Person", "lastname"))));
_eStructuralFeatures.add(_mergeAttributes);
};
ObjectExtensions.<EClass>operator_doubleArrow(
getEClass("PersonList", "Person"), _function);
}
public void introducePlace(final EPackage it) {
final Consumer<EClass> _function = (EClass it_1) -> {
it_1.setAbstract(true);
this.refactorings.extractSuperclass(it_1,
Collections.<EAttribute>unmodifiableList(CollectionLiterals.<EAttribute>newArrayList(getEAttribute("PersonList", "LivingPlace", "address"), getEAttribute("PersonList", "WorkPlace", "address"))));
};
final EClass placeClass = this.lib.newEClass("Place", _function);
EList<EClassifier> _eClassifiers = it.getEClassifiers();
_eClassifiers.add(placeClass);
}
public void introduceWorkingPosition(final EPackage it) {
final Consumer<EClass> _function = (EClass it_1) -> {
EList<EStructuralFeature> _eStructuralFeatures = it_1.getEStructuralFeatures();
final Consumer<EAttribute> _function_1 = (EAttribute it_2) -> {
it_2.setEType(getEDataType("ecore", "EString"));
};
EAttribute _newEAttribute = this.lib.newEAttribute("description", _function_1);
_eStructuralFeatures.add(_newEAttribute);
this.refactorings.extractMetaClass(it_1,
getEReference("PersonList", "Person", "works"), "position", "works");
};
final EClass workingPositionClass = this.lib.newEClass("WorkingPosition", _function);
EList<EClassifier> _eClassifiers = it.getEClassifiers();
_eClassifiers.add(workingPositionClass);
}
public void improveList(final EPackage it) {
EList<EStructuralFeature> _eStructuralFeatures = getEClass("PersonList", "List").getEStructuralFeatures();
EReference _mergeReferences = this.refactorings.mergeReferences("places",
getEClass("PersonList", "Place"),
Collections.<EReference>unmodifiableList(CollectionLiterals.<EReference>newArrayList(getEReference("PersonList", "List", "wplaces"), getEReference("PersonList", "List", "lplaces"))));
_eStructuralFeatures.add(_mergeReferences);
}
@Override
public void performSanityChecks() throws Exception {
ensureEPackageIsLoaded("PersonList");
ensureEPackageIsLoaded("ecore");
}
@Override
protected void doExecute() throws Exception {
improvePerson(getEPackage("PersonList"));
introducePlace(getEPackage("PersonList"));
introduceWorkingPosition(getEPackage("PersonList"));
improveList(getEPackage("PersonList"));
}
}
''',
true
)
}

def private checkCompilation(CharSequence input, CharSequence expectedGeneratedJava) {
checkCompilation(input, expectedGeneratedJava, true)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,14 @@ class EdeltaDerivedStateComputerTest extends EdeltaAbstractTest {
prog.assertNoErrors
}

@Test
def void testPersonListExampleModifyEcore() {
val prog = parseWithLoadedEcore(PERSON_LIST_ECORE_PATH,
personListExampleModifyEcore
)
prog.assertNoErrors
}

protected def EdeltaEcoreQualifiedReference getEcoreRefInManipulationExpressionBlock(EdeltaProgram program) {
program.lastExpression.getManipulationEClassExpression.body.expressions.head.
variableDeclaration.right.
Expand Down
54 changes: 54 additions & 0 deletions edelta.parent/edelta.tests/src/edelta/tests/input/Inputs.xtend
Original file line number Diff line number Diff line change
Expand Up @@ -444,4 +444,58 @@ class Inputs {
}
'''
def personListExampleModifyEcore()
'''
import gssi.refactorings.MMrefactorings

metamodel "PersonList"
metamodel "ecore"

use MMrefactorings as refactorings

modifyEcore improvePerson epackage PersonList {
ecoreref(PersonList.Person) => [
refactorings.
introduceSubclasses(
ecoreref(Person.gender),
ecoreref(Gender),
it
)
EStructuralFeatures+=
refactorings.mergeAttributes("name",
ecoreref(Person.firstname).EType,
#[ecoreref(Person.firstname), ecoreref(Person.lastname)]
)
]
}

modifyEcore introducePlace epackage PersonList {
val placeClass = newEClass("Place") [
abstract = true
refactorings.extractSuperclass(it,
#[ecoreref(LivingPlace.address), ecoreref(WorkPlace.address)]);
]
EClassifiers += placeClass
}

modifyEcore introduceWorkingPosition epackage PersonList {
val workingPositionClass = newEClass("WorkingPosition") [
EStructuralFeatures += newEAttribute("description") [
EType = ecoreref(EString)
]
refactorings.extractMetaClass(it,
ecoreref(Person.works), "position", "works"
);
]
EClassifiers += workingPositionClass
}

modifyEcore improveList epackage PersonList {
ecoreref(PersonList.List).EStructuralFeatures+=
refactorings.mergeReferences("places",
ecoreref(Place),
#[ecoreref(List.wplaces), ecoreref(List.lplaces)]
);
}
'''
}

0 comments on commit e33d408

Please sign in to comment.