Skip to content

Commit

Permalink
Merge pull request #114 from LorenzoBettini/task_104-Remove_old_syntax2
Browse files Browse the repository at this point in the history
Task 104 remove old syntax2
  • Loading branch information
LorenzoBettini committed Jan 24, 2020
2 parents fa7e73a + 136720e commit 0a8ea61
Show file tree
Hide file tree
Showing 27 changed files with 63 additions and 755 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import edelta.lib.AbstractEdelta;
import edelta.refactorings.lib.EdeltaRefactorings;
import java.util.function.Consumer;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.xtext.xbase.lib.Extension;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
Expand All @@ -30,6 +32,16 @@ public EClass createClass(final String name) {
return ObjectExtensions.<EClass>operator_doubleArrow(_newEClass, _function);
}

public void aModification(final EPackage it) {
final Consumer<EClass> _function = (EClass it_1) -> {
this.refactorings.addMandatoryAttr(it_1, "ANewAttribute", getEDataType("ecore", "EString"));
getEAttribute("myecore", "MyNewClass", "ANewAttribute").setEType(getEDataType("ecore", "EInt"));
};
this.lib.addNewEClass(it, "MyNewClass", _function);
this.lib.addEClass(it, this.createClass("ANewDerivedEClass"));
getEClass("myecore", "ANewDerivedEClass").setAbstract(true);
}

@Override
public void performSanityChecks() throws Exception {
ensureEPackageIsLoaded("myecore");
Expand All @@ -38,15 +50,6 @@ public void performSanityChecks() throws Exception {

@Override
protected void doExecute() throws Exception {
createEClass("myecore", "MyNewClass", createList(this::_createEClass_MyNewClass_in_myecore));
}

public void _createEClass_MyNewClass_in_myecore(final EClass it) {
{
this.refactorings.addMandatoryAttr(it, "ANewAttribute", getEDataType("ecore", "EString"));
getEAttribute("myecore", "MyNewClass", "ANewAttribute").setEType(getEDataType("ecore", "EInt"));
this.lib.addEClass(it.getEPackage(), this.createClass("ANewDerivedEClass"));
getEClass("myecore", "ANewDerivedEClass").setAbstract(true);
}
aModification(getEPackage("myecore"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import edelta.refactorings.lib.EdeltaRefactorings

// IMPORTANT: ecores must be in a source directory
// otherwise you can't refer to them

package com.example

metamodel "myecore"
Expand All @@ -16,12 +15,14 @@ def createClass(String name) {
]
}

createEClass MyNewClass in myecore {
// using 'extension'
addMandatoryAttr("ANewAttribute", ecoreref(EString))
// corresponds to refactorings.addMandatoryAttr(it, "ANewAttribute", ecoreref(EString))
ecoreref(ANewAttribute).setEType(ecoreref(EInt))
EPackage.addEClass(createClass("ANewDerivedEClass"))
ecoreref(ANewDerivedEClass).setAbstract(true)
modifyEcore aModification epackage myecore {
addNewEClass("MyNewClass") [
// using 'extension' from EdeltaRefactorings
addMandatoryAttr("ANewAttribute", ecoreref(EString))
// corresponds to refactorings.addMandatoryAttr(it, "ANewAttribute", ecoreref(EString))
ecoreref(ANewAttribute).EType = ecoreref(EInt)
]
addEClass(createClass("ANewDerivedEClass"))
ecoreref(ANewDerivedEClass).abstract = true
}

Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public void testProjectWithErrorFailOnValidationErrorFalse() throws Exception {
assertThat(outputDirectory).exists();

verify(spiedLog)
.error(contains("ERROR:The method or field foobar is undefined"));
.error(contains("ERROR:extraneous input 'foobar' expecting EOF"));
}

@Test
Expand Down
34 changes: 20 additions & 14 deletions edelta.parent/edelta.tests/edelta.tests.launch
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.jdt.junit.launchconfig">
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/edelta.tests"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="4"/>
</listAttribute>
<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value="=edelta.tests"/>
<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"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value=""/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="edelta.tests"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-ea"/>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/edelta.tests"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="4"/>
</listAttribute>
<listAttribute key="org.eclipse.eclemma.core.SCOPE_IDS">
<listEntry value="=edelta/src"/>
<listEntry value="=edelta/xtend-gen"/>
</listAttribute>
<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value="=edelta.tests"/>
<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"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/>
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.m2e.launchconfig.classpathProvider"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value=""/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="edelta.tests"/>
<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>
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ package edelta.tests

import com.google.inject.Inject
import com.google.inject.Provider
import edelta.edelta.EdeltaEcoreBaseEClassManipulationWithBlockExpression
import edelta.edelta.EdeltaEcoreChangeEClassExpression
import edelta.edelta.EdeltaEcoreCreateEAttributeExpression
import edelta.edelta.EdeltaEcoreCreateEClassExpression
import edelta.edelta.EdeltaEcoreDirectReference
import edelta.edelta.EdeltaEcoreQualifiedReference
import edelta.edelta.EdeltaEcoreReferenceExpression
Expand Down Expand Up @@ -208,30 +204,10 @@ abstract class EdeltaAbstractTest {
findFirst[name == classifiername]
}

def protected lastExpression(EdeltaProgram p) {
p.main.expressions.last
}

def protected lastModifyEcoreOperation(EdeltaProgram p) {
p.modifyEcoreOperations.last
}

def protected getCreateEClassExpression(XExpression e) {
e as EdeltaEcoreCreateEClassExpression
}

def protected getChangeEClassExpression(XExpression e) {
e as EdeltaEcoreChangeEClassExpression
}

def protected getManipulationEClassExpression(XExpression e) {
e as EdeltaEcoreBaseEClassManipulationWithBlockExpression
}

def protected getCreateEAttributExpression(XExpression e) {
e as EdeltaEcoreCreateEAttributeExpression
}

def protected getDerivedStateLastEClass(EObject context) {
val derivedEPackage = getDerivedStateLastEPackage(context)
derivedEPackage.EClassifiers.last as EClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,24 @@ import org.junit.Test
import org.junit.runner.RunWith

import static extension org.junit.Assert.*
import org.eclipse.emf.ecore.EcoreFactory

@RunWith(XtextRunner)
@InjectWith(EdeltaInjectorProviderCustom)
class EdeltaCompilerUtilTest extends EdeltaAbstractTest {

@Inject extension EdeltaCompilerUtil

@Test
def void testGetEPackageNameOrNull() {
val factory = EcoreFactory.eINSTANCE
null.EPackageNameOrNull.assertNull
val p = factory.createEPackage => [
name = "test"
]
"test".assertEquals(p.EPackageNameOrNull)
}

@Test
def void testGetStringForEcoreReferenceExpressionEClass() {
'''ecoreref(FooClass)'''.ecoreReferenceExpression => [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
package edelta.tests

import com.google.inject.Inject
import edelta.edelta.EdeltaFactory
import edelta.interpreter.EdeltaInterpreterHelper
import edelta.interpreter.EdeltaSafeInterpreter
import edelta.lib.AbstractEdelta
import edelta.tests.additional.MyCustomEdelta
import org.eclipse.emf.ecore.EcoreFactory
import org.eclipse.emf.ecore.EcorePackage
import edelta.tests.additional.MyCustomEdeltaThatCannotBeLoadedAtRuntime
import org.eclipse.xtext.common.types.util.JavaReflectAccess
import org.eclipse.xtext.testing.InjectWith
import org.eclipse.xtext.testing.XtextRunner
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith

import static org.assertj.core.api.Assertions.*
import static org.junit.Assert.*
import edelta.tests.additional.MyCustomEdeltaThatCannotBeLoadedAtRuntime
import edelta.lib.AbstractEdelta
import org.junit.Before

@RunWith(XtextRunner)
@InjectWith(EdeltaInjectorProviderForJavaReflectAccess)
Expand Down Expand Up @@ -83,31 +80,6 @@ class EdeltaInterpreterHelperTest extends EdeltaAbstractTest {
]
}

@Test
def void testSafeSetEAttributeType() {
val attr = EcoreFactory.eINSTANCE.createEAttribute
interpreterHelper.safeSetEAttributeType(attr,
EdeltaFactory.eINSTANCE.createEdeltaEcoreDirectReference => [
// something that is not an EClassifier
enamedelement = EcoreFactory.eINSTANCE.createEReference
]
)
assertNull(attr.EType)
interpreterHelper.safeSetEAttributeType(attr,
EdeltaFactory.eINSTANCE.createEdeltaEcoreDirectReference => [
enamedelement = EcorePackage.eINSTANCE.EString
]
)
assertEquals(EcorePackage.eINSTANCE.EString, attr.EType)
}

@Test
def void testSafeSetEAttributeTypeWithNullType() {
val attr = EcoreFactory.eINSTANCE.createEAttribute
interpreterHelper.safeSetEAttributeType(attr, null)
assertNull(attr.EType)
}

@Test
def void testSafeInstantiateOfUnresolvedUseAsType() {
assertThatThrownBy[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
import java.util.List;
import java.util.Map;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.xtext.common.types.JvmGenericType;

import edelta.edelta.EdeltaEcoreBaseEClassManipulationWithBlockExpression;
import edelta.edelta.EdeltaModifyEcoreOperation;
import edelta.resource.EdeltaDerivedStateComputer;

Expand All @@ -25,13 +23,6 @@
*/
public class EdeltaDerivedStateComputerWithoutInterpreter extends EdeltaDerivedStateComputer {

@Override
protected void runInterpreter(List<? extends EdeltaEcoreBaseEClassManipulationWithBlockExpression> expressions,
Map<EdeltaEcoreBaseEClassManipulationWithBlockExpression, EClass> opToEClassMap,
JvmGenericType jvmGenericType, List<EPackage> packages) {
// No interpreter is run
}

@Override
protected void runInterpreter(EdeltaModifyEcoreOperation o, Map<String, EPackage> nameToCopiedEPackageMap,
JvmGenericType programJvmType, List<EPackage> packages) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package edelta.tests.additional

import com.google.inject.Singleton
import edelta.resource.EdeltaDerivedStateComputer
import java.util.Collection
import java.util.Map
import org.eclipse.emf.ecore.EClass
import org.eclipse.emf.ecore.EPackage
import org.eclipse.emf.ecore.resource.Resource

Expand All @@ -25,10 +23,6 @@ class TestableEdeltaDerivedStateComputer extends EdeltaDerivedStateComputer {
super.unloadDerivedPackages(nameToEPackageMap)
}

override derivedToSourceMap(Resource resource) {
super.derivedToSourceMap(resource)
}

override nameToEPackageMap(Resource resource) {
super.nameToEPackageMap(resource)
}
Expand All @@ -37,19 +31,11 @@ class TestableEdeltaDerivedStateComputer extends EdeltaDerivedStateComputer {
super.nameToCopiedEPackageMap(resource)
}

override opToEClassMap(Resource resource) {
super.opToEClassMap(resource)
}

override protected getOrAddDerivedStateEPackage(EPackage referredEPackage, Map<String, EPackage> nameToEPackageMap,
Map<String, EPackage> nameToCopiedEPackageMap) {
val result = super.getOrAddDerivedStateEPackage(referredEPackage, nameToEPackageMap, nameToCopiedEPackageMap)
referredEPackage.eAdapters += new EdeltaEContentAdapter
return result
}

override getEClassWithTheSameName(Collection<EPackage> packages, EClass original) {
super.getEClassWithTheSameName(packages, original)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
package edelta.ui.outline

import com.google.inject.Inject
import edelta.edelta.EdeltaMain
import edelta.edelta.EdeltaModifyEcoreOperation
import edelta.edelta.EdeltaOperation
import edelta.edelta.EdeltaProgram
import edelta.services.IEdeltaEcoreModelAssociations
import org.eclipse.xtext.ui.editor.outline.IOutlineNode
import org.eclipse.xtext.ui.editor.outline.impl.DefaultOutlineTreeProvider
import edelta.edelta.EdeltaModifyEcoreOperation

/**
* Customization of the default outline structure.
Expand All @@ -28,7 +27,6 @@ class EdeltaOutlineTreeProvider extends DefaultOutlineTreeProvider {
for (o : p.modifyEcoreOperations) {
createNode(parentNode, o)
}
createNode(parentNode, p.main)
for (derived : p.eResource.copiedEPackages) {
// the cool thing is that we don't need to provide
// customization in the label provider for EPackage and EClass
Expand All @@ -45,7 +43,4 @@ class EdeltaOutlineTreeProvider extends DefaultOutlineTreeProvider {
true
}

def _isLeaf(EdeltaMain m) {
true
}
}
27 changes: 0 additions & 27 deletions edelta.parent/edelta/model/custom/Edelta.ecore
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
eType="#//EdeltaOperation" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="modifyEcoreOperations"
upperBound="-1" eType="#//EdeltaModifyEcoreOperation" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="main" eType="ecore:EClass ../../../org.eclipse.xtext.xbase/model/Xbase.ecore#//XBlockExpression"
containment="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="EdeltaOperation">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType ../../../org.eclipse.emf.ecore/model/Ecore.ecore#//EString"/>
Expand All @@ -34,37 +32,12 @@
<eStructuralFeatures xsi:type="ecore:EReference" name="information" eType="#//EdeltaEcoreReferenceInformation"
containment="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="EdeltaMain" eSuperTypes="../../../org.eclipse.xtext.xbase/model/Xbase.ecore#//XBlockExpression"/>
<eClassifiers xsi:type="ecore:EClass" name="EdeltaModifyEcoreOperation">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType ../../../org.eclipse.emf.ecore/model/Ecore.ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="epackage" eType="ecore:EClass ../../../org.eclipse.emf.ecore/model/Ecore.ecore#//EPackage"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="body" eType="ecore:EClass ../../../org.eclipse.xtext.xbase/model/Xbase.ecore#//XExpression"
containment="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="EdeltaEcoreBaseManipulationWithBlockExpression"
eSuperTypes="../../../org.eclipse.xtext.xbase/model/Xbase.ecore#//XExpression">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType ../../../org.eclipse.emf.ecore/model/Ecore.ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="body" eType="ecore:EClass ../../../org.eclipse.xtext.xbase/model/Xbase.ecore#//XBlockExpression"
containment="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="EdeltaEcoreBaseEClassManipulationWithBlockExpression"
eSuperTypes="#//EdeltaEcoreBaseManipulationWithBlockExpression">
<eStructuralFeatures xsi:type="ecore:EReference" name="epackage" eType="ecore:EClass ../../../org.eclipse.emf.ecore/model/Ecore.ecore#//EPackage"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="EdeltaEcoreCreateEClassExpression" eSuperTypes="#//EdeltaEcoreBaseEClassManipulationWithBlockExpression">
<eStructuralFeatures xsi:type="ecore:EReference" name="ecoreReferenceSuperTypes"
upperBound="-1" eType="#//EdeltaEcoreReference" containment="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="EdeltaEcoreChangeEClassExpression" eSuperTypes="#//EdeltaEcoreBaseEClassManipulationWithBlockExpression">
<eStructuralFeatures xsi:type="ecore:EReference" name="original" eType="ecore:EClass ../../../org.eclipse.emf.ecore/model/Ecore.ecore#//EClass"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="EdeltaEcoreManipulationBlockExpression"
eSuperTypes="../../../org.eclipse.xtext.xbase/model/Xbase.ecore#//XBlockExpression"/>
<eClassifiers xsi:type="ecore:EClass" name="EdeltaEcoreCreateEAttributeExpression"
eSuperTypes="#//EdeltaEcoreBaseManipulationWithBlockExpression">
<eStructuralFeatures xsi:type="ecore:EReference" name="ecoreReferenceDataType"
eType="#//EdeltaEcoreReference" containment="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="EdeltaEcoreReferenceExpression" eSuperTypes="../../../org.eclipse.xtext.xbase/model/Xbase.ecore#//XExpression">
<eStructuralFeatures xsi:type="ecore:EReference" name="reference" eType="#//EdeltaEcoreReference"
containment="true"/>
Expand Down
Loading

0 comments on commit 0a8ea61

Please sign in to comment.