Skip to content

Commit

Permalink
Merge 2e48cab into fa7e73a
Browse files Browse the repository at this point in the history
  • Loading branch information
LorenzoBettini committed Jan 24, 2020
2 parents fa7e73a + 2e48cab commit 5c17b28
Show file tree
Hide file tree
Showing 25 changed files with 59 additions and 696 deletions.
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"));
}
}
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
}

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
@@ -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>
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
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
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
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)
}

}
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
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
19 changes: 0 additions & 19 deletions edelta.parent/edelta/model/custom/Edelta.genmodel
Expand Up @@ -13,7 +13,6 @@
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference Edelta.ecore#//EdeltaProgram/useAsClauses"/>
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference Edelta.ecore#//EdeltaProgram/operations"/>
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference Edelta.ecore#//EdeltaProgram/modifyEcoreOperations"/>
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference Edelta.ecore#//EdeltaProgram/main"/>
</genClasses>
<genClasses ecoreClass="Edelta.ecore#//EdeltaOperation">
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute Edelta.ecore#//EdeltaOperation/name"/>
Expand All @@ -26,29 +25,11 @@
<genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference Edelta.ecore#//EdeltaEcoreReference/originalEnamedelement"/>
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference Edelta.ecore#//EdeltaEcoreReference/information"/>
</genClasses>
<genClasses ecoreClass="Edelta.ecore#//EdeltaMain"/>
<genClasses ecoreClass="Edelta.ecore#//EdeltaModifyEcoreOperation">
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute Edelta.ecore#//EdeltaModifyEcoreOperation/name"/>
<genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference Edelta.ecore#//EdeltaModifyEcoreOperation/epackage"/>
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference Edelta.ecore#//EdeltaModifyEcoreOperation/body"/>
</genClasses>
<genClasses ecoreClass="Edelta.ecore#//EdeltaEcoreBaseManipulationWithBlockExpression">
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute Edelta.ecore#//EdeltaEcoreBaseManipulationWithBlockExpression/name"/>
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference Edelta.ecore#//EdeltaEcoreBaseManipulationWithBlockExpression/body"/>
</genClasses>
<genClasses ecoreClass="Edelta.ecore#//EdeltaEcoreBaseEClassManipulationWithBlockExpression">
<genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference Edelta.ecore#//EdeltaEcoreBaseEClassManipulationWithBlockExpression/epackage"/>
</genClasses>
<genClasses ecoreClass="Edelta.ecore#//EdeltaEcoreCreateEClassExpression">
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference Edelta.ecore#//EdeltaEcoreCreateEClassExpression/ecoreReferenceSuperTypes"/>
</genClasses>
<genClasses ecoreClass="Edelta.ecore#//EdeltaEcoreChangeEClassExpression">
<genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference Edelta.ecore#//EdeltaEcoreChangeEClassExpression/original"/>
</genClasses>
<genClasses ecoreClass="Edelta.ecore#//EdeltaEcoreManipulationBlockExpression"/>
<genClasses ecoreClass="Edelta.ecore#//EdeltaEcoreCreateEAttributeExpression">
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference Edelta.ecore#//EdeltaEcoreCreateEAttributeExpression/ecoreReferenceDataType"/>
</genClasses>
<genClasses ecoreClass="Edelta.ecore#//EdeltaEcoreReferenceExpression">
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference Edelta.ecore#//EdeltaEcoreReferenceExpression/reference"/>
</genClasses>
Expand Down

0 comments on commit 5c17b28

Please sign in to comment.