Skip to content

Commit

Permalink
Add enum parameters by changing to EClassifier (#107)
Browse files Browse the repository at this point in the history
Co-authored-by: Thomas Weber <[email protected]>
  • Loading branch information
AndiMachtSachen and TomWerm authored Mar 5, 2024
1 parent a0c3c06 commit 3ed5ae4
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="MetaclassReference">
<eStructuralFeatures xsi:type="ecore:EReference" name="metamodel" eType="#//MetamodelImport"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="metaclass" eType="ecore:EClass ../../org.eclipse.emf.ecore/model/Ecore.ecore#//EClass"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="metaclass" eType="ecore:EClass ../../org.eclipse.emf.ecore/model/Ecore.ecore#//EClassifier"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="NamedMetaclassReference" eSuperTypes="#//MetaclassReference">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
Expand All @@ -22,11 +22,4 @@
<eClassifiers xsi:type="ecore:EClass" name="MetaclassEReferenceReference" eSuperTypes="#//MetaclassReference">
<eStructuralFeatures xsi:type="ecore:EReference" name="feature" eType="ecore:EClass ../../org.eclipse.emf.ecore/model/Ecore.ecore#//EReference"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="MetaenumReference">
<eStructuralFeatures xsi:type="ecore:EReference" name="metamodel" eType="#//MetamodelImport"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="metaenum" eType="ecore:EClass ../../org.eclipse.emf.ecore/model/Ecore.ecore#//EEnum"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="NamedMetaenumReference" eSuperTypes="#//MetaenumReference">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType ../../org.eclipse.emf.ecore/model/Ecore.ecore#//EString"/>
</eClassifiers>
</ecore:EPackage>
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,16 @@ class CommonLanguageElementsScopeProvider {
if (reference.equals(METAMODEL_IMPORT__PACKAGE)) {
return packagesScope.get()
} else if (reference.equals(METACLASS_FEATURE_REFERENCE__FEATURE)) {
return createEStructuralFeatureScope((context as MetaclassFeatureReference)?.metaclass)
return createEStructuralFeatureScope((context as MetaclassFeatureReference)?.metaclass as EClass)
} else if (reference.equals(METACLASS_EATTRIBUTE_REFERENCE__FEATURE)) {
return createEAttributeScope((context as MetaclassEAttributeReference)?.metaclass)
return createEAttributeScope((context as MetaclassEAttributeReference)?.metaclass as EClass)
} else if (reference.equals(METACLASS_EREFERENCE_REFERENCE__FEATURE)) {
return createEReferenceScope((context as MetaclassEReferenceReference)?.metaclass)
return createEReferenceScope((context as MetaclassEReferenceReference)?.metaclass as EClass)
} else if (reference.equals(METACLASS_REFERENCE__METAMODEL)) {
return createImportsScope(context.eResource)
} else if (reference.equals(METACLASS_REFERENCE__METACLASS)) {
val potentialMetaclassReference = if(context instanceof MetaclassReference) context
return createQualifiedEClassifierScope(potentialMetaclassReference?.metamodel)
} else if (reference.equals(METAENUM_REFERENCE__METAMODEL)) {
return createImportsScope(context.eResource)
} else if (reference.equals(METAENUM_REFERENCE__METAENUM)) {
val potentialMetaenumReference = if(context instanceof MetaenumReference) context
return createQualifiedEClassifierScope(potentialMetaenumReference?.metamodel, false, null, EcorePackage.Literals.EENUM)
}
return null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ routine changeFamilyName(families::Family family){

// Checks whether the member was actually just created (has no corresponding person) or not.
// Only continues if member is a newly created member.
routine tryCreateInsuranceClientFromNewMember(families::Member newMember, families::Family family, enum insurance::Gender gender) {
routine tryCreateInsuranceClientFromNewMember(families::Member newMember, families::Family family, insurance::Gender gender) {
match {
require absence of insurance::InsuranceClient corresponding to newMember
}
Expand All @@ -118,7 +118,7 @@ routine tryCreateInsuranceClientFromNewMember(families::Member newMember, famili
}

// Creates corresponding insurance client and sets up correspondences
routine createInsuranceClient(families::Member newMember, families::Family family, enum insurance::Gender gender) {
routine createInsuranceClient(families::Member newMember, families::Family family, insurance::Gender gender) {
match {
check { assertValidFirstname(newMember) true }
val insuranceDatabase = retrieve insurance::InsuranceDatabase corresponding to family.register
Expand All @@ -140,7 +140,7 @@ routine createInsuranceClient(families::Member newMember, families::Family famil

// Checks if member already existed (as expected gender), and breaks if not
// Updates name and correspondences
routine updateNameAndCorrespondencesOfCorrespondingInsuranceClient(families::Member newMember, families::Family newFamily, enum insurance::Gender gender) {
routine updateNameAndCorrespondencesOfCorrespondingInsuranceClient(families::Member newMember, families::Family newFamily, insurance::Gender gender) {
match {
val correspondingInsuranceClient = retrieve insurance::InsuranceClient corresponding to newMember with {
assertGender(it, gender) true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@
containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="javaInputElements" upperBound="-1"
eType="#//NamedJavaElementReference" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="enumInputElements" upperBound="-1"
eType="ecore:EClass ../../tools.vitruv.dsls.common/model/CommonLanguageElements.ecore#//NamedMetaenumReference"
containment="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="MatchBlock">
<eStructuralFeatures xsi:type="ecore:EReference" name="matchStatements" upperBound="-1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ RoutineOverrideImportPath returns toplevelelements::RoutineOverrideImportPath:

RoutineInput returns toplevelelements::RoutineInput:
{toplevelelements::RoutineInput}
'(' ((modelInputElements+=NamedMetaclassReference | "plain" javaInputElements+=NamedJavaElementReference | "enum" enumInputElements+=NamedMetaenumReference)
(',' (modelInputElements+=NamedMetaclassReference | "plain" javaInputElements+=NamedJavaElementReference | "enum" enumInputElements+=NamedMetaenumReference))*)? ')';
'(' ((modelInputElements+=NamedMetaclassReference | "plain" javaInputElements+=NamedJavaElementReference)
(',' (modelInputElements+=NamedMetaclassReference | "plain" javaInputElements+=NamedJavaElementReference))*)? ')';

// *********** MATCH ***********
MatchBlock returns toplevelelements::MatchBlock:
Expand Down Expand Up @@ -178,7 +178,7 @@ UpdateBlock returns toplevelelements::UpdateBlock:

// ****** CODE BLOCKS ******
fragment MetaclassReference returns common::MetaclassReference:
(metamodel=[common::MetamodelImport] '::')? metaclass=[ecore::EClass|QualifiedName];
(metamodel=[common::MetamodelImport] '::')? metaclass=[ecore::EClassifier|QualifiedName];

UnnamedMetaclassReference returns common::MetaclassReference:
MetaclassReference;
Expand All @@ -195,8 +195,3 @@ MetaclassEAttributeReference returns common::MetaclassEAttributeReference:
MetaclassEReferenceReference returns common::MetaclassEReferenceReference:
MetaclassReference '[' feature=[ecore::EReference|ValidID] ']';

fragment MetaenumReference returns common::MetaenumReference:
(metamodel=[common::MetamodelImport] '::')? metaenum=[ecore::EEnum|QualifiedName];

NamedMetaenumReference returns common::NamedMetaenumReference:
MetaenumReference name=ValidID;
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import tools.vitruv.dsls.reactions.builder.FluentRoutineBuilder.InputBuilder
import tools.vitruv.dsls.reactions.language.toplevelelements.Reaction
import tools.vitruv.dsls.reactions.language.toplevelelements.Routine
import tools.vitruv.dsls.reactions.language.toplevelelements.TopLevelElementsFactory
import org.eclipse.emf.ecore.EClass

/**
* Entry point for fluent reaction builders. The offered methods each create a
Expand Down Expand Up @@ -74,7 +75,7 @@ class FluentReactionsLanguageBuilder {
val contents = EcoreUtil.getAllContents(#[routine])
contents.filter[it instanceof MetaclassReference].forEach [
val ref = it as MetaclassReference
ref.reference(ref.metaclass)
ref.reference(ref.metaclass as EClass)
]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ final class ChangeTypeRepresentationExtractor {
if (modelElementChange?.changeType === null) {
return new ChangeTypeRepresentation(GENERAL_CHANGE_NAME, EChange, null, null, false, false, null, false)
} else {
return generateChangeTypeRepresentation(modelElementChange.changeType, modelElementChange.elementType?.metaclass)
return generateChangeTypeRepresentation(modelElementChange.changeType, modelElementChange.elementType?.metaclass as EClass)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class RoutineClassGenerator extends ClassGenerator {
this.routine = routine
this.routineClassNameGenerator = routine.routineClassNameGenerator
this.routinesFacadeQualifiedName = routine.reactionsSegment.routinesFacadeClassNameGenerator.qualifiedName
this.inputElements = getInputElements(routine.input.modelInputElements, routine.input.javaInputElements, routine.input.enumInputElements)
this.inputElements = getInputElements(routine.input.modelInputElements, routine.input.javaInputElements)
this.inputValuesClass = if (hasInputValues) {
generateElementsContainerClass(INPUT_VALUES_SIMPLE_CLASS_NAME, inputElements)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class RoutineFacadeClassGenerator extends ClassGenerator {
}

private def Iterable<JvmFormalParameter> getInputElementsParameter(Routine routine) {
routine.generateParameters(getInputElements(routine.input.modelInputElements, routine.input.javaInputElements, routine.input.enumInputElements))
routine.generateParameters(getInputElements(routine.input.modelInputElements, routine.input.javaInputElements))
}

protected def StringConcatenationClient generateGetOwnRoutinesFacade() '''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import static extension tools.vitruv.dsls.reactions.codegen.helper.ReactionsLang
import tools.vitruv.dsls.reactions.codegen.helper.AccessibleElement
import tools.vitruv.dsls.reactions.language.toplevelelements.NamedJavaElementReference
import tools.vitruv.dsls.common.elements.NamedMetaclassReference
import tools.vitruv.dsls.common.elements.NamedMetaenumReference
import org.eclipse.emf.ecore.EEnum

class ParameterGenerator {
Expand All @@ -31,10 +30,9 @@ class ParameterGenerator {
elements.map[toParameter(contextObject, it.name, it.generateTypeRef(_typeReferenceBuilder))]
}

def Iterable<AccessibleElement> getInputElements(Iterable<NamedMetaclassReference> metaclassReferences, Iterable<NamedJavaElementReference> javaElements, Iterable<NamedMetaenumReference> metaenumReferences) {
def Iterable<AccessibleElement> getInputElements(Iterable<NamedMetaclassReference> metaclassReferences, Iterable<NamedJavaElementReference> javaElements) {
return metaclassReferences.map[new AccessibleElement(it.name ?: MISSING_PARAMETER_NAME, it.metaclass?.mappedInstanceClassCanonicalName)]
+ javaElements.map[new AccessibleElement(it.name ?: MISSING_PARAMETER_NAME, it.type?.qualifiedName)]
+ metaenumReferences.map[new AccessibleElement(it.name ?: MISSING_PARAMETER_NAME, it.metaenum?.mappedInstanceClassCanonicalName)];
+ javaElements.map[new AccessibleElement(it.name ?: MISSING_PARAMETER_NAME, it.type?.qualifiedName)];
}

private dispatch def getMappedInstanceClassCanonicalName(EClass eClass) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import tools.vitruv.dsls.reactions.language.RetrieveOrRequireAbscenceOfModelElem
import tools.vitruv.dsls.common.elements.CommonLanguageElementsScopeProvider
import tools.vitruv.dsls.reactions.language.toplevelelements.CreateBlock
import tools.vitruv.dsls.reactions.language.toplevelelements.MatchBlock
import org.eclipse.emf.ecore.EClass

/**
* This class contains custom scoping description.
Expand Down Expand Up @@ -153,7 +154,7 @@ class ReactionsLanguageScopeProvider extends AbstractReactionsLanguageScopeProvi
throw new IllegalStateException();
}
createScope(IScope.NULLSCOPE,
featureReference.metaclass.EAllStructuralFeatures.filter(multiplicityFilterFunction).filter(
(featureReference.metaclass as EClass).EAllStructuralFeatures.filter(multiplicityFilterFunction).filter(
typeFilterFunction).iterator, [
EObjectDescription.create(it.name, it)
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ class ReactionsLanguageValidator extends AbstractReactionsLanguageValidator {

@Check
def checkMetaclassFeature(ModelElementChange elementChange) {
val elementType = elementChange?.elementType?.metaclass;
val elementType = elementChange?.elementType?.metaclass as EClass;
val elementChangeType = elementChange?.changeType;
// Only continue if element type is specified and its a feature change
var ElementChangeType atomicChangeType = null;
Expand Down

0 comments on commit 3ed5ae4

Please sign in to comment.