Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task 148 remove old methods from abstract edelta #149

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,6 @@ public void runInitializers() {
super.runInitializers();
}

@Override
public <E> List<E> createList(E e) {
return super.createList(e);
}

@Override
public <E> List<E> createList(E e1, E e2) {
return super.createList(e1, e2);
}

public void fooConsumer(EClass e) {

}
}

protected TestableEdelta edelta;
Expand Down Expand Up @@ -320,90 +307,6 @@ public void testSaveModifiedEcoresAfterRemovingBaseClass2() throws IOException {
MODIFIED+"/"+MY_ECORE);
}

@Test
public void testCreateEClass() {
loadTestEcore(MY_ECORE);
EPackage ePackage = edelta.getEPackage(MYPACKAGE);
assertNull(ePackage.getEClassifier("NewClass"));
EClass createEClass = edelta.createEClass(MYPACKAGE, "NewClass", null);
assertSame(createEClass, ePackage.getEClassifier("NewClass"));
}

@Test
public void testCreateEClassLaterInitialization() {
loadTestEcore(MY_ECORE);
// refers to an EClass that is created later
EClass newClass1 = edelta.createEClass(MYPACKAGE, "NewClass1",
edelta.createList(
c -> c.getESuperTypes().add(edelta.getEClass(MYPACKAGE, "NewClass2")),
c -> c.getESuperTypes().add(edelta.getEClass(MYPACKAGE, "NewClass3"))
)
);
EClass newClass2 = edelta.createEClass(MYPACKAGE, "NewClass2",
edelta.createList(edelta::fooConsumer));
EClass newClass3 = edelta.createEClass(MYPACKAGE, "NewClass3", null);
edelta.runInitializers();
assertSame(newClass2, newClass1.getESuperTypes().get(0));
assertSame(newClass3, newClass1.getESuperTypes().get(1));
}

@Test
public void testChangeEClass() {
loadTestEcore(MY_ECORE);
EPackage ePackage = edelta.getEPackage(MYPACKAGE);
assertNotNull(ePackage.getEClassifier(MY_CLASS));
EClass cl = edelta.changeEClass(MYPACKAGE, MY_CLASS, null);
assertSame(cl, ePackage.getEClassifier(MY_CLASS));
}

@Test
public void testChangeEClassLaterInitialization() {
loadTestEcore(MY_ECORE);
// refers to an EClass that is created later
EClass cl1 = edelta.changeEClass(MYPACKAGE, MY_CLASS,
edelta.createList(
c -> c.getESuperTypes().add(edelta.getEClass(MYPACKAGE, "NewClass2")),
c -> c.getESuperTypes().add(edelta.getEClass(MYPACKAGE, "NewClass3"))
)
);
EClass newClass2 = edelta.createEClass(MYPACKAGE, "NewClass2",
edelta.createList(edelta::fooConsumer));
EClass newClass3 = edelta.createEClass(MYPACKAGE, "NewClass3", null);
edelta.runInitializers();
assertSame(newClass2, cl1.getESuperTypes().get(0));
assertSame(newClass3, cl1.getESuperTypes().get(1));
}

@Test
public void testCreateEAttribute() {
loadTestEcore(MY_ECORE);
EPackage ePackage = edelta.getEPackage(MYPACKAGE);
EClass eClass = (EClass) ePackage.getEClassifier(MY_CLASS);
assertNull(eClass.getEStructuralFeature("newAttribute"));
EAttribute createEAttribute = edelta.createEAttribute(eClass, "newAttribute", null);
assertSame(createEAttribute, eClass.getEStructuralFeature("newAttribute"));
}

@Test
public void testCreateEAttributeLaterInitialization() {
loadTestEcore(MY_ECORE);
EPackage ePackage = edelta.getEPackage(MYPACKAGE);
EClass eClass = (EClass) ePackage.getEClassifier(MY_CLASS);
EAttribute createEAttribute1 = edelta.createEAttribute(eClass, "newAttribute",
edelta.createList(
a -> a.setName("newAttribute1"),
a -> edelta.getEAttribute(MYPACKAGE, MY_CLASS, "newAttribute2").setName("changed")
)
);
EAttribute createEAttribute2 = edelta.createEAttribute(eClass, "newAttribute2", null);
edelta.runInitializers();
// make sure the initializers have been called
// the second attribute must have a different name, changed
assertSame(createEAttribute2, edelta.getEAttribute(MYPACKAGE, MY_CLASS, "changed"));
// the same for the first attribute
assertSame(createEAttribute1, edelta.getEAttribute(MYPACKAGE, MY_CLASS, "newAttribute1"));
}

@Test
public void testRemoveEClassifier() {
loadTestEcore(MY_ECORE);
Expand Down
43 changes: 0 additions & 43 deletions edelta.parent/edelta.lib/src/edelta/lib/AbstractEdelta.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/**
*
*/
package edelta.lib;

import java.io.File;
Expand All @@ -11,7 +8,6 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map.Entry;
import java.util.function.Consumer;
import java.util.function.Supplier;

import org.apache.log4j.Level;
Expand All @@ -28,8 +24,6 @@
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.xtext.xbase.lib.Extension;

import com.google.common.collect.ImmutableList;

import edelta.lib.exception.EdeltaPackageNotLoadedException;

/**
Expand Down Expand Up @@ -288,43 +282,6 @@ public EEnumLiteral getEEnumLiteral(String packageName, String enumName, String
return eenum.getEEnumLiteral(enumLiteralName);
}

public EClass createEClass(String packageName, String name, final List<Consumer<EClass>> initializers) {
final EClass newEClass = lib.newEClass(name);
getEPackage(packageName).getEClassifiers().add(newEClass);
if (initializers != null)
initializers.forEach(i -> safeAddInitializer(eClassifierInitializers, newEClass, i));
return newEClass;
}

public EClass changeEClass(String packageName, String name, final List<Consumer<EClass>> initializers) {
final EClass changedEClass = getEClass(packageName, name);
if (initializers != null)
initializers.forEach(i -> safeAddInitializer(eClassifierInitializers, changedEClass, i));
return changedEClass;
}

protected <E> List<E> createList(E e) {
return ImmutableList.of(e);
}

protected <E> List<E> createList(E e1, E e2) {
return ImmutableList.of(e1, e2);
}

private <T> void safeAddInitializer(List<Runnable> list, final T element, final Consumer<T> initializer) {
list.add(
() -> initializer.accept(element)
);
}

public EAttribute createEAttribute(EClass eClass, String attributeName, final List<Consumer<EAttribute>> initializers) {
EAttribute newAttribute = lib.newEAttribute(attributeName);
eClass.getEStructuralFeatures().add(newAttribute);
if (initializers != null)
initializers.forEach(i -> safeAddInitializer(eStructuralFeaturesInitializers, newAttribute, i));
return newAttribute;
}

public void removeEClassifier(String packageName, String name) {
EdeltaEcoreUtil.removeEClassifier(getEClassifier(packageName, name));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,26 +67,6 @@ class EdeltaInterpreterTest extends EdeltaAbstractTest {
]
}

@Test
def void testCreateEClassAndCallJvmOperationFromSuperclass() {
'''
metamodel "foo"

modifyEcore aTest epackage foo {
addNewEClass("NewClass") [
// call method from superclass AbstractEdelta
EStructuralFeatures += ^createEAttribute(it, "aNewAttr", null)
]
}
'''.assertAfterInterpretationOfEdeltaModifyEcoreOperation[ePackage |
val derivedEClass = ePackage.lastEClass
assertEquals("NewClass", derivedEClass.name)
assertEquals(1, derivedEClass.EStructuralFeatures.size)
val attr = derivedEClass.EStructuralFeatures.head
assertEquals("aNewAttr", attr.name)
]
}

@Test
def void testCreateEClassAndCallOperationThatThrows() {
assertThatThrownBy['''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@ public EStructuralFeature myMethod() {
}

public EClass createANewEClass() {
return createEClass("foo", "ANewClass", null);
return lib.addNewEClass(getEPackage("foo"), "ANewClass");
}

public void createANewEAttribute(EClass c) {
EAttribute a = createEAttribute(c, "aNewAttr", null);
a.setEType(EcorePackage.eINSTANCE.getEString());
lib.addNewEAttribute(c, "aNewAttr", EcorePackage.eINSTANCE.getEString());
}

public void setAttributeBounds(EAttribute a, int low, int upper) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package edelta.tests.additional;

import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EcorePackage;

Expand All @@ -26,12 +25,12 @@ public MyCustomStatefulEdelta(AbstractEdelta other) {
}

public EClass createANewEClass() {
return createEClass("foo", "ANewClass" + (++counter), null);
return lib.addNewEClass(getEPackage("foo"), "ANewClass" + (++counter));
}

public void createANewEAttribute(EClass c) {
EAttribute a = createEAttribute(c, "aNewAttr" + (++counter), null);
a.setEType(EcorePackage.eINSTANCE.getEString());
lib.addNewEAttribute(c, "aNewAttr" + (++counter),
EcorePackage.eINSTANCE.getEString());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -89,38 +89,6 @@ public void testCreateEClassAndCallLibMethod() {
this.assertAfterInterpretationOfEdeltaModifyEcoreOperation(_builder, _function);
}

@Test
public void testCreateEClassAndCallJvmOperationFromSuperclass() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("metamodel \"foo\"");
_builder.newLine();
_builder.newLine();
_builder.append("modifyEcore aTest epackage foo {");
_builder.newLine();
_builder.append("\t");
_builder.append("addNewEClass(\"NewClass\") [");
_builder.newLine();
_builder.append("\t\t");
_builder.append("// call method from superclass AbstractEdelta");
_builder.newLine();
_builder.append("\t\t");
_builder.append("EStructuralFeatures += ^createEAttribute(it, \"aNewAttr\", null)");
_builder.newLine();
_builder.append("\t");
_builder.append("]");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final Procedure1<EPackage> _function = (EPackage ePackage) -> {
final EClass derivedEClass = this.getLastEClass(ePackage);
Assert.assertEquals("NewClass", derivedEClass.getName());
Assert.assertEquals(1, derivedEClass.getEStructuralFeatures().size());
final EStructuralFeature attr = IterableExtensions.<EStructuralFeature>head(derivedEClass.getEStructuralFeatures());
Assert.assertEquals("aNewAttr", attr.getName());
};
this.assertAfterInterpretationOfEdeltaModifyEcoreOperation(_builder, _function);
}

@Test
public void testCreateEClassAndCallOperationThatThrows() {
final ThrowableAssert.ThrowingCallable _function = () -> {
Expand Down