diff --git a/bundles/tools.vitruv.dsls.commonalities.runtime/src/tools/vitruv/dsls/commonalities/runtime/helper/IntermediateModelHelper.xtend b/bundles/tools.vitruv.dsls.commonalities.runtime/src/tools/vitruv/dsls/commonalities/runtime/helper/IntermediateModelHelper.xtend index 9be50f2fa..536e2eefe 100644 --- a/bundles/tools.vitruv.dsls.commonalities.runtime/src/tools/vitruv/dsls/commonalities/runtime/helper/IntermediateModelHelper.xtend +++ b/bundles/tools.vitruv.dsls.commonalities.runtime/src/tools/vitruv/dsls/commonalities/runtime/helper/IntermediateModelHelper.xtend @@ -8,7 +8,7 @@ import tools.vitruv.change.correspondence.CorrespondenceModel import static com.google.common.base.Preconditions.* -import static extension tools.vitruv.dsls.reactions.runtime.helper.ReactionsCorrespondenceHelper.* +import static extension tools.vitruv.dsls.reactions.runtime.helper.ReactionsCorrespondenceHelper.getCorrespondingElements @Utility class IntermediateModelHelper { @@ -28,13 +28,13 @@ class IntermediateModelHelper { static def I getCorrespondingIntermediate(CorrespondenceModel correspondenceModel, EObject object, Class intermediateType) { // Assumption: Each object has at most one Intermediate correspondence. - return correspondenceModel.getCorrespondingObjectsOfType(object, null, intermediateType).head + return correspondenceModel.getCorrespondingElements(object, intermediateType, null).head } static def IntermediateResourceBridge getCorrespondingResourceBridge(CorrespondenceModel correspondenceModel, EObject object) { checkArgument(!(object instanceof Intermediate), "object cannot be of type Intermediate") // Assumption: Each object has at most one Resource correspondence. - return correspondenceModel.getCorrespondingObjectsOfType(object, null, IntermediateResourceBridge).head + return correspondenceModel.getCorrespondingElements(object, IntermediateResourceBridge, null).head } } diff --git a/bundles/tools.vitruv.dsls.commonalities.runtime/src/tools/vitruv/dsls/commonalities/runtime/matching/ParticipationMatcher.xtend b/bundles/tools.vitruv.dsls.commonalities.runtime/src/tools/vitruv/dsls/commonalities/runtime/matching/ParticipationMatcher.xtend index 584cf9033..f7d61938e 100644 --- a/bundles/tools.vitruv.dsls.commonalities.runtime/src/tools/vitruv/dsls/commonalities/runtime/matching/ParticipationMatcher.xtend +++ b/bundles/tools.vitruv.dsls.commonalities.runtime/src/tools/vitruv/dsls/commonalities/runtime/matching/ParticipationMatcher.xtend @@ -10,7 +10,7 @@ import tools.vitruv.dsls.commonalities.runtime.intermediatemodelbase.Intermediat import tools.vitruv.dsls.commonalities.runtime.intermediatemodelbase.IntermediateModelBasePackage import tools.vitruv.dsls.commonalities.runtime.resources.IntermediateResourceBridge import tools.vitruv.dsls.commonalities.runtime.resources.ResourcesFactory -import tools.vitruv.dsls.reactions.runtime.helper.ReactionsCorrespondenceHelper +import static extension tools.vitruv.dsls.reactions.runtime.helper.ReactionsCorrespondenceHelper.getCorrespondingElements import tools.vitruv.change.correspondence.CorrespondenceModel import tools.vitruv.change.propagation.ResourceAccess @@ -217,8 +217,7 @@ class ParticipationMatcher { return Collections.singleton(object) } - if (!ReactionsCorrespondenceHelper.getCorrespondingObjectsOfType(correspondenceModel, object, null, - Intermediate).empty) { + if (!correspondenceModel.getCorrespondingElements(object, Intermediate, null).empty) { val attributeReferenceRootNode = containmentContext.attributeReferenceRootNode if (attributeReferenceRootNode !== null) { if (followAttributeReferences && attributeReferenceRootNode.matchesObject(object, @@ -376,8 +375,8 @@ class ParticipationMatcher { // Note: Not checking for correspondences for our dynamically created (and only partially setup) // ResourceBridge. if (!object.isResourceBridge) { - var correspondingIntermediate = ReactionsCorrespondenceHelper.getCorrespondingObjectsOfType( - correspondenceModel, object, null, Intermediate).head + var correspondingIntermediate = correspondenceModel.getCorrespondingElements( + object, Intermediate, null).head if (correspondingIntermediateType != correspondingIntermediate?.eClass) { if (correspondingIntermediateType === null) { logger.trace('''«indent(depth)»Node «node.toSimpleString»: Object already corresponds to an « diff --git a/bundles/tools.vitruv.dsls.commonalities.runtime/src/tools/vitruv/dsls/commonalities/runtime/operators/mapping/attribute/AbstractAttributeMappingOperator.xtend b/bundles/tools.vitruv.dsls.commonalities.runtime/src/tools/vitruv/dsls/commonalities/runtime/operators/mapping/attribute/AbstractAttributeMappingOperator.xtend index 0029e6039..a0197a2a8 100644 --- a/bundles/tools.vitruv.dsls.commonalities.runtime/src/tools/vitruv/dsls/commonalities/runtime/operators/mapping/attribute/AbstractAttributeMappingOperator.xtend +++ b/bundles/tools.vitruv.dsls.commonalities.runtime/src/tools/vitruv/dsls/commonalities/runtime/operators/mapping/attribute/AbstractAttributeMappingOperator.xtend @@ -1,6 +1,6 @@ package tools.vitruv.dsls.commonalities.runtime.operators.mapping.attribute -import tools.vitruv.dsls.reactions.runtime.ReactionExecutionState +import tools.vitruv.dsls.reactions.runtime.state.ReactionExecutionState import static com.google.common.base.Preconditions.* diff --git a/bundles/tools.vitruv.dsls.commonalities.runtime/src/tools/vitruv/dsls/commonalities/runtime/operators/mapping/reference/AbstractReferenceMappingOperator.xtend b/bundles/tools.vitruv.dsls.commonalities.runtime/src/tools/vitruv/dsls/commonalities/runtime/operators/mapping/reference/AbstractReferenceMappingOperator.xtend index 41211f9a1..3f09f56c3 100644 --- a/bundles/tools.vitruv.dsls.commonalities.runtime/src/tools/vitruv/dsls/commonalities/runtime/operators/mapping/reference/AbstractReferenceMappingOperator.xtend +++ b/bundles/tools.vitruv.dsls.commonalities.runtime/src/tools/vitruv/dsls/commonalities/runtime/operators/mapping/reference/AbstractReferenceMappingOperator.xtend @@ -1,6 +1,6 @@ package tools.vitruv.dsls.commonalities.runtime.operators.mapping.reference -import tools.vitruv.dsls.reactions.runtime.ReactionExecutionState +import tools.vitruv.dsls.reactions.runtime.state.ReactionExecutionState import static com.google.common.base.Preconditions.* diff --git a/bundles/tools.vitruv.dsls.commonalities.runtime/src/tools/vitruv/dsls/commonalities/runtime/operators/mapping/reference/ContainmentReferenceMappingOperator.xtend b/bundles/tools.vitruv.dsls.commonalities.runtime/src/tools/vitruv/dsls/commonalities/runtime/operators/mapping/reference/ContainmentReferenceMappingOperator.xtend index e3a571502..256f5495a 100644 --- a/bundles/tools.vitruv.dsls.commonalities.runtime/src/tools/vitruv/dsls/commonalities/runtime/operators/mapping/reference/ContainmentReferenceMappingOperator.xtend +++ b/bundles/tools.vitruv.dsls.commonalities.runtime/src/tools/vitruv/dsls/commonalities/runtime/operators/mapping/reference/ContainmentReferenceMappingOperator.xtend @@ -3,7 +3,7 @@ package tools.vitruv.dsls.commonalities.runtime.operators.mapping.reference import java.util.List import org.eclipse.emf.ecore.EObject import org.eclipse.emf.ecore.EReference -import tools.vitruv.dsls.reactions.runtime.ReactionExecutionState +import tools.vitruv.dsls.reactions.runtime.state.ReactionExecutionState import static com.google.common.base.Preconditions.* diff --git a/bundles/tools.vitruv.dsls.commonalities.runtime/src/tools/vitruv/dsls/commonalities/runtime/resources/impl/IntermediateResourceBridgeI.xtend b/bundles/tools.vitruv.dsls.commonalities.runtime/src/tools/vitruv/dsls/commonalities/runtime/resources/impl/IntermediateResourceBridgeI.xtend index 7dcb00f6f..496327762 100644 --- a/bundles/tools.vitruv.dsls.commonalities.runtime/src/tools/vitruv/dsls/commonalities/runtime/resources/impl/IntermediateResourceBridgeI.xtend +++ b/bundles/tools.vitruv.dsls.commonalities.runtime/src/tools/vitruv/dsls/commonalities/runtime/resources/impl/IntermediateResourceBridgeI.xtend @@ -8,7 +8,7 @@ import tools.vitruv.dsls.commonalities.runtime.intermediatemodelbase.Intermediat import tools.vitruv.dsls.commonalities.runtime.resources.Resource import tools.vitruv.dsls.commonalities.runtime.resources.ResourcesPackage import tools.vitruv.dsls.reactions.runtime.helper.PersistenceHelper -import tools.vitruv.dsls.reactions.runtime.helper.ReactionsCorrespondenceHelper +import static extension tools.vitruv.dsls.reactions.runtime.helper.ReactionsCorrespondenceHelper.getCorrespondingElements import static com.google.common.base.Preconditions.* import static tools.vitruv.dsls.commonalities.runtime.helper.XtendAssertHelper.* @@ -200,9 +200,9 @@ class IntermediateResourceBridgeI extends IntermediateResourceBridgeImpl { intermediates += intermediateCorrespondenceContainer val resourceHaving = intermediates.flatMap [ - ReactionsCorrespondenceHelper.getCorrespondingModelElements(it, EObject, null, [ + correspondenceModel.getCorrespondingElements(it, EObject, null, [ !(it instanceof Intermediate) && !(it instanceof Resource) && eResource !== null - ], correspondenceModel) + ]) ].head if (resourceHaving === null) { throw new IllegalStateException('''Could not find any transitive correspondence or container of ‹«content @@ -231,8 +231,7 @@ class IntermediateResourceBridgeI extends IntermediateResourceBridgeImpl { // Collecting to Set removes duplicates and avoids a ConcurrentModificationException when adding the results to // the result Set. val transitiveIntermediates = foundIntermediates.flatMap [ intermediate | - ReactionsCorrespondenceHelper.getCorrespondingModelElements(intermediate, Intermediate, null, null, - correspondenceModel) + correspondenceModel.getCorrespondingElements(intermediate, Intermediate, null, null) ].toSet // Add to result Set: This removes objects which we have already found before. @@ -246,8 +245,7 @@ class IntermediateResourceBridgeI extends IntermediateResourceBridgeImpl { private def findIntermediateCorrespondence(EObject object) { if (correspondenceModel === null) return null; // TODO - val result = ReactionsCorrespondenceHelper.getCorrespondingModelElements(object, Intermediate, null, null, - correspondenceModel).head + val result = correspondenceModel.getCorrespondingElements(object, Intermediate, null, null).head if (result === null) { throw new IllegalStateException('''Could not find the intermediate correspondence of ‹«object»›!''') } diff --git a/bundles/tools.vitruv.dsls.reactions.runtime/META-INF/MANIFEST.MF b/bundles/tools.vitruv.dsls.reactions.runtime/META-INF/MANIFEST.MF index 2cbb71749..5723a7e41 100644 --- a/bundles/tools.vitruv.dsls.reactions.runtime/META-INF/MANIFEST.MF +++ b/bundles/tools.vitruv.dsls.reactions.runtime/META-INF/MANIFEST.MF @@ -17,9 +17,12 @@ Require-Bundle: org.apache.log4j;visibility:=reexport, tools.vitruv.change.composite;visibility:=reexport, tools.vitruv.change.propagation;visibility:=reexport, tools.vitruv.change.interaction;visibility:=reexport, - edu.kit.ipd.sdq.commons.util.emf + edu.kit.ipd.sdq.commons.util.emf, + edu.kit.ipd.sdq.activextendannotations Bundle-ActivationPolicy: lazy -Export-Package: tools.vitruv.dsls.reactions.runtime, +Export-Package: tools.vitruv.dsls.reactions.runtime.reactions, + tools.vitruv.dsls.reactions.runtime.routines, + tools.vitruv.dsls.reactions.runtime.state, tools.vitruv.dsls.reactions.runtime.helper, tools.vitruv.dsls.reactions.runtime.marker, tools.vitruv.dsls.reactions.runtime.structure, diff --git a/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/AbstractReactionRealization.xtend b/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/AbstractReactionRealization.xtend deleted file mode 100644 index 289b94bcd..000000000 --- a/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/AbstractReactionRealization.xtend +++ /dev/null @@ -1,49 +0,0 @@ -package tools.vitruv.dsls.reactions.runtime - -import tools.vitruv.dsls.reactions.runtime.IReactionRealization -import tools.vitruv.dsls.reactions.runtime.structure.CallHierarchyHaving -import tools.vitruv.change.atomic.EChange -import org.eclipse.xtend.lib.annotations.Accessors -import tools.vitruv.change.interaction.UserInteractor - -abstract class AbstractReactionRealization extends CallHierarchyHaving implements IReactionRealization { - val AbstractRepairRoutinesFacade routinesFacade; - protected UserInteractor userInteractor; - protected ReactionExecutionState executionState; - - new(AbstractRepairRoutinesFacade routinesFacade) { - this.routinesFacade = routinesFacade; - } - - // generic return type for convenience; the requested type has to match the type of the facade provided during construction - protected def T getRoutinesFacade() { - return routinesFacade as T; - } - - override applyEvent(EChange change, ReactionExecutionState reactionExecutionState) { - this.executionState = reactionExecutionState; - this.userInteractor = reactionExecutionState.userInteractor; - - // set the reaction execution state and caller to use for all following routine calls: - // note: reactions are executed one after the other, therefore we don't need to capture/restore the facade's previous execution state here, - // resetting it after execution is sufficient - routinesFacade._getExecutionState().setExecutionState(executionState, this); - - try { - executeReaction(change); - } finally { - // reset the routines facade execution state: - routinesFacade._getExecutionState().reset(); - } - } - - protected def void executeReaction(EChange change); - - - static abstract class ChangeMatcher { - @Accessors(PUBLIC_GETTER) - T change - - def boolean check(EChange change); - } -} \ No newline at end of file diff --git a/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/AbstractReactionsChangePropagationSpecification.xtend b/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/AbstractReactionsChangePropagationSpecification.xtend deleted file mode 100644 index 99eea21b7..000000000 --- a/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/AbstractReactionsChangePropagationSpecification.xtend +++ /dev/null @@ -1,21 +0,0 @@ -package tools.vitruv.dsls.reactions.runtime - -import tools.vitruv.change.propagation.impl.CompositeChangePropagationSpecification -import tools.vitruv.change.composite.MetamodelDescriptor - -/** - * A {@link CompositeChangePropagationSpecification} that contains the reactions change processor. - * To add further change processors extend the implementing class and override the setup method. - */ -abstract class AbstractReactionsChangePropagationSpecification extends CompositeChangePropagationSpecification { - new(MetamodelDescriptor sourceMetamodelDescriptor, MetamodelDescriptor targetMetamodelDescriptor) { - super(sourceMetamodelDescriptor, targetMetamodelDescriptor); - this.setup(); - } - - /** - * Adds the reactions change processor to this {@link CompositeChangePropagationSpecification}. - * For adding further change processors overwrite this method and call the super method at the right place. - */ - protected abstract def void setup(); -} diff --git a/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/AbstractReactionsExecutor.xtend b/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/AbstractReactionsExecutor.xtend deleted file mode 100644 index 5dabf81ac..000000000 --- a/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/AbstractReactionsExecutor.xtend +++ /dev/null @@ -1,58 +0,0 @@ -package tools.vitruv.dsls.reactions.runtime - -import org.apache.log4j.Logger -import tools.vitruv.dsls.reactions.runtime.IReactionRealization -import tools.vitruv.change.interaction.UserInteractor -import tools.vitruv.change.atomic.EChange -import tools.vitruv.change.correspondence.CorrespondenceModel -import tools.vitruv.change.propagation.ResourceAccess -import java.util.List -import tools.vitruv.change.propagation.impl.AbstractChangePropagationSpecification -import tools.vitruv.change.composite.MetamodelDescriptor - -abstract class AbstractReactionsExecutor extends AbstractChangePropagationSpecification { - static val LOGGER = Logger.getLogger(AbstractReactionsExecutor); - - val RoutinesFacadesProvider routinesFacadesProvider; - List reactions; - - new(MetamodelDescriptor sourceMetamodelDescriptor, MetamodelDescriptor targetMetamodelDescriptor) { - super(sourceMetamodelDescriptor, targetMetamodelDescriptor); - this.reactions = newArrayList; - this.routinesFacadesProvider = this.createRoutinesFacadesProvider(); - this.setup(); - } - - protected def getRoutinesFacadesProvider() { - return routinesFacadesProvider; - } - - protected def void addReaction(IReactionRealization reaction) { - this.reactions += reaction; - } - - override doesHandleChange(EChange change, CorrespondenceModel correspondenceModel) { - return true - } - - override propagateChange(EChange change, CorrespondenceModel correspondenceModel, - ResourceAccess resourceAccess) { - LOGGER.trace("Call relevant reactions from " + sourceMetamodelDescriptor + " to " + targetMetamodelDescriptor); - for (reaction : reactions) { - LOGGER.trace("Calling reaction: " + reaction.class.simpleName + " with change: " + change); - val executionState = new ReactionExecutionState(userInteractor, correspondenceModel, resourceAccess, this); - reaction.applyEvent(change, executionState) - } - } - - override setUserInteractor(UserInteractor userInteractor) { - super.setUserInteractor(userInteractor); - reactions = newArrayList; - setup(); - } - - protected abstract def RoutinesFacadesProvider createRoutinesFacadesProvider(); - - protected abstract def void setup(); - -} diff --git a/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/AbstractRepairRoutineRealization.xtend b/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/AbstractRepairRoutineRealization.xtend deleted file mode 100644 index eadb8848b..000000000 --- a/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/AbstractRepairRoutineRealization.xtend +++ /dev/null @@ -1,195 +0,0 @@ -package tools.vitruv.dsls.reactions.runtime - -import java.io.IOException -import java.util.List -import java.util.function.Function -import org.eclipse.emf.ecore.EObject -import org.eclipse.emf.ecore.resource.Resource -import org.eclipse.emf.ecore.util.EcoreUtil -import tools.vitruv.dsls.reactions.runtime.helper.PersistenceHelper -import tools.vitruv.dsls.reactions.runtime.helper.ReactionsCorrespondenceHelper -import tools.vitruv.dsls.reactions.runtime.structure.CallHierarchyHaving -import tools.vitruv.dsls.reactions.runtime.structure.Loggable -import tools.vitruv.change.correspondence.CorrespondenceModel -import tools.vitruv.change.interaction.UserInteractor -import tools.vitruv.change.propagation.ResourceAccess -import org.eclipse.emf.common.util.URI - -abstract class AbstractRepairRoutineRealization extends CallHierarchyHaving implements RepairRoutine { - val AbstractRepairRoutinesFacade routinesFacade; - extension val ReactionExecutionState executionState; - - new(AbstractRepairRoutinesFacade routinesFacade, ReactionExecutionState executionState, CallHierarchyHaving calledBy) { - super(calledBy); - this.routinesFacade = routinesFacade; - this.executionState = executionState; - } - - // generic return type for convenience; the requested type has to match the type of the facade provided during construction - protected def T getRoutinesFacade() { - return routinesFacade as T; - } - - protected def ReactionExecutionState getExecutionState() { - return executionState; - } - - protected def UserInteractor getUserInteractor() { - return executionState.userInteractor; - } - - protected def CorrespondenceModel getCorrespondenceModel() { - return executionState.correspondenceModel; - } - - override boolean applyRoutine() { - // capture the current routines facade execution state: - val facadeExecutionState = routinesFacade._getExecutionState().capture(); - // set the reaction execution state and caller to use for all following routine calls: - routinesFacade._getExecutionState.setExecutionState(executionState, this); - - try { - // Exception handling could be added here when productively used - return executeRoutine(); - } finally { - // restore the previously captured execution state of the facade: - routinesFacade._getExecutionState().restore(facadeExecutionState); - } - } - - protected abstract def boolean executeRoutine() throws IOException; - - static class Match extends Loggable { - protected final extension ReactionExecutionState executionState - - new(ReactionExecutionState executionState) { - this.executionState = executionState - } - - protected def List getCorrespondingElements( - EObject correspondenceSource, - Class elementClass, - Function correspondencePreconditionMethod, - String tag - ) { - val retrievedElements = ReactionsCorrespondenceHelper.getCorrespondingModelElements(correspondenceSource, - elementClass, tag, correspondencePreconditionMethod, correspondenceModel); - return retrievedElements; - } - - protected def T getCorrespondingElement( - EObject correspondenceSource, - Class elementClass, - Function correspondencePreconditionMethod, - String tag, - boolean asserted - ) { - val retrievedElements = getCorrespondingElements(correspondenceSource, - elementClass, correspondencePreconditionMethod, tag); - if (retrievedElements.size > 1) { - CorrespondenceFailHandlerFactory.createExceptionHandler().handle(retrievedElements, correspondenceSource, - elementClass, executionState.userInteractor); - } - if (asserted && retrievedElements.size == 0) { - CorrespondenceFailHandlerFactory.createExceptionHandler().handle(retrievedElements, correspondenceSource, - elementClass, executionState.userInteractor); - } - val retrievedElement = if (!retrievedElements.empty) retrievedElements.get(0) else null; - return retrievedElement; - } - } - - static class Create extends Loggable { - protected final extension ReactionExecutionState executionState - - new(ReactionExecutionState executionState) { - this.executionState = executionState - } - - protected def void notifyObjectCreated(EObject createdObject) { - executionState.changePropagationObservable.notifyObjectCreated(createdObject); - } - } - - static class Update extends Loggable { - protected final extension ReactionExecutionState executionState - - new(ReactionExecutionState executionState) { - this.executionState = executionState - } - - /** - * Persists a given {@link EObject} as root object in the {@link Resource} at the specified path, - * relative to the project root folder. - * - * @param alreadyPersistedObject - - * An object that was already persisted within the project (necessary for retrieving the project folder) - * @param elementToPersist - - * The element to be persisted - * @param persistencePath - - * The path relative to the project root folder at which the element shall be persisted, - * using "/" as separator char and including the file name with extension - */ - protected def persistProjectRelative(EObject alreadyPersistedObject, EObject elementToPersist, - String persistencePath) { - if (alreadyPersistedObject === null || elementToPersist === null || persistencePath === null) { - throw new IllegalArgumentException( - "correspondenceSource, element and persistancePath must be specified"); - } - - val _resourceURI = PersistenceHelper.getURIFromSourceProjectFolder(alreadyPersistedObject, persistencePath); - persistAsRoot(elementToPersist, _resourceURI) - } - - /** - * Persists the given object as root of the metadata model specified by - * the given metadata key. - * - * @param rootObject The root object, not null. - * @param metadataKey The key uniquely identifying the metadata model. - * See {@link ResourceAccess#getMetadataModelURI}. - */ - protected def persistAsMetadataRoot(EObject rootObject, String... metadataKey) { - if (rootObject === null) { - throw new IllegalArgumentException("rootObject is null!"); - } - val modelURI = resourceAccess.getMetadataModelURI(metadataKey) - persistAsRoot(rootObject, modelURI) - } - - private def persistAsRoot(EObject rootObject, URI uri) { - logger.trace("Registered to persist root " + rootObject + " in: " + uri) - if (rootObject.eResource?.URI !== uri) { - EcoreUtil.remove(rootObject) - resourceAccess.persistAsRoot(rootObject, uri) - } - } - - def void addCorrespondenceBetween(EObject firstElement, EObject secondElement) { - addCorrespondenceBetween(firstElement, secondElement, null) - } - - def void addCorrespondenceBetween(EObject firstElement, EObject secondElement, String tag) { - ReactionsCorrespondenceHelper.addCorrespondence(correspondenceModel, firstElement, secondElement, tag); - } - - def void removeObject(EObject element) { - if (element === null) { - return - } - if (logger.debugEnabled) { - logger.debug("Removing object " + element + " from container " + element.eContainer()) - } - EcoreUtil.remove(element) - } - - def void removeCorrespondenceBetween(EObject firstElement, EObject secondElement) { - removeCorrespondenceBetween(firstElement, secondElement, null) - } - - def void removeCorrespondenceBetween(EObject firstElement, EObject secondElement, String tag) { - ReactionsCorrespondenceHelper.removeCorrespondencesBetweenElements(correspondenceModel, - firstElement, secondElement, tag) - } - } -} diff --git a/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/AbstractRepairRoutinesFacade.xtend b/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/AbstractRepairRoutinesFacade.xtend deleted file mode 100644 index b6fcf2472..000000000 --- a/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/AbstractRepairRoutinesFacade.xtend +++ /dev/null @@ -1,35 +0,0 @@ -package tools.vitruv.dsls.reactions.runtime - -import tools.vitruv.dsls.reactions.runtime.structure.Loggable -import tools.vitruv.dsls.reactions.runtime.structure.ReactionsImportPath - -/** - * Note: All methods start with an underscore here to not conflict with the methods that are generated from the routines by - * concrete implementations. - */ -abstract class AbstractRepairRoutinesFacade extends Loggable { - // used by concrete implementations to request routines facades of executed routines: - val RoutinesFacadesProvider routinesFacadesProvider; - // absolute path inside the import hierarchy to the segment this routines facade belongs to, never null: - val ReactionsImportPath reactionsImportPath; - // shared execution state among all routines facades in the import hierarchy: - val RoutinesFacadeExecutionState executionState; - - new(RoutinesFacadesProvider routinesFacadesProvider, ReactionsImportPath reactionsImportPath, RoutinesFacadeExecutionState executionState) { - this.routinesFacadesProvider = routinesFacadesProvider; - this.reactionsImportPath = reactionsImportPath; - this.executionState = executionState; - } - - protected def RoutinesFacadesProvider _getRoutinesFacadesProvider() { - return routinesFacadesProvider; - } - - protected def ReactionsImportPath _getReactionsImportPath() { - return reactionsImportPath; - } - - protected def RoutinesFacadeExecutionState _getExecutionState() { - return executionState; - } -} diff --git a/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/CorrespondenceFailHandler.xtend b/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/CorrespondenceFailHandler.xtend deleted file mode 100644 index 35a33da1f..000000000 --- a/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/CorrespondenceFailHandler.xtend +++ /dev/null @@ -1,11 +0,0 @@ -package tools.vitruv.dsls.reactions.runtime - -import org.eclipse.emf.ecore.EObject -import tools.vitruv.change.interaction.UserInteractor - -interface CorrespondenceFailHandler { - /** - * Returns whether the execution shall be continued or not - */ - def boolean handle(Iterable foundObjects, EObject sourceElement, Class expectedType, UserInteractor userInteractor); -} \ No newline at end of file diff --git a/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/CorrespondenceFailHandlerFactory.xtend b/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/CorrespondenceFailHandlerFactory.xtend deleted file mode 100644 index b1a6aa53e..000000000 --- a/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/CorrespondenceFailHandlerFactory.xtend +++ /dev/null @@ -1,24 +0,0 @@ -package tools.vitruv.dsls.reactions.runtime - -import tools.vitruv.dsls.reactions.runtime.correspondenceFailHandler.CorrespondenceFailException -import tools.vitruv.dsls.reactions.runtime.correspondenceFailHandler.CorrespondenceFailDefaultDialog -import tools.vitruv.dsls.reactions.runtime.correspondenceFailHandler.CorrespondenceFailCustomDialog -import tools.vitruv.dsls.reactions.runtime.correspondenceFailHandler.CorrespondenceFailDoNothing - -class CorrespondenceFailHandlerFactory { - static def CorrespondenceFailHandler createExceptionHandler() { - return new CorrespondenceFailException(); - } - - static def CorrespondenceFailHandler createDefaultUserDialogHandler(boolean abortEffect) { - return new CorrespondenceFailDefaultDialog(abortEffect); - } - - static def CorrespondenceFailHandler createCustomUserDialogHandler(boolean abortEffect, String message) { - return new CorrespondenceFailCustomDialog(abortEffect, message); - } - - static def CorrespondenceFailHandler createDoNothingHandler(boolean abortEffect) { - return new CorrespondenceFailDoNothing(abortEffect); - } -} \ No newline at end of file diff --git a/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/IReactionRealization.xtend b/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/IReactionRealization.xtend deleted file mode 100644 index 143a10a26..000000000 --- a/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/IReactionRealization.xtend +++ /dev/null @@ -1,7 +0,0 @@ -package tools.vitruv.dsls.reactions.runtime - -import tools.vitruv.change.atomic.EChange - -interface IReactionRealization { - def void applyEvent(EChange change, ReactionExecutionState executionState); -} diff --git a/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/ReactionsExecutor.xtend b/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/ReactionsExecutor.xtend deleted file mode 100644 index b313ed2a4..000000000 --- a/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/ReactionsExecutor.xtend +++ /dev/null @@ -1,10 +0,0 @@ -package tools.vitruv.dsls.reactions.runtime - -import org.eclipse.emf.common.command.Command -import java.util.List -import tools.vitruv.change.atomic.EChange -import tools.vitruv.change.correspondence.CorrespondenceModel - -interface ReactionsExecutor { - def List generateCommandsForEvent(EChange change, CorrespondenceModel correspondenceModel); -} \ No newline at end of file diff --git a/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/RepairRoutine.xtend b/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/RepairRoutine.xtend deleted file mode 100644 index 67b33c8f9..000000000 --- a/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/RepairRoutine.xtend +++ /dev/null @@ -1,5 +0,0 @@ -package tools.vitruv.dsls.reactions.runtime - -interface RepairRoutine { - def boolean applyRoutine(); -} \ No newline at end of file diff --git a/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/RoutinesFacadeExecutionState.xtend b/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/RoutinesFacadeExecutionState.xtend deleted file mode 100644 index 2196a95f1..000000000 --- a/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/RoutinesFacadeExecutionState.xtend +++ /dev/null @@ -1,49 +0,0 @@ -package tools.vitruv.dsls.reactions.runtime - -import tools.vitruv.dsls.reactions.runtime.structure.CallHierarchyHaving - -/** - * Stores the common execution state shared among all routines facades of an import hierarchy. - *

- * The stored reaction execution state and caller get passed to called routines by the routines facades using this execution state. - */ -class RoutinesFacadeExecutionState { - - var ReactionExecutionState reactionExecutionState = null; - var CallHierarchyHaving caller = null; - - new() { - } - - private new(ReactionExecutionState reactionExecutionState, CallHierarchyHaving caller) { - this.reactionExecutionState = reactionExecutionState; - this.caller = caller; - } - - def ReactionExecutionState getReactionExecutionState() { - return reactionExecutionState; - } - - def CallHierarchyHaving getCaller() { - return caller; - } - - def void setExecutionState(ReactionExecutionState reactionExecutionState, CallHierarchyHaving caller) { - this.reactionExecutionState = reactionExecutionState; - this.caller = caller; - } - - def void reset() { - this.setExecutionState(null, null); - } - - // creates a snapshot of the current execution state: - def RoutinesFacadeExecutionState capture() { - return new RoutinesFacadeExecutionState(reactionExecutionState, caller); - } - - // restores a previously captured execution state: - def void restore(RoutinesFacadeExecutionState executionState) { - this.setExecutionState(executionState.reactionExecutionState, executionState.caller); - } -} diff --git a/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/correspondenceFailHandler/AbstractCorrespondenceFailHandler.xtend b/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/correspondenceFailHandler/AbstractCorrespondenceFailHandler.xtend deleted file mode 100644 index e4ddc7e20..000000000 --- a/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/correspondenceFailHandler/AbstractCorrespondenceFailHandler.xtend +++ /dev/null @@ -1,15 +0,0 @@ -package tools.vitruv.dsls.reactions.runtime.correspondenceFailHandler - -import tools.vitruv.dsls.reactions.runtime.structure.Loggable -import tools.vitruv.dsls.reactions.runtime.CorrespondenceFailHandler -import org.eclipse.emf.ecore.EObject - -abstract class AbstractCorrespondenceFailHandler extends Loggable implements CorrespondenceFailHandler { - def logFail(Iterable foundObjects, EObject sourceElement, Class expectedType) { - logger.debug("There were (" + foundObjects.size + ") corresponding elements of type " + - expectedType.getSimpleName() + " for: " + sourceElement) - for (obj : foundObjects) { - logger.debug(" " + obj); - } - } -} \ No newline at end of file diff --git a/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/correspondenceFailHandler/CorrespondenceFailCustomDialog.xtend b/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/correspondenceFailHandler/CorrespondenceFailCustomDialog.xtend deleted file mode 100644 index 2402a6c89..000000000 --- a/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/correspondenceFailHandler/CorrespondenceFailCustomDialog.xtend +++ /dev/null @@ -1,22 +0,0 @@ -package tools.vitruv.dsls.reactions.runtime.correspondenceFailHandler - -import org.eclipse.emf.ecore.EObject -import tools.vitruv.change.interaction.UserInteractor -import tools.vitruv.change.interaction.UserInteractionOptions.WindowModality - -class CorrespondenceFailCustomDialog extends AbstractCorrespondenceFailHandler { - final boolean abortEffect; - final String message; - - new(boolean abortEffect, String message) { - this.abortEffect = abortEffect; - this.message = message; - } - - override handle(Iterable foundObjects, EObject sourceElement, Class expectedType, UserInteractor userInteractor) { - logFail(foundObjects, sourceElement, expectedType); - logger.debug("Show user dialog with message: " + message); - userInteractor.notificationDialogBuilder.message(message).windowModality(WindowModality.MODAL).startInteraction(); - return abortEffect; - } -} \ No newline at end of file diff --git a/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/correspondenceFailHandler/CorrespondenceFailDefaultDialog.xtend b/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/correspondenceFailHandler/CorrespondenceFailDefaultDialog.xtend deleted file mode 100644 index 8b011c030..000000000 --- a/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/correspondenceFailHandler/CorrespondenceFailDefaultDialog.xtend +++ /dev/null @@ -1,22 +0,0 @@ -package tools.vitruv.dsls.reactions.runtime.correspondenceFailHandler - -import org.eclipse.emf.ecore.EObject -import tools.vitruv.change.interaction.UserInteractor -import tools.vitruv.change.interaction.UserInteractionOptions.WindowModality - -class CorrespondenceFailDefaultDialog extends AbstractCorrespondenceFailHandler { - final boolean abortEffect; - - new(boolean abortEffect) { - this.abortEffect = abortEffect; - } - - override handle(Iterable foundObjects, EObject sourceElement, Class expectedType, UserInteractor userInteractor) { - logFail(foundObjects, sourceElement, expectedType); - logger.debug("Show user dialog default message"); - val message = "There were (" + foundObjects.size + ") corresponding elements of type " - + expectedType.getSimpleName() + "although one was expected for: " + sourceElement - userInteractor.notificationDialogBuilder.message(message).windowModality(WindowModality.MODAL).startInteraction(); - return abortEffect; - } -} \ No newline at end of file diff --git a/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/correspondenceFailHandler/CorrespondenceFailDoNothing.xtend b/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/correspondenceFailHandler/CorrespondenceFailDoNothing.xtend deleted file mode 100644 index a6794f56f..000000000 --- a/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/correspondenceFailHandler/CorrespondenceFailDoNothing.xtend +++ /dev/null @@ -1,18 +0,0 @@ -package tools.vitruv.dsls.reactions.runtime.correspondenceFailHandler - -import org.eclipse.emf.ecore.EObject -import tools.vitruv.change.interaction.UserInteractor - -class CorrespondenceFailDoNothing extends AbstractCorrespondenceFailHandler { - final boolean abortEffect; - - new(boolean abortEffect) { - this.abortEffect = abortEffect; - } - - override handle(Iterable foundObjects, EObject sourceElement, Class expectedType, UserInteractor userInteractor) { - logFail(foundObjects, sourceElement, expectedType); - logger.debug("And nothing ist done"); - return abortEffect; - } -} \ No newline at end of file diff --git a/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/correspondenceFailHandler/CorrespondenceFailException.xtend b/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/correspondenceFailHandler/CorrespondenceFailException.xtend deleted file mode 100644 index 77f1ce937..000000000 --- a/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/correspondenceFailHandler/CorrespondenceFailException.xtend +++ /dev/null @@ -1,14 +0,0 @@ -package tools.vitruv.dsls.reactions.runtime.correspondenceFailHandler - -import org.eclipse.emf.ecore.EObject -import tools.vitruv.change.interaction.UserInteractor - -class CorrespondenceFailException extends AbstractCorrespondenceFailHandler { - override handle(Iterable foundObjects, EObject sourceElement, Class expectedType, UserInteractor userInteractor) { - logFail(foundObjects, sourceElement, expectedType); - logger.debug("Throw exception due to correspondence fail"); - throw new IllegalArgumentException( - "There were (" + foundObjects.size + ") corresponding elements of type " + - expectedType.getSimpleName() + " for: " + sourceElement + ", which are: " + foundObjects); - } -} \ No newline at end of file diff --git a/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/helper/PersistenceHelper.xtend b/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/helper/PersistenceHelper.xtend index 01a5028a5..f5160ba08 100644 --- a/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/helper/PersistenceHelper.xtend +++ b/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/helper/PersistenceHelper.xtend @@ -8,21 +8,10 @@ import static edu.kit.ipd.sdq.commons.util.org.eclipse.emf.common.util.URIUtil.g import static extension tools.vitruv.change.propagation.ProjectMarker.getProjectRootFolder import java.nio.file.Path import static edu.kit.ipd.sdq.commons.util.org.eclipse.emf.common.util.URIUtil.createFileURI +import edu.kit.ipd.sdq.activextendannotations.Utility -final class PersistenceHelper { - private new() {} - - static def EObject getModelRoot(EObject modelObject) { - var result = modelObject - while (result.eContainer !== null) { - result = result.eContainer - } - return result - } - - private static def URI getURIOfElementResourceFolder(EObject element) { - return element.eResource.URI.trimSegments(1) - } +@Utility +class PersistenceHelper { private static def URI getURIOfElementProject(EObject element) { val elementUri = element.eResource.URI @@ -35,7 +24,8 @@ final class PersistenceHelper { val elementPath = Path.of(elementUri.toFileString) return createFileURI(elementPath.projectRootFolder.toFile()) } else { - throw new UnsupportedOperationException("Other URI types than file and platform are currently not supported"); + throw new UnsupportedOperationException( + "Other URI types than file and platform are currently not supported"); } } @@ -47,11 +37,6 @@ final class PersistenceHelper { return baseURI.appendSegments(newModelFileSegments) } - static def URI getURIFromSourceResourceFolder(EObject source, String relativePath) { - val baseURI = getURIOfElementResourceFolder(source) - return baseURI.appendPathToURI(relativePath) - } - /** * Returns the URI of the project folder, relative as specified in relativePath * to the project root, determined from the element source. diff --git a/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/helper/ReactionsCorrespondenceHelper.xtend b/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/helper/ReactionsCorrespondenceHelper.xtend index 9d2d1af1d..5a2d8e9ca 100644 --- a/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/helper/ReactionsCorrespondenceHelper.xtend +++ b/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/helper/ReactionsCorrespondenceHelper.xtend @@ -1,64 +1,49 @@ package tools.vitruv.dsls.reactions.runtime.helper -import java.util.ArrayList -import java.util.List import org.apache.log4j.Logger import org.eclipse.emf.ecore.EObject import org.eclipse.xtext.xbase.lib.Functions.Function1 import tools.vitruv.dsls.reactions.runtime.correspondence.ReactionsCorrespondence -import tools.vitruv.dsls.reactions.runtime.ReactionsCorrespondenceModelViewFactory import tools.vitruv.change.correspondence.CorrespondenceModel +import edu.kit.ipd.sdq.activextendannotations.Utility -final class ReactionsCorrespondenceHelper { - - static Logger logger = Logger.getLogger(ReactionsCorrespondenceHelper) - - private new() {} +@Utility +class ReactionsCorrespondenceHelper { + static val Logger logger = Logger.getLogger(ReactionsCorrespondenceHelper) private static def getReactionsView(CorrespondenceModel correspondenceModel) { - return correspondenceModel.getEditableView(ReactionsCorrespondenceModelViewFactory.instance); - } - - static def removeCorrespondencesBetweenElements(CorrespondenceModel correspondenceModel, - EObject source, EObject target, String tag) { - logger.trace("Removing correspondence between " + source + " and " + target + " with tag: " + tag); - val correspondenceModelView = correspondenceModel.reactionsView; - correspondenceModelView.removeCorrespondencesBetween(#[source], #[target], tag); + return correspondenceModel.getEditableView(ReactionsCorrespondenceModelViewFactory.instance) } - static def removeCorrespondencesOfObject(CorrespondenceModel correspondenceModel, - EObject source) { - logger.trace("Removing correspondences of object " + source); - val correspondenceModelView = correspondenceModel.reactionsView; - correspondenceModelView.removeCorrespondencesFor(#[source], null); + static def removeCorrespondences(CorrespondenceModel correspondenceModel, EObject source, EObject target, + String tag) { + logger.trace("Removing correspondence between " + source + " and " + target + " with tag: " + tag) + val correspondenceModelView = correspondenceModel.reactionsView + correspondenceModelView.removeCorrespondencesBetween(#[source], #[target], tag) } - static def ReactionsCorrespondence addCorrespondence( - CorrespondenceModel correspondenceModel, EObject source, EObject target, String tag) { - logger.trace("Adding correspondence between " + source + " and " + target + " with tag: " + tag); - val correspondence = correspondenceModel.reactionsView. - createAndAddCorrespondence(#[source], #[target]); - correspondence.tag = tag ?: ""; - return correspondence; + static def ReactionsCorrespondence addCorrespondence(CorrespondenceModel correspondenceModel, EObject source, + EObject target, String tag) { + logger.trace("Adding correspondence between " + source + " and " + target + " with tag: " + tag) + val correspondence = correspondenceModel.reactionsView.createAndAddCorrespondence(#[source], #[target]) + correspondence.tag = tag ?: "" + return correspondence } - static def Iterable getCorrespondingObjectsOfType( - CorrespondenceModel correspondenceModel, EObject source, String expectedTag, - Class type) { - return correspondenceModel.reactionsView.getCorrespondingEObjects(#[source], expectedTag).flatten.filter(type); - } - - static def List getCorrespondingModelElements(EObject sourceElement, Class affectedElementClass, - String expectedTag, Function1 preconditionMethod, CorrespondenceModel correspondenceModel) { + static def Iterable getCorrespondingElements(CorrespondenceModel correspondenceModel, EObject sourceElement, + Class expectedType, String expectedTag) { if (sourceElement === null) { - return #[]; + return #[] } - val nonNullPreconditionMethod = if (preconditionMethod !== null) preconditionMethod else [T input|true]; - val targetElements = new ArrayList(); - val correspondingObjects = getCorrespondingObjectsOfType(correspondenceModel, sourceElement, expectedTag, - affectedElementClass); - targetElements += correspondingObjects.filterNull.filter(nonNullPreconditionMethod); + return correspondenceModel.reactionsView.getCorrespondingEObjects(#[sourceElement], expectedTag).flatten.filter( + expectedType) + } - return targetElements; + static def Iterable getCorrespondingElements(CorrespondenceModel correspondenceModel, EObject sourceElement, + Class expectedType, String expectedTag, Function1 preconditionMethod) { + val correspondingObjects = correspondenceModel.getCorrespondingElements(sourceElement, expectedType, + expectedTag) + val nonNullPreconditionMethod = if(preconditionMethod !== null) preconditionMethod else [T input|true] + return correspondingObjects.filterNull.filter(nonNullPreconditionMethod) } } diff --git a/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/ReactionsCorrespondenceModelViewFactory.java b/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/helper/ReactionsCorrespondenceModelViewFactory.java similarity index 62% rename from bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/ReactionsCorrespondenceModelViewFactory.java rename to bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/helper/ReactionsCorrespondenceModelViewFactory.java index 96a0ab6eb..5f19c845a 100644 --- a/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/ReactionsCorrespondenceModelViewFactory.java +++ b/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/helper/ReactionsCorrespondenceModelViewFactory.java @@ -1,4 +1,4 @@ -package tools.vitruv.dsls.reactions.runtime; +package tools.vitruv.dsls.reactions.runtime.helper; import tools.vitruv.dsls.reactions.runtime.correspondence.ReactionsCorrespondence; import tools.vitruv.change.correspondence.CorrespondenceModelView; @@ -7,31 +7,29 @@ import tools.vitruv.change.correspondence.impl.CorrespondenceModelViewImpl; import tools.vitruv.dsls.reactions.runtime.correspondence.CorrespondenceFactory; -public class ReactionsCorrespondenceModelViewFactory implements - CorrespondenceModelViewFactory> { +final class ReactionsCorrespondenceModelViewFactory + implements CorrespondenceModelViewFactory> { private static ReactionsCorrespondenceModelViewFactory instance; - - private ReactionsCorrespondenceModelViewFactory() {} - + + private ReactionsCorrespondenceModelViewFactory() { + } + public static synchronized ReactionsCorrespondenceModelViewFactory getInstance() { if (instance == null) { instance = new ReactionsCorrespondenceModelViewFactory(); } return instance; } - + @Override - public CorrespondenceModelView createCorrespondenceModelView( - InternalCorrespondenceModel correspondenceModel) { - return new CorrespondenceModelViewImpl(ReactionsCorrespondence.class, - correspondenceModel, null); + public CorrespondenceModelView createCorrespondenceModelView(InternalCorrespondenceModel correspondenceModel) { + return new CorrespondenceModelViewImpl(ReactionsCorrespondence.class, correspondenceModel, null); } @Override - public CorrespondenceModelView createEditableCorrespondenceModelView( - InternalCorrespondenceModel correspondenceModel) { - return new CorrespondenceModelViewImpl(ReactionsCorrespondence.class, - correspondenceModel, () -> CorrespondenceFactory.eINSTANCE.createReactionsCorrespondence()); + public CorrespondenceModelView createEditableCorrespondenceModelView(InternalCorrespondenceModel correspondenceModel) { + return new CorrespondenceModelViewImpl(ReactionsCorrespondence.class, correspondenceModel, + () -> CorrespondenceFactory.eINSTANCE.createReactionsCorrespondence()); } } diff --git a/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/reactions/AbstractReaction.xtend b/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/reactions/AbstractReaction.xtend new file mode 100644 index 000000000..c8bc00e66 --- /dev/null +++ b/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/reactions/AbstractReaction.xtend @@ -0,0 +1,33 @@ +package tools.vitruv.dsls.reactions.runtime.reactions + +import tools.vitruv.dsls.reactions.runtime.structure.CallHierarchyHaving +import tools.vitruv.change.atomic.EChange +import tools.vitruv.dsls.reactions.runtime.state.ReactionExecutionState +import tools.vitruv.dsls.reactions.runtime.routines.RoutinesFacade +import java.util.function.Function + +/** + * A Reaction retrieves a routines facade upon each execution and applies the + * current execution's state to that facade such that it gets + * propagated through all routines and their used facades. + */ +abstract class AbstractReaction extends CallHierarchyHaving implements Reaction { + val Function routinesFacadeGenerator + + new(Function routinesFacadeGenerator) { + this.routinesFacadeGenerator = routinesFacadeGenerator + } + + override execute(EChange change, ReactionExecutionState reactionExecutionState) { + val routinesFacade = routinesFacadeGenerator.apply(reactionExecutionState) + routinesFacade._pushCaller(this) + try { + executeReaction(change, reactionExecutionState, routinesFacade) + } finally { + routinesFacade._dropLastCaller() + } + } + + protected def void executeReaction(EChange change, ReactionExecutionState executionState, RoutinesFacade routinesFacade) + +} diff --git a/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/reactions/AbstractReactionsChangePropagationSpecification.xtend b/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/reactions/AbstractReactionsChangePropagationSpecification.xtend new file mode 100644 index 000000000..19932995a --- /dev/null +++ b/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/reactions/AbstractReactionsChangePropagationSpecification.xtend @@ -0,0 +1,51 @@ +package tools.vitruv.dsls.reactions.runtime.reactions + +import tools.vitruv.change.composite.MetamodelDescriptor +import org.apache.log4j.Logger +import tools.vitruv.change.propagation.impl.AbstractChangePropagationSpecification +import java.util.List +import tools.vitruv.change.atomic.EChange +import tools.vitruv.change.correspondence.CorrespondenceModel +import tools.vitruv.change.interaction.UserInteractor +import tools.vitruv.change.propagation.ResourceAccess +import tools.vitruv.dsls.reactions.runtime.state.ReactionExecutionState + +/** + * A {@link ChangePropagationSpecification} that executes {@link Reaction}s. + */ +abstract class AbstractReactionsChangePropagationSpecification extends AbstractChangePropagationSpecification { + static val LOGGER = Logger.getLogger(AbstractReactionsChangePropagationSpecification) + + val List reactions + + new(MetamodelDescriptor sourceMetamodelDescriptor, MetamodelDescriptor targetMetamodelDescriptor) { + super(sourceMetamodelDescriptor, targetMetamodelDescriptor) + this.reactions = newArrayList + this.setup() + } + + protected def void addReaction(Reaction reaction) { + this.reactions += reaction + } + + override doesHandleChange(EChange change, CorrespondenceModel correspondenceModel) { + return true + } + + override propagateChange(EChange change, CorrespondenceModel correspondenceModel, ResourceAccess resourceAccess) { + LOGGER.trace("Call relevant reactions from " + sourceMetamodelDescriptor + " to " + targetMetamodelDescriptor) + for (reaction : reactions) { + LOGGER.trace("Calling reaction: " + reaction.class.simpleName + " with change: " + change) + val executionState = new ReactionExecutionState(userInteractor, correspondenceModel, resourceAccess, this) + reaction.execute(change, executionState) + } + } + + override setUserInteractor(UserInteractor userInteractor) { + super.setUserInteractor(userInteractor) + reactions.clear() + setup() + } + + protected abstract def void setup() +} diff --git a/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/reactions/Reaction.xtend b/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/reactions/Reaction.xtend new file mode 100644 index 000000000..fd9ebe394 --- /dev/null +++ b/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/reactions/Reaction.xtend @@ -0,0 +1,8 @@ +package tools.vitruv.dsls.reactions.runtime.reactions + +import tools.vitruv.change.atomic.EChange +import tools.vitruv.dsls.reactions.runtime.state.ReactionExecutionState + +interface Reaction { + def void execute(EChange change, ReactionExecutionState executionState) +} diff --git a/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/routines/AbstractRoutine.xtend b/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/routines/AbstractRoutine.xtend new file mode 100644 index 000000000..c81953239 --- /dev/null +++ b/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/routines/AbstractRoutine.xtend @@ -0,0 +1,204 @@ +package tools.vitruv.dsls.reactions.runtime.routines + +import java.io.IOException +import java.util.function.Function +import org.eclipse.emf.ecore.EObject +import org.eclipse.emf.ecore.resource.Resource +import org.eclipse.emf.ecore.util.EcoreUtil +import tools.vitruv.dsls.reactions.runtime.helper.PersistenceHelper +import static extension tools.vitruv.dsls.reactions.runtime.helper.ReactionsCorrespondenceHelper.getCorrespondingElements +import static extension tools.vitruv.dsls.reactions.runtime.helper.ReactionsCorrespondenceHelper.addCorrespondence +import static extension tools.vitruv.dsls.reactions.runtime.helper.ReactionsCorrespondenceHelper.removeCorrespondences +import tools.vitruv.dsls.reactions.runtime.structure.CallHierarchyHaving +import tools.vitruv.dsls.reactions.runtime.structure.Loggable +import tools.vitruv.change.propagation.ResourceAccess +import org.eclipse.emf.common.util.URI +import static com.google.common.base.Preconditions.checkState +import tools.vitruv.dsls.reactions.runtime.state.ReactionExecutionState +import org.eclipse.xtend.lib.annotations.Accessors +import tools.vitruv.change.correspondence.CorrespondenceModel + +abstract class AbstractRoutine extends CallHierarchyHaving implements Routine { + val AbstractRoutinesFacade routinesFacade + @Accessors(PROTECTED_GETTER) + extension val ReactionExecutionState executionState + + new(AbstractRoutinesFacade routinesFacade, ReactionExecutionState executionState, CallHierarchyHaving calledBy) { + super(calledBy) + this.routinesFacade = routinesFacade + this.executionState = executionState + } + + // generic return type for convenience; the requested type has to match the type of the facade provided during construction + protected def T getRoutinesFacade() { + return routinesFacade as T + } + + override boolean execute() { + routinesFacade._pushCaller(this) + + try { + return executeRoutine() + } finally { + routinesFacade._dropLastCaller() + } + } + + protected abstract def boolean executeRoutine() throws IOException + + private static class CorrespondenceRetriever extends Loggable { + CorrespondenceModel _correspondenceModel + + new(CorrespondenceModel correspondenceModel) { + this._correspondenceModel = correspondenceModel + } + + protected def boolean hasCorrespondingElements( + EObject correspondenceSource, + Class elementClass, + Function correspondencePreconditionMethod, + String tag + ) { + return !getCorrespondingElements(correspondenceSource, elementClass, correspondencePreconditionMethod, tag). + empty + } + + protected def Iterable getCorrespondingElements( + EObject correspondenceSource, + Class elementClass, + Function correspondencePreconditionMethod, + String tag + ) { + val Function preconditionMethod = correspondencePreconditionMethod ?: [true] + val retrievedElements = _correspondenceModel.getCorrespondingElements(correspondenceSource, + elementClass, tag, preconditionMethod) + return retrievedElements + } + + protected def T getCorrespondingElement( + EObject correspondenceSource, + Class elementClass, + Function correspondencePreconditionMethod, + String tag, + boolean asserted + ) { + val retrievedElements = getCorrespondingElements(correspondenceSource, elementClass, + correspondencePreconditionMethod, tag) + checkState(retrievedElements.size <= 1 && (!asserted || retrievedElements.size == 1), + "There were (%s) corresponding elements of type %s for: %s, which are: %s", retrievedElements.size, + elementClass.simpleName, correspondenceSource, retrievedElements) + val retrievedElement = retrievedElements.head + return retrievedElement + } + } + + static class Match extends CorrespondenceRetriever { + protected val extension ReactionExecutionState executionState + + new(ReactionExecutionState executionState) { + super(executionState.correspondenceModel) + this.executionState = executionState + } + + } + + static class Create extends Loggable { + protected val extension ReactionExecutionState executionState + + new(ReactionExecutionState executionState) { + this.executionState = executionState + } + + protected def T createObject(()=>T creator) { + val createdObject = creator.apply + createdObject.notifyObjectCreated + return createdObject + } + + private def void notifyObjectCreated(EObject createdObject) { + executionState.changePropagationObservable.notifyObjectCreated(createdObject) + } + } + + static class Update extends CorrespondenceRetriever { + protected val extension ReactionExecutionState executionState + + new(ReactionExecutionState executionState) { + super(executionState.correspondenceModel) + this.executionState = executionState + } + + /** + * Persists a given {@link EObject} as root object in the {@link Resource} at the specified path, + * relative to the project root folder. + * + * @param alreadyPersistedObject - + * An object that was already persisted within the project (necessary for retrieving the project folder) + * @param elementToPersist - + * The element to be persisted + * @param persistencePath - + * The path relative to the project root folder at which the element shall be persisted, + * using "/" as separator char and including the file name with extension + */ + protected def persistProjectRelative(EObject alreadyPersistedObject, EObject elementToPersist, + String persistencePath) { + if (alreadyPersistedObject === null || elementToPersist === null || persistencePath === null) { + throw new IllegalArgumentException( + "correspondenceSource, element and persistancePath must be specified") + } + + val _resourceURI = PersistenceHelper.getURIFromSourceProjectFolder(alreadyPersistedObject, persistencePath) + persistAsRoot(elementToPersist, _resourceURI) + } + + /** + * Persists the given object as root of the metadata model specified by + * the given metadata key. + * + * @param rootObject The root object, not null. + * @param metadataKey The key uniquely identifying the metadata model. + * See {@link ResourceAccess#getMetadataModelURI}. + */ + protected def persistAsMetadataRoot(EObject rootObject, String... metadataKey) { + if (rootObject === null) { + throw new IllegalArgumentException("rootObject is null!") + } + val modelURI = resourceAccess.getMetadataModelURI(metadataKey) + persistAsRoot(rootObject, modelURI) + } + + private def persistAsRoot(EObject rootObject, URI uri) { + logger.trace("Registered to persist root " + rootObject + " in: " + uri) + if (rootObject.eResource?.URI !== uri) { + EcoreUtil.remove(rootObject) + resourceAccess.persistAsRoot(rootObject, uri) + } + } + + protected def void addCorrespondenceBetween(EObject firstElement, EObject secondElement) { + addCorrespondenceBetween(firstElement, secondElement, null) + } + + protected def void addCorrespondenceBetween(EObject firstElement, EObject secondElement, String tag) { + correspondenceModel.addCorrespondence(firstElement, secondElement, tag) + } + + def void removeObject(EObject element) { + if (element === null) { + return + } + if (logger.debugEnabled) { + logger.debug("Removing object " + element + " from container " + element.eContainer()) + } + EcoreUtil.remove(element) + } + + protected def void removeCorrespondenceBetween(EObject firstElement, EObject secondElement) { + removeCorrespondenceBetween(firstElement, secondElement, null) + } + + protected def void removeCorrespondenceBetween(EObject firstElement, EObject secondElement, String tag) { + correspondenceModel.removeCorrespondences(firstElement, secondElement, tag) + } + } +} diff --git a/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/routines/AbstractRoutinesFacade.xtend b/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/routines/AbstractRoutinesFacade.xtend new file mode 100644 index 000000000..4f84abb98 --- /dev/null +++ b/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/routines/AbstractRoutinesFacade.xtend @@ -0,0 +1,55 @@ +package tools.vitruv.dsls.reactions.runtime.routines + +import tools.vitruv.dsls.reactions.runtime.structure.Loggable +import tools.vitruv.dsls.reactions.runtime.structure.ReactionsImportPath +import tools.vitruv.dsls.reactions.runtime.state.ReactionExecutionState +import tools.vitruv.dsls.reactions.runtime.structure.CallHierarchyHaving +import java.util.Stack + +/** + * Note: All methods start with an underscore here to not conflict with the methods that are generated from the routines by + * concrete implementations. + */ +abstract class AbstractRoutinesFacade extends Loggable implements RoutinesFacade { + // used by concrete implementations to request routines facades of executed routines: + val RoutinesFacadesProvider routinesFacadesProvider + // absolute path inside the import hierarchy to the segment this routines facade belongs to, never null: + val ReactionsImportPath reactionsImportPath + // shared execution state among all routines facades in the import hierarchy: + var ReactionExecutionState executionState + val Stack callerStack = new Stack() + + new(RoutinesFacadesProvider routinesFacadesProvider, ReactionsImportPath reactionsImportPath) { + this.routinesFacadesProvider = routinesFacadesProvider + this.reactionsImportPath = reactionsImportPath + } + + protected def RoutinesFacadesProvider _getRoutinesFacadesProvider() { + return routinesFacadesProvider + } + + protected def ReactionsImportPath _getReactionsImportPath() { + return reactionsImportPath + } + + override _setExecutionState(ReactionExecutionState executionState) { + this.executionState = executionState + } + + override _getExecutionState() { + return executionState + } + + override _pushCaller(CallHierarchyHaving caller) { + callerStack.push(caller) + } + + override _getCurrentCaller() { + return if (!callerStack.empty()) callerStack.peek() else null + } + + override _dropLastCaller() { + callerStack.pop() + } + +} diff --git a/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/AbstractRoutinesFacadesProvider.xtend b/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/routines/AbstractRoutinesFacadesProvider.xtend similarity index 53% rename from bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/AbstractRoutinesFacadesProvider.xtend rename to bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/routines/AbstractRoutinesFacadesProvider.xtend index 6a19c6101..6340eb3d5 100644 --- a/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/AbstractRoutinesFacadesProvider.xtend +++ b/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/routines/AbstractRoutinesFacadesProvider.xtend @@ -1,10 +1,11 @@ -package tools.vitruv.dsls.reactions.runtime +package tools.vitruv.dsls.reactions.runtime.routines import java.util.HashMap import java.util.Map import tools.vitruv.dsls.reactions.runtime.structure.ReactionsImportPath import static com.google.common.base.Preconditions.* +import tools.vitruv.dsls.reactions.runtime.state.ReactionExecutionState /** * A RoutinesFacadesProvider which caches created routines facades. @@ -14,28 +15,31 @@ import static com.google.common.base.Preconditions.* */ abstract class AbstractRoutinesFacadesProvider implements RoutinesFacadesProvider { - val RoutinesFacadeExecutionState sharedRoutinesFacadeExecutionState = new RoutinesFacadeExecutionState(); // the routines facades that were created so far: - val Map routinesFacades = new HashMap(); + val Map routinesFacades = new HashMap() - new() { + val ReactionExecutionState executionState + + new(ReactionExecutionState executionState) { + this.executionState = executionState } // creates the specified routines facade: - protected def abstract AbstractRepairRoutinesFacade createRoutinesFacade(ReactionsImportPath reactionsImportPath, RoutinesFacadeExecutionState sharedExecutionState); + protected def abstract AbstractRoutinesFacade createRoutinesFacade(ReactionsImportPath reactionsImportPath) - override T getRoutinesFacade(ReactionsImportPath reactionsImportPath) { - checkNotNull(reactionsImportPath, "reactionsImportPath is null"); + override T getRoutinesFacade(ReactionsImportPath reactionsImportPath) { + checkNotNull(reactionsImportPath, "reactionsImportPath is null") // check if we already created the requested routines facade: - var T routinesFacade = routinesFacades.get(reactionsImportPath) as T; - if (routinesFacade !== null) return routinesFacade; + var T routinesFacade = routinesFacades.get(reactionsImportPath) as T + if(routinesFacade !== null) return routinesFacade // create the routines facade: - routinesFacade = this.createRoutinesFacade(reactionsImportPath, sharedRoutinesFacadeExecutionState) as T; + routinesFacade = this.createRoutinesFacade(reactionsImportPath) as T if (routinesFacade !== null) { + routinesFacade._setExecutionState(executionState) // store created routines facade: - routinesFacades.put(reactionsImportPath, routinesFacade); - return routinesFacade; + routinesFacades.put(reactionsImportPath, routinesFacade) + return routinesFacade } - return routinesFacade; + return routinesFacade } } diff --git a/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/routines/Routine.xtend b/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/routines/Routine.xtend new file mode 100644 index 000000000..02cab22ad --- /dev/null +++ b/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/routines/Routine.xtend @@ -0,0 +1,5 @@ +package tools.vitruv.dsls.reactions.runtime.routines + +interface Routine { + def boolean execute() +} diff --git a/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/routines/RoutinesFacade.xtend b/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/routines/RoutinesFacade.xtend new file mode 100644 index 000000000..4c4cefc95 --- /dev/null +++ b/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/routines/RoutinesFacade.xtend @@ -0,0 +1,35 @@ +package tools.vitruv.dsls.reactions.runtime.routines + +import tools.vitruv.dsls.reactions.runtime.structure.CallHierarchyHaving +import tools.vitruv.dsls.reactions.runtime.state.ReactionExecutionState + +/** + * Note: All methods start with an underscore here to not conflict with the methods that are generated from the routines by + * concrete implementations of a facade + */ +interface RoutinesFacade { + /** + * Sets the execution state for the current execution run. + */ + def void _setExecutionState(ReactionExecutionState executionState) + + /** + * Returns the execution state of the current execution run. + */ + def ReactionExecutionState _getExecutionState() + + /** + * Pushes the given caller to the call stack. + */ + def void _pushCaller(CallHierarchyHaving caller) + + /** + * Returns the current routine caller + */ + def CallHierarchyHaving _getCurrentCaller() + + /** + * Drops the last caller from the call stack. + */ + def void _dropLastCaller() +} diff --git a/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/RoutinesFacadesProvider.xtend b/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/routines/RoutinesFacadesProvider.xtend similarity index 83% rename from bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/RoutinesFacadesProvider.xtend rename to bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/routines/RoutinesFacadesProvider.xtend index d1eec6d79..ad12d9850 100644 --- a/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/RoutinesFacadesProvider.xtend +++ b/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/routines/RoutinesFacadesProvider.xtend @@ -1,4 +1,4 @@ -package tools.vitruv.dsls.reactions.runtime +package tools.vitruv.dsls.reactions.runtime.routines import tools.vitruv.dsls.reactions.runtime.structure.ReactionsImportPath @@ -18,5 +18,5 @@ interface RoutinesFacadesProvider { * @throws IllegalArgumentException if the specified import path is not valid (for ex. does not exist in the import hierarchy) * @throws ClassCastException if the specified routines facade type is not applicable to the actually returned routines facade */ - def T getRoutinesFacade(ReactionsImportPath reactionsImportPath); + def T getRoutinesFacade(ReactionsImportPath reactionsImportPath) } diff --git a/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/ReactionExecutionState.xtend b/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/state/ReactionExecutionState.xtend similarity index 90% rename from bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/ReactionExecutionState.xtend rename to bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/state/ReactionExecutionState.xtend index 61792cd6c..32a6022dc 100644 --- a/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/ReactionExecutionState.xtend +++ b/bundles/tools.vitruv.dsls.reactions.runtime/src/tools/vitruv/dsls/reactions/runtime/state/ReactionExecutionState.xtend @@ -1,4 +1,4 @@ -package tools.vitruv.dsls.reactions.runtime +package tools.vitruv.dsls.reactions.runtime.state import tools.vitruv.change.interaction.UserInteractor import tools.vitruv.change.correspondence.CorrespondenceModel diff --git a/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/builder/FluentRoutineBuilder.xtend b/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/builder/FluentRoutineBuilder.xtend index a16aa09e9..61761e21d 100644 --- a/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/builder/FluentRoutineBuilder.xtend +++ b/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/builder/FluentRoutineBuilder.xtend @@ -22,9 +22,9 @@ import static tools.vitruv.dsls.reactions.codegen.ReactionsLanguageConstants.* import tools.vitruv.dsls.reactions.language.LanguageFactory import tools.vitruv.dsls.common.elements.ElementsFactory import org.eclipse.xtext.xbase.XBlockExpression -import tools.vitruv.dsls.reactions.runtime.AbstractRepairRoutineRealization import tools.vitruv.dsls.common.elements.NamedMetaclassReference import org.eclipse.xtext.xbase.XFeatureCall +import tools.vitruv.dsls.reactions.runtime.routines.AbstractRoutine class FluentRoutineBuilder extends FluentReactionsSegmentChildBuilder { @@ -492,7 +492,7 @@ class FluentRoutineBuilder extends FluentReactionsSegmentChildBuilder { val statement = (XbaseFactory.eINSTANCE.createXFeatureCall => [ explicitOperationCall = true ]).whenJvmTypes [ - feature = typeProvider.findMethod(AbstractRepairRoutineRealization.Update, 'removeObject') + feature = typeProvider.findMethod(AbstractRoutine.Update, 'removeObject') featureCallArguments += existingElement(existingElement) ] expressionBlock.expressions += statement @@ -526,7 +526,7 @@ class FluentRoutineBuilder extends FluentReactionsSegmentChildBuilder { (XbaseFactory.eINSTANCE.createXFeatureCall => [ explicitOperationCall = true ]).whenJvmTypes [ - feature = typeProvider.findMethod(AbstractRepairRoutineRealization.Update, 'addCorrespondenceBetween') + feature = typeProvider.findMethod(AbstractRoutine.Update, 'addCorrespondenceBetween') ] } @@ -558,7 +558,7 @@ class FluentRoutineBuilder extends FluentReactionsSegmentChildBuilder { (XbaseFactory.eINSTANCE.createXFeatureCall => [ explicitOperationCall = true ]).whenJvmTypes [ - feature = typeProvider.findMethod(AbstractRepairRoutineRealization.Update, 'removeCorrespondenceBetween') + feature = typeProvider.findMethod(AbstractRoutine.Update, 'removeCorrespondenceBetween') ] } diff --git a/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/ReactionsLanguageConstants.xtend b/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/ReactionsLanguageConstants.xtend index 405d50e93..e483bc418 100644 --- a/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/ReactionsLanguageConstants.xtend +++ b/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/ReactionsLanguageConstants.xtend @@ -8,7 +8,6 @@ import edu.kit.ipd.sdq.activextendannotations.Utility public static val RETRIEVAL_PRECONDITION_METHOD_TARGET = "potentialTarget" static val ROUTINES_FACADE_NAME = "routinesFacade"; public static val ROUTINES_FACADE_PARAMETER_NAME = ROUTINES_FACADE_NAME; - public static val ROUTINES_FACADE_FIELD_NAME = ROUTINES_FACADE_NAME; static val USER_INTERACTING_NAME = "userInteractor"; public static val USER_INTERACTING_PARAMETER_NAME = USER_INTERACTING_NAME; public static val USER_INTERACTING_FIELD_NAME = USER_INTERACTING_NAME; @@ -17,9 +16,6 @@ import edu.kit.ipd.sdq.activextendannotations.Utility public static val REACTION_EXECUTION_STATE_FIELD_NAME = REACTION_EXECUTION_STATE_NAME; public static val CHANGE_PARAMETER_NAME = "change"; - public static val ROUTINES_FACADE_CALLER_FIELD_NAME = "caller"; - - public static val EFFECT_USER_EXECUTION_SIMPLE_NAME = "RoutineCall"; public static val REACTION_USER_EXECUTION_ROUTINE_CALL_FACADE_PARAMETER_NAME = "_routinesFacade" public static val CHANGE_AFFECTED_ELEMENT_ATTRIBUTE = "affectedEObject" diff --git a/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/ChangePropagationSpecificationClassGenerator.xtend b/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/ChangePropagationSpecificationClassGenerator.xtend index 7afa7cf17..88f2b7469 100644 --- a/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/ChangePropagationSpecificationClassGenerator.xtend +++ b/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/ChangePropagationSpecificationClassGenerator.xtend @@ -1,61 +1,79 @@ package tools.vitruv.dsls.reactions.codegen.classgenerators -import java.util.ArrayList import org.eclipse.emf.ecore.impl.EPackageImpl import org.eclipse.xtext.common.types.JvmGenericType import org.eclipse.xtext.common.types.JvmVisibility import tools.vitruv.dsls.reactions.codegen.typesbuilder.TypesBuilderExtensionProvider import tools.vitruv.dsls.reactions.language.toplevelelements.ReactionsSegment -import tools.vitruv.dsls.reactions.runtime.AbstractReactionsChangePropagationSpecification +import tools.vitruv.dsls.reactions.runtime.reactions.AbstractReactionsChangePropagationSpecification import tools.vitruv.change.propagation.ChangePropagationSpecification -import static extension tools.vitruv.dsls.reactions.codegen.helper.ClassNamesGenerators.* +import static extension tools.vitruv.dsls.reactions.codegen.helper.ReactionsImportsHelper.getIncludedReactions +import static extension tools.vitruv.dsls.reactions.codegen.helper.ClassNamesGenerators.getReactionClassNameGenerator +import static extension tools.vitruv.dsls.reactions.codegen.helper.ClassNamesGenerators.getChangePropagationSpecificationClassNameGenerator +import static extension tools.vitruv.dsls.reactions.codegen.helper.ClassNamesGenerators.getRoutinesFacadesProviderClassNameGenerator import static extension tools.vitruv.dsls.reactions.codegen.helper.ReactionsElementsCompletionChecker.isReferenceable import java.util.Set import tools.vitruv.change.composite.MetamodelDescriptor +import tools.vitruv.dsls.reactions.runtime.structure.ReactionsImportPath +import static com.google.common.base.Preconditions.checkState +import tools.vitruv.dsls.reactions.runtime.routines.RoutinesFacadesProvider +import tools.vitruv.dsls.reactions.runtime.state.ReactionExecutionState +import tools.vitruv.dsls.reactions.codegen.helper.AccessibleElement class ChangePropagationSpecificationClassGenerator extends ClassGenerator { - final ReactionsSegment reactionsSegment; - var JvmGenericType generatedClass; + final ReactionsSegment reactionsSegment + var JvmGenericType generatedClass new(ReactionsSegment reactionsSegment, TypesBuilderExtensionProvider typesBuilderExtensionProvider) { super(typesBuilderExtensionProvider) - if (!reactionsSegment.isReferenceable) { - throw new IllegalArgumentException("incomplete"); - } - this.reactionsSegment = reactionsSegment; + checkState(reactionsSegment.isReferenceable, "reactions segment is incomplete") + this.reactionsSegment = reactionsSegment } override generateEmptyClass() { generatedClass = reactionsSegment.toClass( reactionsSegment.changePropagationSpecificationClassNameGenerator.qualifiedName) [ - visibility = JvmVisibility.PUBLIC; - ]; + visibility = JvmVisibility.PUBLIC + ] } override generateBody() { generatedClass => [ - superTypes += typeRef(AbstractReactionsChangePropagationSpecification); - superTypes += typeRef(ChangePropagationSpecification); + superTypes += typeRef(AbstractReactionsChangePropagationSpecification) + superTypes += typeRef(ChangePropagationSpecification) members += reactionsSegment.toConstructor() [ body = ''' super(«MetamodelDescriptor».with(«Set».of(«FOR namespaceUri : reactionsSegment.fromMetamodels.map[package.nsURI] SEPARATOR ','»"«namespaceUri»"«ENDFOR»)), «MetamodelDescriptor».with(«Set».of(«FOR namespaceUri : reactionsSegment.toMetamodels.map[package.nsURI] SEPARATOR ','»"«namespaceUri»"«ENDFOR»)));''' ] + + // create routines facades provider: + members += reactionsSegment.toMethod("createRoutinesFacadesProvider", typeRef(RoutinesFacadesProvider)) [ + visibility = JvmVisibility.PROTECTED + val executionStateParameter = generateParameter(new AccessibleElement("executionState", ReactionExecutionState)) + parameters += executionStateParameter + body = ''' + return new «reactionsSegment.routinesFacadesProviderClassNameGenerator.qualifiedName»(«executionStateParameter.name»); + ''' + ] - // register executor as change processor: + // register all reactions, including imported and overridden reactions: members += reactionsSegment.toMethod("setup", typeRef(Void.TYPE)) [ - visibility = JvmVisibility.PROTECTED; - val metamodelPackageClassQualifiedNames = new ArrayList - metamodelPackageClassQualifiedNames += - (reactionsSegment.fromMetamodels + reactionsSegment.toMetamodels).map[package.class].filter [ - it !== EPackageImpl - ].map[name] + visibility = JvmVisibility.PROTECTED + val metamodelPackageClassQualifiedNames = (reactionsSegment.fromMetamodels + + reactionsSegment.toMetamodels).map[package.class].filter[it !== EPackageImpl].map[name] body = ''' «FOR metamodelPackageClassQualifiedName : metamodelPackageClassQualifiedNames»org.eclipse.emf.ecore.EPackage.Registry.INSTANCE.putIfAbsent(« metamodelPackageClassQualifiedName».eNS_URI, «metamodelPackageClassQualifiedName».eINSTANCE); «ENDFOR» - this.addChangeMainprocessor(new «reactionsSegment.executorClassNameGenerator.qualifiedName»()); + «FOR reactionEntry : reactionsSegment.includedReactions.entrySet.filter[key.isReferenceable]» + «val reaction = reactionEntry.key» + «val reactionsImportPath = reactionEntry.value» + «val reactionsNameGenerator = reaction.reactionClassNameGenerator» + addReaction(new «reactionsNameGenerator.qualifiedName»((executionState) -> createRoutinesFacadesProvider(executionState).getRoutinesFacade(« + »«ReactionsImportPath».fromPathString("«reactionsImportPath.pathString»")))); + «ENDFOR» ''' ] ] diff --git a/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/ClassGenerator.xtend b/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/ClassGenerator.xtend index e93f891c3..5740c6365 100644 --- a/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/ClassGenerator.xtend +++ b/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/ClassGenerator.xtend @@ -1,12 +1,7 @@ package tools.vitruv.dsls.reactions.codegen.classgenerators import org.eclipse.xtext.common.types.JvmGenericType -import java.util.Map -import org.eclipse.xtext.common.types.JvmOperation import org.eclipse.emf.ecore.EObject -import org.eclipse.xtext.common.types.JvmTypeReference -import org.eclipse.xtext.xbase.lib.Procedures.Procedure1 -import java.util.HashMap import tools.vitruv.dsls.reactions.codegen.helper.AccessibleElement import tools.vitruv.dsls.reactions.codegen.typesbuilder.TypesBuilderExtensionProvider import static extension edu.kit.ipd.sdq.commons.util.java.lang.IterableUtil.mapFixed @@ -22,47 +17,20 @@ import org.eclipse.xtext.common.types.JvmVisibility * {@link ClassGenerator#generateEmptyClass() generateEmptyClass} * and {@link ClassGenerator#generateBody(JvmGenericType) generateBody} for those steps. */ -abstract class ClassGenerator extends TypesBuilderExtensionProvider implements IJvmOperationRegistry { - Map methodMap; - +abstract class ClassGenerator extends TypesBuilderExtensionProvider { protected def generateAccessibleElementsParameters(EObject sourceObject, Iterable accessibleElements) { - sourceObject.generateMethodInputParameters(accessibleElements) + sourceObject.generateParameters(accessibleElements) } new(TypesBuilderExtensionProvider typesBuilderExtensionProvider) { typesBuilderExtensionProvider.copyBuildersTo(this); - this.methodMap = new HashMap(); } def JvmGenericType generateEmptyClass() def JvmGenericType generateBody() - override JvmOperation getOrGenerateMethod(EObject contextObject, String methodName, JvmTypeReference returnType, - Procedure1 initializer) { - if (!methodMap.containsKey(methodName)) { - val operation = contextObject.toMethod(methodName, returnType, initializer); - methodMap.put(operation.simpleName, operation); - } - - return methodMap.get(methodName); - } - - override JvmOperation getOrGenerateMethod(String methodName, JvmTypeReference returnType, - Procedure1 initializer) { - if (!methodMap.containsKey(methodName)) { - val operation = generateUnassociatedMethod(methodName, returnType, initializer); - methodMap.put(operation.simpleName, operation); - } - - return methodMap.get(methodName); - } - - protected def Iterable getGeneratedMethods() { - return methodMap.values; - } - protected def getCommentWithoutMarkers(String documentation) { if (documentation !== null && documentation.length > 4) { val withoutMultilineCommentMarkers = documentation.replaceAll("\\n \\* ","\\n") @@ -74,7 +42,7 @@ abstract class ClassGenerator extends TypesBuilderExtensionProvider implements I protected def generateElementsContainerClass(String qualifiedClassName, Iterable elements) { generateUnassociatedClass(qualifiedClassName) [ - val retrievedElementParameters = generateMethodInputParameters(elements) + val retrievedElementParameters = generateParameters(elements) members += retrievedElementParameters.mapFixed[ toField(name, parameterType) => [ final = true diff --git a/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/ExecutorClassGenerator.xtend b/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/ExecutorClassGenerator.xtend deleted file mode 100644 index 0bd0ef3c8..000000000 --- a/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/ExecutorClassGenerator.xtend +++ /dev/null @@ -1,69 +0,0 @@ -package tools.vitruv.dsls.reactions.codegen.classgenerators - -import org.eclipse.xtext.common.types.JvmGenericType -import tools.vitruv.dsls.reactions.codegen.classgenerators.ClassGenerator -import org.eclipse.xtext.common.types.JvmVisibility -import tools.vitruv.dsls.reactions.language.toplevelelements.ReactionsSegment -import tools.vitruv.dsls.reactions.runtime.AbstractReactionsExecutor -import tools.vitruv.dsls.reactions.runtime.RoutinesFacadesProvider -import tools.vitruv.dsls.reactions.runtime.structure.ReactionsImportPath -import static extension tools.vitruv.dsls.reactions.codegen.helper.ClassNamesGenerators.* -import tools.vitruv.dsls.reactions.codegen.typesbuilder.TypesBuilderExtensionProvider -import static extension tools.vitruv.dsls.reactions.codegen.helper.ReactionsImportsHelper.*; -import static extension tools.vitruv.dsls.reactions.codegen.helper.ReactionsElementsCompletionChecker.isReferenceable -import static extension tools.vitruv.dsls.reactions.codegen.helper.ReactionsElementsCompletionChecker.isComplete -import java.util.Set -import tools.vitruv.change.composite.MetamodelDescriptor - -class ExecutorClassGenerator extends ClassGenerator { - final ReactionsSegment reactionsSegment; - var JvmGenericType generatedClass; - - new(ReactionsSegment reactionsSegment, TypesBuilderExtensionProvider typesBuilderExtensionProvider) { - super(typesBuilderExtensionProvider) - if (!reactionsSegment.isReferenceable) { - throw new IllegalArgumentException("incomplete"); - } - this.reactionsSegment = reactionsSegment; - } - - override generateEmptyClass() { - generatedClass = reactionsSegment.toClass(reactionsSegment.executorClassNameGenerator.qualifiedName) [ - visibility = JvmVisibility.DEFAULT; - ]; - } - - override generateBody() { - generatedClass => [ - superTypes += typeRef(AbstractReactionsExecutor); - members += reactionsSegment.toConstructor() [ - body = ''' - super(«MetamodelDescriptor».with(«Set».of(«FOR namespaceUri : reactionsSegment.fromMetamodels.map[package.nsURI] SEPARATOR ','»"«namespaceUri»"«ENDFOR»)), - «MetamodelDescriptor».with(«Set».of(«FOR namespaceUri : reactionsSegment.toMetamodels.map[package.nsURI] SEPARATOR ','»"«namespaceUri»"«ENDFOR»)));''' - ] - - // create routines facades provider: - members += reactionsSegment.toMethod("createRoutinesFacadesProvider", typeRef(RoutinesFacadesProvider)) [ - visibility = JvmVisibility.PROTECTED; - body = ''' - return new «reactionsSegment.routinesFacadesProviderClassNameGenerator.qualifiedName»(); - ''' - ] - - // register all reactions, including imported and overridden reactions: - members += reactionsSegment.toMethod("setup", typeRef(Void.TYPE)) [ - visibility = JvmVisibility.PROTECTED; - body = ''' - «FOR reactionEntry : reactionsSegment.includedReactions.entrySet.filter[key.isReferenceable]» - «val reaction = reactionEntry.key» - «val reactionsImportPath = reactionEntry.value» - «val reactionsNameGenerator = reaction.reactionClassNameGenerator» - this.addReaction(new «reactionsNameGenerator.qualifiedName»(this.getRoutinesFacadesProvider().getRoutinesFacade(« - »«ReactionsImportPath».fromPathString("«reactionsImportPath.pathString»")))); - «ENDFOR» - ''' - ] - ] - } - -} \ No newline at end of file diff --git a/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/IJvmOperationRegistry.xtend b/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/IJvmOperationRegistry.xtend deleted file mode 100644 index 657e53103..000000000 --- a/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/IJvmOperationRegistry.xtend +++ /dev/null @@ -1,11 +0,0 @@ -package tools.vitruv.dsls.reactions.codegen.classgenerators - -import org.eclipse.xtext.common.types.JvmTypeReference -import org.eclipse.xtext.xbase.lib.Procedures.Procedure1 -import org.eclipse.xtext.common.types.JvmOperation -import org.eclipse.emf.ecore.EObject - -interface IJvmOperationRegistry { - def JvmOperation getOrGenerateMethod(EObject contextObject, String methodName, JvmTypeReference returnType, Procedure1 initializer); - def JvmOperation getOrGenerateMethod(String methodName, JvmTypeReference returnType, Procedure1 initializer); -} \ No newline at end of file diff --git a/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/ReactionClassGenerator.xtend b/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/ReactionClassGenerator.xtend index c1d349c11..8e72e20cf 100644 --- a/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/ReactionClassGenerator.xtend +++ b/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/ReactionClassGenerator.xtend @@ -4,21 +4,25 @@ import org.eclipse.xtext.common.types.JvmConstructor import org.eclipse.xtext.common.types.JvmGenericType import org.eclipse.xtext.common.types.JvmVisibility import org.eclipse.xtext.common.types.JvmOperation -import tools.vitruv.dsls.reactions.runtime.AbstractReactionRealization import tools.vitruv.dsls.reactions.language.toplevelelements.Reaction import static extension tools.vitruv.dsls.reactions.codegen.helper.ClassNamesGenerators.* import static extension tools.vitruv.dsls.reactions.codegen.changetyperepresentation.ChangeTypeRepresentationExtractor.* import tools.vitruv.dsls.reactions.codegen.typesbuilder.TypesBuilderExtensionProvider import tools.vitruv.dsls.reactions.codegen.changetyperepresentation.ChangeTypeRepresentation -import tools.vitruv.dsls.reactions.codegen.classgenerators.routine.StepExecutionClassGenerator -import tools.vitruv.dsls.reactions.codegen.classgenerators.routine.UpdateBlockClassGenerator -import tools.vitruv.dsls.reactions.codegen.classgenerators.routine.EmptyStepExecutionClassGenerator +import tools.vitruv.dsls.reactions.codegen.classgenerators.steps.StepExecutionClassGenerator +import tools.vitruv.dsls.reactions.codegen.classgenerators.steps.UpdateBlockClassGenerator +import tools.vitruv.dsls.reactions.codegen.classgenerators.steps.EmptyStepExecutionClassGenerator import org.eclipse.xtend2.lib.StringConcatenationClient import static com.google.common.base.Preconditions.checkArgument +import tools.vitruv.dsls.reactions.runtime.reactions.AbstractReaction +import tools.vitruv.dsls.reactions.runtime.routines.RoutinesFacade +import tools.vitruv.dsls.reactions.runtime.state.ReactionExecutionState +import java.util.function.Function +import tools.vitruv.dsls.reactions.codegen.helper.AccessibleElement class ReactionClassGenerator extends ClassGenerator { static val EXECUTION_STATE_VARIABLE = "executionState" - static val ROUTINES_FACADE_VARIABLE = "getRoutinesFacade()" + static val ROUTINES_FACADE_VARIABLE = "routinesFacade" static val EXECUTE_REACTION_METHOD_NAME = "executeReaction" static val MATCH_CHANGE_METHOD_NAME = "isCurrentChangeMatchingTrigger" @@ -57,7 +61,7 @@ class ReactionClassGenerator extends ClassGenerator { override generateBody() { generatedClass => [ documentation = getCommentWithoutMarkers(reaction.documentation) - superTypes += typeRef(AbstractReactionRealization) + superTypes += typeRef(AbstractReaction) members += reaction.toField(changeType.name, changeType.accessibleElement.generateTypeRef(_typeReferenceBuilder)) members += reaction.generateConstructor() @@ -69,7 +73,7 @@ class ReactionClassGenerator extends ClassGenerator { private def JvmConstructor generateConstructor(Reaction reaction) { return reaction.toConstructor [ visibility = JvmVisibility.PUBLIC - val routinesFacadeParameter = generateRoutinesFacadeParameter(reaction.reactionsSegment) + val routinesFacadeParameter = generateParameter(new AccessibleElement(ROUTINES_FACADE_VARIABLE + "Generator", Function.name, ReactionExecutionState.name, RoutinesFacade.name)) parameters += routinesFacadeParameter body = ''' super(«routinesFacadeParameter.name»); @@ -83,8 +87,14 @@ class ReactionClassGenerator extends ClassGenerator { val executeReactionMethod = reaction.toMethod(EXECUTE_REACTION_METHOD_NAME, typeRef(Void.TYPE)) [ visibility = JvmVisibility.PUBLIC val changeParameter = generateUntypedChangeParameter + val reactionExecutionStateParameter = generateParameter(new AccessibleElement(EXECUTION_STATE_VARIABLE, ReactionExecutionState)) + val routinesFacadeParameter = generateParameter(new AccessibleElement(ROUTINES_FACADE_VARIABLE + "Untyped", RoutinesFacade)) parameters += changeParameter + parameters += reactionExecutionStateParameter + parameters += routinesFacadeParameter + val facadeClassName = reaction.reactionsSegment.routinesFacadeClassNameGenerator.qualifiedName body = ''' + «facadeClassName» «ROUTINES_FACADE_VARIABLE» = («facadeClassName»)«ROUTINES_FACADE_VARIABLE»Untyped; «generateMatchChangeMethodCallCode(matchChangeMethod, changeParameter.name)» «changeType.generatePropertiesAssignmentCode» «generateUserDefinedPreconditionMethodCall(userDefinedPreconditionMethod)» diff --git a/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/RoutineClassGenerator.xtend b/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/RoutineClassGenerator.xtend index 5fe5aba74..2354463ea 100644 --- a/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/RoutineClassGenerator.xtend +++ b/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/RoutineClassGenerator.xtend @@ -7,18 +7,18 @@ import static extension edu.kit.ipd.sdq.commons.util.java.lang.IterableUtil.* import org.eclipse.xtext.common.types.JvmConstructor import tools.vitruv.dsls.reactions.runtime.structure.CallHierarchyHaving import tools.vitruv.dsls.reactions.language.toplevelelements.Routine -import tools.vitruv.dsls.reactions.runtime.AbstractRepairRoutineRealization import static extension tools.vitruv.dsls.reactions.codegen.helper.ClassNamesGenerators.* import tools.vitruv.dsls.reactions.codegen.helper.AccessibleElement import tools.vitruv.dsls.reactions.codegen.typesbuilder.TypesBuilderExtensionProvider import tools.vitruv.dsls.common.ClassNameGenerator import static extension tools.vitruv.dsls.reactions.codegen.helper.ReactionsElementsCompletionChecker.isReferenceable -import tools.vitruv.dsls.reactions.codegen.classgenerators.routine.CreateBlockClassGenerator -import tools.vitruv.dsls.reactions.codegen.classgenerators.routine.MatchBlockClassGenerator -import tools.vitruv.dsls.reactions.codegen.classgenerators.routine.UpdateBlockClassGenerator +import tools.vitruv.dsls.reactions.codegen.classgenerators.steps.CreateBlockClassGenerator +import tools.vitruv.dsls.reactions.codegen.classgenerators.steps.MatchBlockClassGenerator +import tools.vitruv.dsls.reactions.codegen.classgenerators.steps.UpdateBlockClassGenerator import org.eclipse.xtend2.lib.StringConcatenationClient -import tools.vitruv.dsls.reactions.codegen.classgenerators.routine.EmptyStepExecutionClassGenerator -import tools.vitruv.dsls.reactions.codegen.classgenerators.routine.StepExecutionClassGenerator +import tools.vitruv.dsls.reactions.codegen.classgenerators.steps.EmptyStepExecutionClassGenerator +import tools.vitruv.dsls.reactions.codegen.classgenerators.steps.StepExecutionClassGenerator +import tools.vitruv.dsls.reactions.runtime.routines.AbstractRoutine class RoutineClassGenerator extends ClassGenerator { static val EXECUTION_STATE_VARIABLE = "getExecutionState()" @@ -50,7 +50,7 @@ class RoutineClassGenerator extends ClassGenerator { } this.routine = routine this.routineClassNameGenerator = routine.routineClassNameGenerator - this.inputElements = routine.getInputElements(routine.input.modelInputElements, routine.input.javaInputElements) + this.inputElements = getInputElements(routine.input.modelInputElements, routine.input.javaInputElements) this.inputValuesClass = if (hasInputValues) { generateElementsContainerClass(INPUT_VALUES_SIMPLE_CLASS_NAME, inputElements) } @@ -94,7 +94,7 @@ class RoutineClassGenerator extends ClassGenerator { val executeMethod = generateMethodExecuteRoutine() generatedClass => [ documentation = getCommentWithoutMarkers(routine.documentation) - superTypes += typeRef(AbstractRepairRoutineRealization) + superTypes += typeRef(AbstractRoutine) if(hasInputValues) members += routine.toField(INPUT_VALUES_FIELD_NAME, typeRef(inputValuesClass)) members += if (!matchBlockClassGenerator.empty) routine.toField(RETRIEVED_VALUES_FIELD_NAME, @@ -120,8 +120,8 @@ class RoutineClassGenerator extends ClassGenerator { visibility = JvmVisibility.PUBLIC val routinesFacadeParameter = generateRoutinesFacadeParameter(routine.reactionsSegment) val executionStateParameter = generateReactionExecutionStateParameter() - val calledByParameter = generateParameter("calledBy", typeRef(CallHierarchyHaving)) - val inputParameters = routine.generateMethodInputParameters(inputElements) + val calledByParameter = generateParameter(new AccessibleElement("calledBy", CallHierarchyHaving)) + val inputParameters = routine.generateParameters(inputElements) parameters += routinesFacadeParameter parameters += executionStateParameter parameters += calledByParameter diff --git a/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/RoutineFacadeClassGenerator.xtend b/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/RoutineFacadeClassGenerator.xtend index bf56c60a2..74c33e7ad 100644 --- a/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/RoutineFacadeClassGenerator.xtend +++ b/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/RoutineFacadeClassGenerator.xtend @@ -6,8 +6,7 @@ import org.eclipse.xtext.common.types.JvmConstructor import org.eclipse.xtext.common.types.JvmOperation import org.eclipse.xtext.common.types.JvmVisibility import tools.vitruv.dsls.reactions.language.toplevelelements.Routine -import tools.vitruv.dsls.reactions.runtime.AbstractRepairRoutinesFacade -import tools.vitruv.dsls.reactions.runtime.RoutinesFacadesProvider +import tools.vitruv.dsls.reactions.runtime.routines.RoutinesFacadesProvider import tools.vitruv.dsls.reactions.runtime.structure.ReactionsImportPath import tools.vitruv.dsls.reactions.language.toplevelelements.ReactionsSegment import static extension tools.vitruv.dsls.reactions.codegen.helper.ClassNamesGenerators.* @@ -15,17 +14,22 @@ import static extension tools.vitruv.dsls.reactions.codegen.helper.ReactionsImpo import tools.vitruv.dsls.reactions.codegen.typesbuilder.TypesBuilderExtensionProvider import org.eclipse.xtext.common.types.JvmGenericType import tools.vitruv.dsls.common.ClassNameGenerator -import tools.vitruv.dsls.reactions.runtime.ReactionExecutionState +import tools.vitruv.dsls.reactions.runtime.state.ReactionExecutionState import tools.vitruv.dsls.reactions.runtime.structure.CallHierarchyHaving -import tools.vitruv.dsls.reactions.runtime.RoutinesFacadeExecutionState import static extension tools.vitruv.dsls.reactions.codegen.helper.ReactionsElementsCompletionChecker.isReferenceable +import tools.vitruv.dsls.reactions.runtime.routines.AbstractRoutinesFacade +import org.eclipse.xtext.common.types.JvmFormalParameter +import tools.vitruv.dsls.reactions.codegen.helper.AccessibleElement class RoutineFacadeClassGenerator extends ClassGenerator { + protected static val EXECUTION_STATE_ACCESS_CODE = "_getExecutionState()" + val ReactionsSegment reactionsSegment - val ClassNameGenerator routinesFacadeNameGenerator; - var Map includedRoutinesFacades; + val ClassNameGenerator routinesFacadeNameGenerator + + var Map includedRoutinesFacades var JvmGenericType generatedClass - + new(ReactionsSegment reactionsSegment, TypesBuilderExtensionProvider typesBuilderExtensionProvider) { super(typesBuilderExtensionProvider); if (!reactionsSegment.isReferenceable) { @@ -44,7 +48,7 @@ class RoutineFacadeClassGenerator extends ClassGenerator { override generateBody() { this.includedRoutinesFacades = reactionsSegment.includedRoutinesFacades; generatedClass => [ - superTypes += typeRef(AbstractRepairRoutinesFacade); + superTypes += typeRef(AbstractRoutinesFacade); members += generateConstructor(); // fields for all routines facades of reactions segments imported with qualified names, @@ -78,15 +82,12 @@ class RoutineFacadeClassGenerator extends ClassGenerator { protected def JvmConstructor generateConstructor() { return reactionsSegment.toConstructor() [ - val routinesFacadesProviderParameter = generateParameter("routinesFacadesProvider", - typeRef(RoutinesFacadesProvider)); - val reactionsImportPathParameter = generateParameter("reactionsImportPath", typeRef(ReactionsImportPath)); - val executionState = generateParameter("executionState", typeRef(RoutinesFacadeExecutionState)); + val routinesFacadesProviderParameter = generateParameter(new AccessibleElement("routinesFacadesProvider", RoutinesFacadesProvider)); + val reactionsImportPathParameter = generateParameter(new AccessibleElement("reactionsImportPath", ReactionsImportPath)); parameters += routinesFacadesProviderParameter; parameters += reactionsImportPathParameter; - parameters += executionState; body = ''' - super(«routinesFacadesProviderParameter.name», «reactionsImportPathParameter.name», «executionState.name»); + super(«routinesFacadesProviderParameter.name», «reactionsImportPathParameter.name»); «this.getExtendedConstructorBody()»''' ] } @@ -104,15 +105,14 @@ class RoutineFacadeClassGenerator extends ClassGenerator { val routineNameGenerator = routine.routineClassNameGenerator; routine.associatePrimary(routine.toMethod(routine.name, typeRef(Boolean.TYPE)) [ visibility = JvmVisibility.PUBLIC; - parameters += - generateMethodInputParameters(routine.input.modelInputElements, routine.input.javaInputElements); + parameters += routine.inputElementsParameter body = ''' «typeRef(routinesFacadeNameGenerator.qualifiedName)» _routinesFacade = «generateGetOwnRoutinesFacade()»; - «ReactionExecutionState» _reactionExecutionState = this._getExecutionState().getReactionExecutionState(); - «CallHierarchyHaving» _caller = this._getExecutionState().getCaller(); - «typeRef(routineNameGenerator.qualifiedName)» routine = new «typeRef(routineNameGenerator.qualifiedName)»(_routinesFacade, _reactionExecutionState, _caller« + «ReactionExecutionState» _executionState = «EXECUTION_STATE_ACCESS_CODE»; + «CallHierarchyHaving» _caller = this._getCurrentCaller(); + «typeRef(routineNameGenerator.qualifiedName)» routine = new «typeRef(routineNameGenerator.qualifiedName)»(_routinesFacade, _executionState, _caller« »«FOR parameter : parameters BEFORE ', ' SEPARATOR ', '»«parameter.name»«ENDFOR»); - return routine.applyRoutine(); + return routine.execute(); ''' ]) } @@ -123,14 +123,17 @@ class RoutineFacadeClassGenerator extends ClassGenerator { val routinesFacadeNameGenerator = routine.reactionsSegment.routinesFacadeClassNameGenerator; routine.associatePrimary(routine.toMethod(routine.name, typeRef(Boolean.TYPE)) [ visibility = JvmVisibility.PUBLIC; - parameters += - generateMethodInputParameters(routine.input.modelInputElements, routine.input.javaInputElements); + parameters += routine.inputElementsParameter body = ''' «routinesFacadeNameGenerator.qualifiedName» _routinesFacade = «relativeImportPath.generateGetRoutinesFacadeCall»; return _routinesFacade.«routine.name»(«FOR parameter : parameters SEPARATOR ', '»«parameter.name»«ENDFOR»); ''' ]) } + + private def Iterable getInputElementsParameter(Routine routine) { + routine.generateParameters(getInputElements(routine.input.modelInputElements, routine.input.javaInputElements)) + } protected def StringConcatenationClient generateGetOwnRoutinesFacade() ''' this''' diff --git a/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/RoutinesFacadesProviderClassGenerator.xtend b/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/RoutinesFacadesProviderClassGenerator.xtend index a90249af0..3e0a189e0 100644 --- a/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/RoutinesFacadesProviderClassGenerator.xtend +++ b/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/RoutinesFacadesProviderClassGenerator.xtend @@ -7,14 +7,15 @@ import org.eclipse.xtext.common.types.JvmVisibility import tools.vitruv.dsls.common.ClassNameGenerator import tools.vitruv.dsls.reactions.codegen.typesbuilder.TypesBuilderExtensionProvider import tools.vitruv.dsls.reactions.language.toplevelelements.ReactionsSegment -import tools.vitruv.dsls.reactions.runtime.AbstractRepairRoutinesFacade -import tools.vitruv.dsls.reactions.runtime.AbstractRoutinesFacadesProvider -import tools.vitruv.dsls.reactions.runtime.RoutinesFacadeExecutionState +import tools.vitruv.dsls.reactions.runtime.routines.AbstractRoutinesFacadesProvider import tools.vitruv.dsls.reactions.runtime.structure.ReactionsImportPath import static extension tools.vitruv.dsls.reactions.codegen.helper.ClassNamesGenerators.* import static extension tools.vitruv.dsls.reactions.codegen.helper.ReactionsImportsHelper.* import static extension tools.vitruv.dsls.reactions.codegen.helper.ReactionsElementsCompletionChecker.isReferenceable +import tools.vitruv.dsls.reactions.runtime.routines.AbstractRoutinesFacade +import tools.vitruv.dsls.reactions.codegen.helper.AccessibleElement +import tools.vitruv.dsls.reactions.runtime.state.ReactionExecutionState class RoutinesFacadesProviderClassGenerator extends ClassGenerator { @@ -39,28 +40,28 @@ class RoutinesFacadesProviderClassGenerator extends ClassGenerator { override generateBody() { generatedClass => [ superTypes += typeRef(AbstractRoutinesFacadesProvider); - members += reactionsSegment.toConstructor()[]; + members += reactionsSegment.toConstructor()[ + val executionStateParameter = generateParameter(new AccessibleElement("executionState", ReactionExecutionState)) + parameters += executionStateParameter + body = '''super(«executionStateParameter.name»);''' + ]; // create routines facades for the whole reactions import hierarchy: - members += reactionsSegment.toMethod("createRoutinesFacade", typeRef(AbstractRepairRoutinesFacade)) [ + members += reactionsSegment.toMethod("createRoutinesFacade", typeRef(AbstractRoutinesFacade)) [ visibility = JvmVisibility.PUBLIC; - val reactionsImportPathParameter = generateParameter("reactionsImportPath", - typeRef(ReactionsImportPath)); - val sharedExecutionStateParameter = generateParameter("sharedExecutionState", - typeRef(RoutinesFacadeExecutionState)); + val reactionsImportPathParameter = generateParameter(new AccessibleElement("reactionsImportPath", ReactionsImportPath)); parameters += reactionsImportPathParameter; - parameters += sharedExecutionStateParameter; body = ''' switch(«reactionsImportPathParameter.name».getPathString()) { «FOR importHierarchyEntry : reactionsSegment.importHierarchyRoutinesFacades.entrySet» «val importPath = importHierarchyEntry.key» «val routinesFacadeClassNameGenerator = importHierarchyEntry.value» case "«importPath.pathString»": { - return new «routinesFacadeClassNameGenerator.qualifiedName»(this, «reactionsImportPathParameter.name», «sharedExecutionStateParameter.name»); + return new «routinesFacadeClassNameGenerator.qualifiedName»(this, «reactionsImportPathParameter.name»); } «ENDFOR» default: { - throw new IllegalArgumentException("Unexpected import path: " + «reactionsImportPathParameter.name».getPathString()); + throw new IllegalArgumentException("Unexpected import path: " + «reactionsImportPathParameter.name».getPathString()); } } ''' diff --git a/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/routine/CreateBlockClassGenerator.xtend b/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/steps/CreateBlockClassGenerator.xtend similarity index 90% rename from bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/routine/CreateBlockClassGenerator.xtend rename to bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/steps/CreateBlockClassGenerator.xtend index 06859f72c..1bee558a2 100644 --- a/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/routine/CreateBlockClassGenerator.xtend +++ b/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/steps/CreateBlockClassGenerator.xtend @@ -1,4 +1,4 @@ -package tools.vitruv.dsls.reactions.codegen.classgenerators.routine +package tools.vitruv.dsls.reactions.codegen.classgenerators.steps import tools.vitruv.dsls.reactions.codegen.typesbuilder.TypesBuilderExtensionProvider import tools.vitruv.dsls.reactions.codegen.helper.AccessibleElement @@ -12,14 +12,16 @@ import static extension tools.vitruv.dsls.reactions.codegen.helper.ReactionsLang import static extension tools.vitruv.dsls.reactions.codegen.helper.ReactionsLanguageHelper.getJavaClassName import static extension edu.kit.ipd.sdq.commons.util.java.lang.IterableUtil.mapFixed import tools.vitruv.dsls.reactions.language.toplevelelements.CreateBlock -import tools.vitruv.dsls.reactions.runtime.AbstractRepairRoutineRealization import tools.vitruv.dsls.common.elements.NamedMetaclassReference +import tools.vitruv.dsls.reactions.runtime.routines.AbstractRoutine /** * Generates for a {@link CreateBlock} of a routine a class providing a creation method (with the name defined in {@link #CREATE_ELEMENTS_METHOD_NAME}) * that returns the created elements. */ class CreateBlockClassGenerator extends StepExecutionClassGenerator { + static val PREDEFINED_CREATE_OBJECT_METHOD_NAME = "createObject" + static val MISSING_NAME = "/* Name missing */" static val MISSING_TYPE = "/* Type missing */" static val CREATED_ELEMENTS_SIMPLE_CLASS_NAME = "CreatedValues" @@ -73,7 +75,7 @@ class CreateBlockClassGenerator extends StepExecutionClassGenerator { override generateBody() { generatedClass => [ - superTypes += typeRef(AbstractRepairRoutineRealization.Create) + superTypes += typeRef(AbstractRoutine.Create) members += createdElementsClass members += generateConstructor() members += generateMethodCreate() @@ -104,9 +106,10 @@ class CreateBlockClassGenerator extends StepExecutionClassGenerator { val affectedElementClass = elementCreate.metaclass val createdClassFactory = affectedElementClass?.EPackage?.EFactoryInstance?.runtimeClassName return ''' - «affectedElementClass.javaClassName» «elementCreate.name ?: MISSING_NAME» = «createdClassFactory?: - MISSING_TYPE».eINSTANCE.create«affectedElementClass?.name?: MISSING_TYPE»(); - notifyObjectCreated(«elementCreate.name ?: MISSING_NAME»);''' + «affectedElementClass.javaClassName» «elementCreate.name ?: MISSING_NAME» = «PREDEFINED_CREATE_OBJECT_METHOD_NAME»(() -> { + return «createdClassFactory?: MISSING_TYPE».eINSTANCE.create«affectedElementClass?.name?: MISSING_TYPE»(); + }); + ''' } override generateStepExecutionCode( diff --git a/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/routine/EmptyStepExecutionClassGenerator.xtend b/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/steps/EmptyStepExecutionClassGenerator.xtend similarity index 93% rename from bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/routine/EmptyStepExecutionClassGenerator.xtend rename to bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/steps/EmptyStepExecutionClassGenerator.xtend index 0b0f3aa16..979f93f85 100644 --- a/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/routine/EmptyStepExecutionClassGenerator.xtend +++ b/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/steps/EmptyStepExecutionClassGenerator.xtend @@ -1,4 +1,4 @@ -package tools.vitruv.dsls.reactions.codegen.classgenerators.routine +package tools.vitruv.dsls.reactions.codegen.classgenerators.steps import tools.vitruv.dsls.reactions.codegen.typesbuilder.TypesBuilderExtensionProvider import org.eclipse.xtend2.lib.StringConcatenationClient diff --git a/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/routine/MatchBlockClassGenerator.xtend b/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/steps/MatchBlockClassGenerator.xtend similarity index 83% rename from bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/routine/MatchBlockClassGenerator.xtend rename to bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/steps/MatchBlockClassGenerator.xtend index 48cb7c9a9..720c501a4 100644 --- a/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/routine/MatchBlockClassGenerator.xtend +++ b/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/steps/MatchBlockClassGenerator.xtend @@ -1,4 +1,4 @@ -package tools.vitruv.dsls.reactions.codegen.classgenerators.routine +package tools.vitruv.dsls.reactions.codegen.classgenerators.steps import org.eclipse.emf.ecore.EObject import tools.vitruv.dsls.reactions.codegen.typesbuilder.TypesBuilderExtensionProvider @@ -20,11 +20,13 @@ import static extension edu.kit.ipd.sdq.commons.util.java.lang.IterableUtil.mapF import java.io.IOException import org.eclipse.xtext.common.types.JvmFormalParameter import static extension tools.vitruv.dsls.reactions.codegen.helper.ReactionsLanguageHelper.* -import tools.vitruv.dsls.reactions.runtime.AbstractRepairRoutineRealization import static com.google.common.base.Preconditions.checkNotNull import static com.google.common.base.Preconditions.checkArgument import tools.vitruv.dsls.reactions.language.toplevelelements.MatchBlock import tools.vitruv.dsls.reactions.language.MatchCheckStatement +import org.eclipse.xtext.common.types.JvmTypeReference +import org.eclipse.xtext.xbase.lib.Procedures.Procedure1 +import tools.vitruv.dsls.reactions.runtime.routines.AbstractRoutine /** * Generates for a {@link Matcher} block of a routine a class providing a method (with the name defined in @@ -32,6 +34,10 @@ import tools.vitruv.dsls.reactions.language.MatchCheckStatement * defined match statements. */ class MatchBlockClassGenerator extends StepExecutionClassGenerator { + static val PREDEFINED_HAS_CORRESPONDING_ELEMENTS_METHOD_NAME = "hasCorrespondingElements" + static val PREDEFINED_GET_CORRESPONDING_ELEMENT_METHOD_NAME = "getCorrespondingElement" + static val PREDEFINED_GET_CORRESPONDING_ELEMENTS_METHOD_NAME = "getCorrespondingElements" + static val MATCH_METHOD_NAME = "match" static val MISSING_TYPE = "/* Type missing */" static val RETRIEVED_ELEMENTS_SIMPLE_CLASS_NAME = "RetrievedValues" @@ -80,11 +86,10 @@ class MatchBlockClassGenerator extends StepExecutionClassGenerator { override generateBody() { generatedClass => [ - superTypes += typeRef(AbstractRepairRoutineRealization.Match) + superTypes += typeRef(AbstractRoutine.Match) members += retrievedElementsClass members += generateConstructor() members += generateMatchMethod() - members += generatedMethods ] } @@ -120,9 +125,9 @@ class MatchBlockClassGenerator extends StepExecutionClassGenerator { val retrieveStatementArguments = getGeneralGetCorrespondingElementStatementArguments(elementAbscence, null, currentlyAccessibleElements) val StringConcatenationClient statements = ''' - if (!getCorrespondingElements( + if («PREDEFINED_HAS_CORRESPONDING_ELEMENTS_METHOD_NAME»( «retrieveStatementArguments» - ).isEmpty()) { + )) { return null; } ''' @@ -143,7 +148,7 @@ class MatchBlockClassGenerator extends StepExecutionClassGenerator { private def dispatch StringConcatenationClient createStatements(RetrieveManyModelElements retrieveElement, String name, String typeName, StringConcatenationClient generalArguments) { val StringConcatenationClient statement = ''' - «IF !name.nullOrEmpty»«List»<«typeName»> «name» = «ENDIF»getCorrespondingElements( + «IF !name.nullOrEmpty»«Iterable»<«typeName»> «name» = «ENDIF»«PREDEFINED_GET_CORRESPONDING_ELEMENTS_METHOD_NAME»( «generalArguments» ); ''' @@ -153,10 +158,10 @@ class MatchBlockClassGenerator extends StepExecutionClassGenerator { private def dispatch StringConcatenationClient createStatements(RetrieveOneModelElement retrieveElement, String name, String typeName, StringConcatenationClient generalArguments) { val retrieveStatement = ''' - getCorrespondingElement( - «generalArguments», - «retrieveElement.asserted» // asserted - )'''; + «PREDEFINED_GET_CORRESPONDING_ELEMENT_METHOD_NAME»( + «generalArguments», + «retrieveElement.asserted» // asserted + )''' if (name.nullOrEmpty) { if (!retrieveElement.optional) { return '''if («retrieveStatement» == null) { @@ -184,13 +189,13 @@ class MatchBlockClassGenerator extends StepExecutionClassGenerator { val checkMethod = generateMethodMatcherPrecondition(checkStatement, currentlyAccessibleElements) val checkMethodCall = checkMethod?.userExecutionMethodCallString return ''' - if (!«checkMethodCall») { - «IF checkStatement.asserted» - throw new «IllegalStateException»(); - «ELSE» - return null; - «ENDIF» - }'''; + if (!«checkMethodCall») { + «IF checkStatement.asserted» + throw new «IllegalStateException»(); + «ELSE» + return null; + «ENDIF» + }''' } private def StringConcatenationClient getTagString(RetrieveOrRequireAbscenceOfModelElement retrieveElement, @@ -208,14 +213,14 @@ class MatchBlockClassGenerator extends StepExecutionClassGenerator { Iterable currentlyAccessibleElements) { val affectedElementClass = retrieveElement.elementType?.javaClassName if (retrieveElement.precondition === null) { - return '''(«affectedElementClass» _element) -> true''' + return '''null''' } val preconditionMethod = generateMethodCorrespondencePrecondition(retrieveElement, name, currentlyAccessibleElements) return '''(«affectedElementClass» _element) -> «preconditionMethod.simpleName»(« // - preconditionMethod.generateMethodParameterCallList.toString.replace(name?: - RETRIEVAL_PRECONDITION_METHOD_TARGET, "_element" - )»)''' + preconditionMethod.generateMethodParameterCallList.toString.replace(name?: + RETRIEVAL_PRECONDITION_METHOD_TARGET, "_element" + )»)''' } private def StringConcatenationClient getGeneralGetCorrespondingElementStatementArguments( @@ -229,17 +234,17 @@ class MatchBlockClassGenerator extends StepExecutionClassGenerator { val correspondenceSourceMethodCall = correspondenceSourceMethod?.userExecutionMethodCallString val tagString = getTagString(retrieveElement, currentlyAccessibleElements) return ''' - «correspondenceSourceMethodCall», // correspondence source supplier - «affectedElementClass ?: MISSING_TYPE».class, - «correspondingElementPreconditionChecker», // correspondence precondition checker - «tagString»''' + «correspondenceSourceMethodCall», // correspondence source supplier + «affectedElementClass ?: MISSING_TYPE».class, + «correspondingElementPreconditionChecker», // correspondence precondition checker + «tagString»''' } private def JvmOperation generateMethodGetRetrieveTag(Taggable taggable, Iterable currentlyAccessibleElements) { val methodName = "getRetrieveTag" + counterGetRetrieveTagMethods++; - return taggable.tag?.getOrGenerateMethod(methodName, typeRef(String)) [ + return taggable.tag?.generateAndAddMethod(methodName, typeRef(String)) [ parameters += generateAccessibleElementsParameters(currentlyAccessibleElements) body = taggable.tag.code; ]; @@ -249,11 +254,10 @@ class MatchBlockClassGenerator extends StepExecutionClassGenerator { String name, Iterable currentlyAccessibleElements) { val methodName = "getCorrespondingModelElementsPrecondition" + (elementRetrieve.retrieveOrRequireAbscenceMethodSuffix ?: counterGetCorrespondenceSource++) - return elementRetrieve.precondition?.getOrGenerateMethod(methodName, typeRef(Boolean.TYPE)) [ - val elementParameter = generateModelElementParameter(elementRetrieve.elementType, - name ?: RETRIEVAL_PRECONDITION_METHOD_TARGET) - parameters += generateAccessibleElementsParameters(currentlyAccessibleElements) - parameters += elementParameter + return elementRetrieve.precondition?.generateAndAddMethod(methodName, typeRef(Boolean.TYPE)) [ + val element = new AccessibleElement(name ?: RETRIEVAL_PRECONDITION_METHOD_TARGET, elementRetrieve.elementType.javaClassName) + parameters += generateParameters(currentlyAccessibleElements) + parameters += generateParameter(element) body = elementRetrieve.precondition.code ]; } @@ -263,8 +267,8 @@ class MatchBlockClassGenerator extends StepExecutionClassGenerator { val methodName = "getCorrepondenceSource" + (elementRetrieve.retrieveOrRequireAbscenceMethodSuffix ?: counterGetCorrespondenceSource++); - val correspondenceSourceBlock = elementRetrieve.correspondenceSource; - return correspondenceSourceBlock?.getOrGenerateMethod(methodName, typeRef(EObject)) [ + val correspondenceSourceBlock = elementRetrieve.correspondenceSource + return correspondenceSourceBlock?.generateAndAddMethod(methodName, typeRef(EObject)) [ parameters += generateAccessibleElementsParameters(currentlyAccessibleElements) body = correspondenceSourceBlock.code; ]; @@ -276,7 +280,7 @@ class MatchBlockClassGenerator extends StepExecutionClassGenerator { private def JvmOperation generateMethodMatcherPrecondition(MatchCheckStatement checkStatement, Iterable currentlyAccessibleElements) { val methodName = "checkMatcherPrecondition" + counterCheckMatcherPreconditionMethods++; - return checkStatement.getOrGenerateMethod(methodName, typeRef(Boolean.TYPE)) [ + return checkStatement.generateAndAddMethod(methodName, typeRef(Boolean.TYPE)) [ parameters += generateAccessibleElementsParameters(currentlyAccessibleElements) body = checkStatement.code; ]; @@ -328,7 +332,7 @@ class MatchBlockClassGenerator extends StepExecutionClassGenerator { return new AccessibleElement(retrieveElement.name, retrieveElementType) } RetrieveManyModelElements: - return new AccessibleElement(retrieveElement.name, List.name, retrieveElementType) + return new AccessibleElement(retrieveElement.name, Iterable.name, retrieveElementType) } } @@ -336,5 +340,12 @@ class MatchBlockClassGenerator extends StepExecutionClassGenerator { override getNewlyAccessibleElementsContainerType() { return retrievedElementsClass } + + def JvmOperation generateAndAddMethod(EObject contextObject, String methodName, JvmTypeReference returnType, + Procedure1 initializer) { + val generatedMethod = contextObject.toMethod(methodName, returnType, initializer) + generatedClass.members += generatedMethod + return generatedMethod + } } diff --git a/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/routine/StepExecutionClassGenerator.xtend b/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/steps/StepExecutionClassGenerator.xtend similarity index 97% rename from bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/routine/StepExecutionClassGenerator.xtend rename to bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/steps/StepExecutionClassGenerator.xtend index a0071e56b..600747560 100644 --- a/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/routine/StepExecutionClassGenerator.xtend +++ b/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/steps/StepExecutionClassGenerator.xtend @@ -1,4 +1,4 @@ -package tools.vitruv.dsls.reactions.codegen.classgenerators.routine +package tools.vitruv.dsls.reactions.codegen.classgenerators.steps import tools.vitruv.dsls.reactions.codegen.classgenerators.ClassGenerator import tools.vitruv.dsls.reactions.codegen.typesbuilder.TypesBuilderExtensionProvider diff --git a/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/routine/UpdateBlockClassGenerator.xtend b/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/steps/UpdateBlockClassGenerator.xtend similarity index 95% rename from bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/routine/UpdateBlockClassGenerator.xtend rename to bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/steps/UpdateBlockClassGenerator.xtend index 92354b506..782405334 100644 --- a/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/routine/UpdateBlockClassGenerator.xtend +++ b/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/classgenerators/steps/UpdateBlockClassGenerator.xtend @@ -1,9 +1,8 @@ -package tools.vitruv.dsls.reactions.codegen.classgenerators.routine +package tools.vitruv.dsls.reactions.codegen.classgenerators.steps import org.eclipse.xtext.common.types.JvmVisibility import org.eclipse.xtext.common.types.JvmOperation import org.eclipse.xtext.common.types.JvmTypeReference -import tools.vitruv.dsls.reactions.runtime.AbstractRepairRoutineRealization import tools.vitruv.dsls.reactions.codegen.helper.AccessibleElement import tools.vitruv.dsls.reactions.codegen.typesbuilder.TypesBuilderExtensionProvider import org.eclipse.xtext.common.types.JvmGenericType @@ -11,6 +10,7 @@ import static com.google.common.base.Preconditions.checkArgument import static com.google.common.base.Preconditions.checkNotNull import org.eclipse.xtend2.lib.StringConcatenationClient import tools.vitruv.dsls.reactions.language.toplevelelements.CodeBlock +import tools.vitruv.dsls.reactions.runtime.routines.AbstractRoutine /** * Generates for an {@link UpdateBlock} of a routine a class with a method (with the name defined in @@ -60,7 +60,7 @@ class UpdateBlockClassGenerator extends StepExecutionClassGenerator { override generateBody() { generatedClass => [ - superTypes += typeRef(AbstractRepairRoutineRealization.Update) + superTypes += typeRef(AbstractRoutine.Update) members += generateConstructor() members += generateUpdateMethod() ] diff --git a/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/helper/ClassNamesGenerators.xtend b/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/helper/ClassNamesGenerators.xtend index 615db94f8..510d8d546 100644 --- a/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/helper/ClassNamesGenerators.xtend +++ b/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/helper/ClassNamesGenerators.xtend @@ -97,17 +97,17 @@ class ClassNamesGenerators { } private static class RoutinesFacadesProviderClassNameGenerator implements ClassNameGenerator { - val ReactionsSegment reactionSegment; + val ReactionsSegment reactionsSegment; - new(ReactionsSegment reactionSegment) { - this.reactionSegment = reactionSegment; + new(ReactionsSegment reactionsSegment) { + this.reactionsSegment = reactionsSegment; } override String getSimpleName() ''' - «ROUTINES_FACADES_PROVIDER_CLASS_NAME»''' + «reactionsSegment.name.toFirstUpper»«ROUTINES_FACADES_PROVIDER_CLASS_NAME»''' override String getPackageName() ''' - «basicRoutinesPackageQualifiedName».«reactionSegment.packageName»''' + «basicRoutinesPackageQualifiedName».«reactionsSegment.packageName»''' } private static class ReactionClassNameGenerator implements ClassNameGenerator { @@ -157,7 +157,7 @@ class ClassNamesGenerators { } override String getSimpleName() ''' - «ROUTINES_FACADE_CLASS_NAME»''' + «reactionsSegment.name.toFirstUpper»«ROUTINES_FACADE_CLASS_NAME»''' override String getPackageName() ''' «reactionsSegment.routinesPackageQualifiedName»''' @@ -173,7 +173,7 @@ class ClassNamesGenerators { } override String getSimpleName() ''' - «ROUTINES_FACADE_CLASS_NAME»''' + «reactionsSegment.name.toFirstUpper»«ROUTINES_FACADE_CLASS_NAME»''' override String getPackageName() ''' «reactionsSegment.routinesPackageQualifiedName».«relativeImportPath.segments.join(".", [it.reactionsSegmentPackageName])»''' diff --git a/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/typesbuilder/ParameterGenerator.xtend b/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/typesbuilder/ParameterGenerator.xtend index 76eb09987..e7b576254 100644 --- a/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/typesbuilder/ParameterGenerator.xtend +++ b/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/codegen/typesbuilder/ParameterGenerator.xtend @@ -3,15 +3,11 @@ package tools.vitruv.dsls.reactions.codegen.typesbuilder import org.eclipse.xtext.xbase.jvmmodel.JvmTypeReferenceBuilder import org.eclipse.xtext.common.types.JvmFormalParameter import org.eclipse.emf.ecore.EObject -import java.util.ArrayList -import org.eclipse.xtext.common.types.JvmTypeReference -import tools.vitruv.change.interaction.UserInteractor -import tools.vitruv.dsls.reactions.runtime.ReactionExecutionState +import tools.vitruv.dsls.reactions.runtime.state.ReactionExecutionState import org.eclipse.emf.ecore.EClass import tools.vitruv.dsls.reactions.language.toplevelelements.ReactionsSegment import tools.vitruv.dsls.reactions.language.inputTypes.InputTypesPackage import tools.vitruv.change.atomic.EChange -import tools.vitruv.dsls.common.elements.MetaclassReference import static extension tools.vitruv.dsls.reactions.codegen.helper.ReactionsLanguageHelper.*; import static extension tools.vitruv.dsls.reactions.codegen.helper.ClassNamesGenerators.*; import tools.vitruv.dsls.reactions.codegen.helper.AccessibleElement @@ -22,70 +18,39 @@ import tools.vitruv.dsls.common.elements.NamedMetaclassReference class ParameterGenerator { static val MISSING_PARAMETER_NAME = "/* Name missing */" - protected final extension JvmTypeReferenceBuilder _typeReferenceBuilder; - protected final extension JvmTypesBuilderWithoutAssociations _typesBuilder; + protected final extension JvmTypeReferenceBuilder _typeReferenceBuilder + protected final extension JvmTypesBuilderWithoutAssociations _typesBuilder new (JvmTypeReferenceBuilder typeReferenceBuilder, JvmTypesBuilderWithoutAssociations typesBuilder) { - _typeReferenceBuilder = typeReferenceBuilder; - _typesBuilder = typesBuilder; + _typeReferenceBuilder = typeReferenceBuilder + _typesBuilder = typesBuilder } - def JvmFormalParameter generateModelElementParameter(EObject parameterContext, MetaclassReference metaclassReference, String elementName) { - if (metaclassReference?.metaclass !== null) { - return parameterContext.generateParameter(elementName, typeRef(metaclassReference.javaClassName)) - } - return null; + def JvmFormalParameter generateUntypedChangeParameter(EObject parameterContext) { + return parameterContext.generateParameter(new AccessibleElement(CHANGE_PARAMETER_NAME, EChange)) } def JvmFormalParameter generateRoutinesFacadeParameter(EObject parameterContext, ReactionsSegment reactionsSegment) { - return generateParameter(parameterContext, ROUTINES_FACADE_PARAMETER_NAME, typeRef(reactionsSegment.routinesFacadeClassNameGenerator.qualifiedName)); + return generateParameter(parameterContext, new AccessibleElement(ROUTINES_FACADE_PARAMETER_NAME, reactionsSegment.routinesFacadeClassNameGenerator.qualifiedName)) } def JvmFormalParameter generateReactionExecutionStateParameter(EObject parameterContext) { - return generateParameter(parameterContext, REACTION_EXECUTION_STATE_PARAMETER_NAME, ReactionExecutionState); - } - - def JvmFormalParameter generateUserInteractorParameter(EObject parameterContext) { - return generateParameter(parameterContext, USER_INTERACTING_PARAMETER_NAME, UserInteractor); + return generateParameter(parameterContext, new AccessibleElement(REACTION_EXECUTION_STATE_PARAMETER_NAME, ReactionExecutionState)) } - def generateParameter(EObject context, String parameterName, JvmTypeReference parameterType) { - if (parameterType === null) { - return null; - } - return context.toParameter(parameterName, parameterType); - } - - - def generateParameterFromClasses(EObject context, String parameterName, Class parameterClass, Iterable typeParameterClasses) { - return generateParameter(context, parameterName, parameterClass, typeParameterClasses); + def generateParameter(EObject contextObject, AccessibleElement element) { + toParameter(contextObject, element.name, element.generateTypeRef(_typeReferenceBuilder)) } - def generateParameter(EObject context, String parameterName, Class parameterClass, String... typeParameterClassNames) { - if (parameterClass === null) { - return null; - } - val typeParameters = new ArrayList(typeParameterClassNames.size); - for (typeParameterClassName : typeParameterClassNames.filter[!nullOrEmpty]) { - typeParameters.add(typeRef(typeParameterClassName)); - } - val changeType = typeRef(parameterClass, typeParameters); - return context.toParameter(parameterName, changeType); + def Iterable generateParameters(EObject contextObject, Iterable elements) { + elements.map[toParameter(contextObject, it.name, it.generateTypeRef(_typeReferenceBuilder))] } - def Iterable getInputElements(EObject contextObject, Iterable metaclassReferences, Iterable javaElements) { + def Iterable getInputElements(Iterable metaclassReferences, Iterable 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)]; } - def Iterable generateMethodInputParameters(EObject contextObject, Iterable metaclassReferences, Iterable javaElements) { - return contextObject.generateMethodInputParameters(contextObject.getInputElements(metaclassReferences, javaElements)); - } - - def Iterable generateMethodInputParameters(EObject contextObject, Iterable elements) { - elements.map[toParameter(contextObject, it.name, it.generateTypeRef(_typeReferenceBuilder))] - } - private def getMappedInstanceClassCanonicalName(EClass eClass) { switch eClass { case InputTypesPackage.Literals.STRING: String.name @@ -101,9 +66,5 @@ class ParameterGenerator { } } - def JvmFormalParameter generateUntypedChangeParameter(EObject parameterContext) { - return parameterContext.generateParameter(CHANGE_PARAMETER_NAME, EChange); - } - } \ No newline at end of file diff --git a/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/jvmmodel/ReactionsLanguageJvmModelInferrer.xtend b/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/jvmmodel/ReactionsLanguageJvmModelInferrer.xtend index fb51f9232..716e62648 100644 --- a/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/jvmmodel/ReactionsLanguageJvmModelInferrer.xtend +++ b/bundles/tools.vitruv.dsls.reactions/src/tools/vitruv/dsls/reactions/jvmmodel/ReactionsLanguageJvmModelInferrer.xtend @@ -6,7 +6,6 @@ package tools.vitruv.dsls.reactions.jvmmodel import com.google.inject.Inject import org.eclipse.xtext.xbase.jvmmodel.AbstractModelInferrer import org.eclipse.xtext.xbase.jvmmodel.IJvmDeclaredTypeAcceptor -import tools.vitruv.dsls.reactions.codegen.classgenerators.ExecutorClassGenerator import tools.vitruv.dsls.reactions.codegen.classgenerators.RoutineFacadeClassGenerator import tools.vitruv.dsls.reactions.codegen.classgenerators.RoutineClassGenerator import tools.vitruv.dsls.reactions.language.toplevelelements.Routine @@ -63,7 +62,6 @@ class ReactionsLanguageJvmModelInferrer extends AbstractModelInferrer { for (reaction : reactionsSegment.reactions.filter[it.isReferenceable]) { generate(reaction, acceptor, isPreIndexingPhase); } - acceptor.accept(new ExecutorClassGenerator(reactionsSegment, typesBuilderExtensionProvider), reactionsSegment); acceptor.accept(new ChangePropagationSpecificationClassGenerator(reactionsSegment, typesBuilderExtensionProvider), reactionsSegment); } diff --git a/tests/tools.vitruv.dsls.commonalities.tests/src/tools/vitruv/dsls/commonalities/tests/operators/DigitsAttributeOperator.xtend b/tests/tools.vitruv.dsls.commonalities.tests/src/tools/vitruv/dsls/commonalities/tests/operators/DigitsAttributeOperator.xtend index 58847e620..c3a142e65 100644 --- a/tests/tools.vitruv.dsls.commonalities.tests/src/tools/vitruv/dsls/commonalities/tests/operators/DigitsAttributeOperator.xtend +++ b/tests/tools.vitruv.dsls.commonalities.tests/src/tools/vitruv/dsls/commonalities/tests/operators/DigitsAttributeOperator.xtend @@ -4,7 +4,7 @@ import java.util.List import tools.vitruv.dsls.commonalities.runtime.operators.mapping.attribute.AbstractAttributeMappingOperator import tools.vitruv.dsls.commonalities.runtime.operators.mapping.attribute.AttributeMappingOperator import tools.vitruv.dsls.commonalities.runtime.operators.mapping.attribute.AttributeType -import tools.vitruv.dsls.reactions.runtime.ReactionExecutionState +import tools.vitruv.dsls.reactions.runtime.state.ReactionExecutionState /** * Converts between an integer number on the participation side and a list of diff --git a/tests/tools.vitruv.dsls.commonalities.tests/src/tools/vitruv/dsls/commonalities/tests/operators/MockReferenceMappingOperator.xtend b/tests/tools.vitruv.dsls.commonalities.tests/src/tools/vitruv/dsls/commonalities/tests/operators/MockReferenceMappingOperator.xtend index f055c5d6e..f2bae0463 100644 --- a/tests/tools.vitruv.dsls.commonalities.tests/src/tools/vitruv/dsls/commonalities/tests/operators/MockReferenceMappingOperator.xtend +++ b/tests/tools.vitruv.dsls.commonalities.tests/src/tools/vitruv/dsls/commonalities/tests/operators/MockReferenceMappingOperator.xtend @@ -3,7 +3,7 @@ package tools.vitruv.dsls.commonalities.tests.operators import tools.vitruv.dsls.commonalities.runtime.operators.mapping.reference.IReferenceMappingOperator import org.eclipse.emf.ecore.EObject import tools.vitruv.dsls.commonalities.runtime.operators.mapping.reference.ReferenceMappingOperator -import tools.vitruv.dsls.reactions.runtime.ReactionExecutionState +import tools.vitruv.dsls.reactions.runtime.state.ReactionExecutionState @ReferenceMappingOperator( name = "mock", diff --git a/tests/tools.vitruv.dsls.commonalities.tests/src/tools/vitruv/dsls/commonalities/tests/operators/MultiplyAttributeOperator.xtend b/tests/tools.vitruv.dsls.commonalities.tests/src/tools/vitruv/dsls/commonalities/tests/operators/MultiplyAttributeOperator.xtend index ad8dc3ff8..e31fed000 100644 --- a/tests/tools.vitruv.dsls.commonalities.tests/src/tools/vitruv/dsls/commonalities/tests/operators/MultiplyAttributeOperator.xtend +++ b/tests/tools.vitruv.dsls.commonalities.tests/src/tools/vitruv/dsls/commonalities/tests/operators/MultiplyAttributeOperator.xtend @@ -3,7 +3,7 @@ package tools.vitruv.dsls.commonalities.tests.operators import tools.vitruv.dsls.commonalities.runtime.operators.mapping.attribute.AbstractAttributeMappingOperator import tools.vitruv.dsls.commonalities.runtime.operators.mapping.attribute.AttributeMappingOperator import tools.vitruv.dsls.commonalities.runtime.operators.mapping.attribute.AttributeType -import tools.vitruv.dsls.reactions.runtime.ReactionExecutionState +import tools.vitruv.dsls.reactions.runtime.state.ReactionExecutionState import static tools.vitruv.dsls.commonalities.runtime.helper.XtendAssertHelper.* diff --git a/tests/tools.vitruv.dsls.reactions.tests/src/tools/vitruv/dsls/reactions/builder/FluentReactionsLanguageBuilderTests.xtend b/tests/tools.vitruv.dsls.reactions.tests/src/tools/vitruv/dsls/reactions/builder/FluentReactionsLanguageBuilderTests.xtend index f12159baf..b78a7c1ee 100644 --- a/tests/tools.vitruv.dsls.reactions.tests/src/tools/vitruv/dsls/reactions/builder/FluentReactionsLanguageBuilderTests.xtend +++ b/tests/tools.vitruv.dsls.reactions.tests/src/tools/vitruv/dsls/reactions/builder/FluentReactionsLanguageBuilderTests.xtend @@ -24,7 +24,7 @@ class FluentReactionsLanguageBuilderTests extends FluentReactionsBuilderTest { ] val reactionResult = ''' - import tools.vitruv.dsls.reactions.runtime.AbstractRepairRoutineRealization.Update + import tools.vitruv.dsls.reactions.runtime.^routines.AbstractRoutine.Update import "http://tools.vitruv.testutils.metamodels.allElementTypes" as allElementTypes @@ -63,7 +63,7 @@ class FluentReactionsLanguageBuilderTests extends FluentReactionsBuilderTest { ] val reactionResult = ''' - import tools.vitruv.dsls.reactions.runtime.AbstractRepairRoutineRealization.Update + import tools.vitruv.dsls.reactions.runtime.^routines.AbstractRoutine.Update import "http://tools.vitruv.testutils.metamodels.allElementTypes" as allElementTypes @@ -122,7 +122,7 @@ class FluentReactionsLanguageBuilderTests extends FluentReactionsBuilderTest { builder += extendedSegment val reactionResult = ''' - import tools.vitruv.dsls.reactions.runtime.AbstractRepairRoutineRealization.Update + import tools.vitruv.dsls.reactions.runtime.^routines.AbstractRoutine.Update import "http://tools.vitruv.testutils.metamodels.allElementTypes" as allElementTypes @@ -206,7 +206,7 @@ class FluentReactionsLanguageBuilderTests extends FluentReactionsBuilderTest { builder += extendedSegment val reactionResult = ''' - import tools.vitruv.dsls.reactions.runtime.AbstractRepairRoutineRealization.Update + import tools.vitruv.dsls.reactions.runtime.^routines.AbstractRoutine.Update import "http://tools.vitruv.testutils.metamodels.allElementTypes" as allElementTypes @@ -295,7 +295,7 @@ class FluentReactionsLanguageBuilderTests extends FluentReactionsBuilderTest { builder += extendedSegment2 val reactionResult = ''' - import tools.vitruv.dsls.reactions.runtime.AbstractRepairRoutineRealization.Update + import tools.vitruv.dsls.reactions.runtime.^routines.AbstractRoutine.Update import "http://tools.vitruv.testutils.metamodels.allElementTypes" as allElementTypes @@ -387,7 +387,7 @@ class FluentReactionsLanguageBuilderTests extends FluentReactionsBuilderTest { ] val expectedReaction = ''' - import tools.vitruv.dsls.reactions.runtime.AbstractRepairRoutineRealization.Update + import tools.vitruv.dsls.reactions.runtime.^routines.AbstractRoutine.Update import "http://tools.vitruv.testutils.metamodels.allElementTypes" as allElementTypes @@ -425,7 +425,7 @@ class FluentReactionsLanguageBuilderTests extends FluentReactionsBuilderTest { reactionsFile += reactionsSegment val expectedReaction = ''' - import tools.vitruv.dsls.reactions.runtime.AbstractRepairRoutineRealization.Update + import tools.vitruv.dsls.reactions.runtime.^routines.AbstractRoutine.Update import "http://tools.vitruv.testutils.metamodels.allElementTypes" as allElementTypes import "http://www.eclipse.org/emf/2002/Ecore" as ecore @@ -480,7 +480,7 @@ class FluentReactionsLanguageBuilderTests extends FluentReactionsBuilderTest { reactionsFile += reactionsSegment val expectedReaction = ''' - import tools.vitruv.dsls.reactions.runtime.AbstractRepairRoutineRealization.Update + import tools.vitruv.dsls.reactions.runtime.^routines.AbstractRoutine.Update import "http://www.eclipse.org/emf/2002/Ecore" as ecore import "http://tools.vitruv.testutils.metamodels.allElementTypes" as allElementTypes @@ -585,7 +585,7 @@ class FluentReactionsLanguageBuilderTests extends FluentReactionsBuilderTest { val expectedReaction = ''' import «objectExtensionsFqn» - import tools.vitruv.dsls.reactions.runtime.AbstractRepairRoutineRealization.Update + import tools.vitruv.dsls.reactions.runtime.^routines.AbstractRoutine.Update import "http://tools.vitruv.testutils.metamodels.allElementTypes" as allElementTypes @@ -639,7 +639,7 @@ class FluentReactionsLanguageBuilderTests extends FluentReactionsBuilderTest { create.reaction('CreateRoot2Test').afterElement(Root2).created.call(commonRoutine) val expectedReaction = ''' - import tools.vitruv.dsls.reactions.runtime.AbstractRepairRoutineRealization.Update + import tools.vitruv.dsls.reactions.runtime.^routines.AbstractRoutine.Update import "http://tools.vitruv.testutils.metamodels.allElementTypes" as allElementTypes import "http://www.eclipse.org/emf/2002/Ecore" as ecore @@ -705,7 +705,7 @@ class FluentReactionsLanguageBuilderTests extends FluentReactionsBuilderTest { reactionsFile += secondSegment val expectedReaction = ''' - import tools.vitruv.dsls.reactions.runtime.AbstractRepairRoutineRealization.Update + import tools.vitruv.dsls.reactions.runtime.^routines.AbstractRoutine.Update import "http://tools.vitruv.testutils.metamodels.allElementTypes" as allElementTypes import "http://tools.vitruv.testutils.metamodels.allElementTypes2" as allElementTypes2 diff --git a/tests/tools.vitruv.dsls.reactions.tests/src/tools/vitruv/dsls/reactions/generator/ReactionsGeneratorTest.xtend b/tests/tools.vitruv.dsls.reactions.tests/src/tools/vitruv/dsls/reactions/generator/ReactionsGeneratorTest.xtend index 7e73f24db..2d565dd02 100755 --- a/tests/tools.vitruv.dsls.reactions.tests/src/tools/vitruv/dsls/reactions/generator/ReactionsGeneratorTest.xtend +++ b/tests/tools.vitruv.dsls.reactions.tests/src/tools/vitruv/dsls/reactions/generator/ReactionsGeneratorTest.xtend @@ -28,7 +28,6 @@ class ReactionsGeneratorTest { @Inject Provider generatorProvider @Inject Provider resourceSetProvider static val CHANGE_PROPAGATION_SPEC_NAME_SUFFIX = 'ChangePropagationSpecification' - static val EXECUTOR_CLASS_NAME = 'ReactionsExecutor' static val REACTION_NAME = 'TestReaction' static val FIRST_SEGMENT = 'firstTestReaction' static val SECOND_SEGMENT = 'secondTestReaction' @@ -61,14 +60,12 @@ class ReactionsGeneratorTest { } private static def assertFilesForReaction(InMemoryFileSystemAccess fsa, String segmentName, String reactionName) { - assertFilesForReactionWithoutExecutor(fsa, segmentName, reactionName) - assertThat(fsa.allFiles.keySet, - hasItem(endsWith(segmentName + '/' + EXECUTOR_CLASS_NAME + '.java'))) + assertFilesForReactionWithoutChangePropagationSpecification(fsa, segmentName, reactionName) assertThat(fsa.allFiles.keySet, hasItem(endsWith(segmentName + '/' + segmentName.toFirstUpper + CHANGE_PROPAGATION_SPEC_NAME_SUFFIX + '.java'))) } - private static def assertFilesForReactionWithoutExecutor(InMemoryFileSystemAccess fsa, String segmentName, String reactionName) { + private static def assertFilesForReactionWithoutChangePropagationSpecification(InMemoryFileSystemAccess fsa, String segmentName, String reactionName) { assertThat(fsa.allFiles.keySet, hasItem(endsWith(segmentName + '/' + reactionName + 'Reaction.java'))) assertThat(fsa.allFiles.keySet, @@ -93,10 +90,10 @@ class ReactionsGeneratorTest { fsa.assertFilesForReaction(SECOND_SEGMENT, REACTION_NAME); fsa.assertFilesForReaction(THIRD_SEGMENT, REACTION_NAME); - val secondExecutorFileName = fsa.allFiles.entrySet.findFirst [ - key.endsWith(SECOND_SEGMENT + '/' + EXECUTOR_CLASS_NAME + '.java') + val secondChangePropagationSpecificationFileName = fsa.allFiles.entrySet.findFirst [ + key.endsWith(SECOND_SEGMENT + '/' + SECOND_SEGMENT.toFirstUpper + CHANGE_PROPAGATION_SPEC_NAME_SUFFIX + '.java') ].key - fsa.deleteFile(secondExecutorFileName, '') + fsa.deleteFile(secondChangePropagationSpecificationFileName, '') generator = generatorProvider.get() generator.useResourceSet(resourceSetProvider.get()) @@ -104,7 +101,7 @@ class ReactionsGeneratorTest { generator.generate(fsa) fsa.assertFilesForReaction(FIRST_SEGMENT, REACTION_NAME); - fsa.assertFilesForReactionWithoutExecutor(SECOND_SEGMENT, REACTION_NAME); + fsa.assertFilesForReactionWithoutChangePropagationSpecification(SECOND_SEGMENT, REACTION_NAME); fsa.assertFilesForReaction(THIRD_SEGMENT, REACTION_NAME); fsa.assertFilesForReaction(FOURTH_SEGMENT, REACTION_NAME); }