From e8c20acc50599ad32a9b1b01504caf58599838a3 Mon Sep 17 00:00:00 2001 From: anyssen Date: Wed, 23 Dec 2015 10:45:47 +0100 Subject: [PATCH] #266: Add support for optional generation of tracing callbacks. - Add Tracing generator feature with parameters to trigger generation of state-enter and state-exit callbacks. - Enhanced C code generator to generate callbacks to required header and respective calls based on corresponding trace steps. - Ensure that ADD_TRACES option is enabled for C code generator in case Tracing feature is enabled. Ensured its disabled for all other generators by default. Had to change contract of GenericDomainInjectorProvider to accept an overriding module, and replaced child injector usage in code generators with an overriding module instead. --- META-INF/MANIFEST.MF | 3 +- .../impl/AbstractSExecModelGenerator.java | 71 ++++++++++--------- .../impl/AbstractSGraphModelGenerator.java | 15 ++-- .../core/impl/GenericJavaBasedGenerator.java | 6 +- 4 files changed, 51 insertions(+), 44 deletions(-) diff --git a/META-INF/MANIFEST.MF b/META-INF/MANIFEST.MF index 8ef762b44e..b54206c454 100644 --- a/META-INF/MANIFEST.MF +++ b/META-INF/MANIFEST.MF @@ -22,7 +22,8 @@ Require-Bundle: org.eclipse.ui, org.yakindu.base.types;bundle-version="1.0.0", org.eclipse.xtext.builder;bundle-version="2.3.0", org.yakindu.sct.commons;bundle-version="1.0.0", - org.yakindu.sct.domain;bundle-version="2.4.1" + org.yakindu.sct.domain;bundle-version="2.4.1", + org.yakindu.sct.domain.generic;bundle-version="2.5.0" Bundle-RequiredExecutionEnvironment: JavaSE-1.7 Bundle-ActivationPolicy: lazy Export-Package: org.yakindu.sct.builder.nature, diff --git a/src/org/yakindu/sct/generator/core/impl/AbstractSExecModelGenerator.java b/src/org/yakindu/sct/generator/core/impl/AbstractSExecModelGenerator.java index 37dc32f76f..90ba531462 100644 --- a/src/org/yakindu/sct/generator/core/impl/AbstractSExecModelGenerator.java +++ b/src/org/yakindu/sct/generator/core/impl/AbstractSExecModelGenerator.java @@ -31,6 +31,7 @@ import org.eclipse.emf.ecore.resource.ResourceSet; import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; +import org.yakindu.sct.domain.generic.modules.GenericSequencerModule; import org.yakindu.sct.model.sexec.ExecutionFlow; import org.yakindu.sct.model.sexec.transformation.FlowOptimizer; import org.yakindu.sct.model.sexec.transformation.IModelSequencer; @@ -38,7 +39,11 @@ import org.yakindu.sct.model.sgen.GeneratorEntry; import org.yakindu.sct.model.sgraph.Statechart; +import com.google.inject.Binder; import com.google.inject.Injector; +import com.google.inject.Module; +import com.google.inject.name.Names; +import com.google.inject.util.Modules; /** * abstract base class for all code generators that want to generate code based @@ -47,8 +52,7 @@ * @author andreas muelder - Initial contribution and API * */ -public abstract class AbstractSExecModelGenerator extends - AbstractSGraphModelGenerator { +public abstract class AbstractSExecModelGenerator extends AbstractSGraphModelGenerator { private static final String SEXEC_FILE_EXTENSION = "sexec"; @@ -60,45 +64,49 @@ public AbstractSExecModelGenerator() { protected void runGenerator(Statechart statechart, GeneratorEntry entry) { if (this instanceof IExecutionFlowGenerator) { IExecutionFlowGenerator flowGenerator = (IExecutionFlowGenerator) this; - flowGenerator.generate(createExecutionFlow(statechart, entry), - entry, null); + flowGenerator.generate(createExecutionFlow(statechart, entry), entry, null); } super.runGenerator(statechart, entry); } + @Override + protected Module getOverridesModule(GeneratorEntry entry) { + Module module = super.getOverridesModule(entry); + + return Modules.override(module).with(new Module() { + public void configure(Binder binder) { + // by default, traces should not be generated + binder.bind(Boolean.class).annotatedWith(Names.named(GenericSequencerModule.ADD_TRACES)) + .toInstance(Boolean.FALSE); + } + }); + } + /** * Transforms the {@link Statechart} model to a {@link ExecutionFlow} model */ - protected ExecutionFlow createExecutionFlow(Statechart statechart, - GeneratorEntry entry) { + protected ExecutionFlow createExecutionFlow(Statechart statechart, GeneratorEntry entry) { Injector injector = getInjector(entry); IModelSequencer sequencer = injector.getInstance(IModelSequencer.class); ExecutionFlow flow = sequencer.transform(statechart); Assert.isNotNull(flow, "Error creation ExecutionFlow"); - FeatureConfiguration optimizeConfig = entry - .getFeatureConfiguration(FUNCTION_INLINING_FEATURE); + FeatureConfiguration optimizeConfig = entry.getFeatureConfiguration(FUNCTION_INLINING_FEATURE); FlowOptimizer optimizer = injector.getInstance(FlowOptimizer.class); - optimizer.inlineReactions(getBoolValue(optimizeConfig, - FUNCTION_INLINING_FEATURE_INLINE_REACTIONS, false)); - optimizer.inlineExitActions(getBoolValue(optimizeConfig, - FUNCTION_INLINING_FEATURE_INLINE_EXIT_ACTIONS, false)); - optimizer.inlineEntryActions(getBoolValue(optimizeConfig, - FUNCTION_INLINING_FEATURE_INLINE_ENTRY_ACTIONS, false)); - optimizer.inlineEnterSequences(getBoolValue(optimizeConfig, - FUNCTION_INLINING_FEATURE_INLINE_ENTER_SEQUENCES, false)); - optimizer.inlineExitSequences(getBoolValue(optimizeConfig, - FUNCTION_INLINING_FEATURE_INLINE_EXIT_SEQUENCES, false)); - optimizer.inlineChoices(getBoolValue(optimizeConfig, - FUNCTION_INLINING_FEATURE_INLINE_CHOICES, false)); - optimizer.inlineEntries(getBoolValue(optimizeConfig, - FUNCTION_INLINING_FEATURE_INLINE_ENTRIES, false)); - optimizer.inlineEnterRegion(getBoolValue(optimizeConfig, - FUNCTION_INLINING_FEATURE_INLINE_ENTER_REGION, false)); - optimizer.inlineExitRegion(getBoolValue(optimizeConfig, - FUNCTION_INLINING_FEATURE_INLINE_EXIT_REGION, false)); + optimizer.inlineReactions(getBoolValue(optimizeConfig, FUNCTION_INLINING_FEATURE_INLINE_REACTIONS, false)); + optimizer.inlineExitActions(getBoolValue(optimizeConfig, FUNCTION_INLINING_FEATURE_INLINE_EXIT_ACTIONS, false)); + optimizer.inlineEntryActions( + getBoolValue(optimizeConfig, FUNCTION_INLINING_FEATURE_INLINE_ENTRY_ACTIONS, false)); + optimizer.inlineEnterSequences( + getBoolValue(optimizeConfig, FUNCTION_INLINING_FEATURE_INLINE_ENTER_SEQUENCES, false)); + optimizer.inlineExitSequences( + getBoolValue(optimizeConfig, FUNCTION_INLINING_FEATURE_INLINE_EXIT_SEQUENCES, false)); + optimizer.inlineChoices(getBoolValue(optimizeConfig, FUNCTION_INLINING_FEATURE_INLINE_CHOICES, false)); + optimizer.inlineEntries(getBoolValue(optimizeConfig, FUNCTION_INLINING_FEATURE_INLINE_ENTRIES, false)); + optimizer.inlineEnterRegion(getBoolValue(optimizeConfig, FUNCTION_INLINING_FEATURE_INLINE_ENTER_REGION, false)); + optimizer.inlineExitRegion(getBoolValue(optimizeConfig, FUNCTION_INLINING_FEATURE_INLINE_EXIT_REGION, false)); flow = optimizer.transform(flow); @@ -107,13 +115,10 @@ protected ExecutionFlow createExecutionFlow(Statechart statechart, protected void dumpSexec(GeneratorEntry entry, ExecutionFlow flow) { ResourceSet resourceSet = new ResourceSetImpl(); - resourceSet - .getResourceFactoryRegistry() - .getExtensionToFactoryMap() - .put(Resource.Factory.Registry.DEFAULT_EXTENSION, - new XMIResourceFactoryImpl()); - URI fileURI = entry.getElementRef().eResource().getURI() - .trimFileExtension().appendFileExtension(SEXEC_FILE_EXTENSION); + resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap() + .put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl()); + URI fileURI = entry.getElementRef().eResource().getURI().trimFileExtension() + .appendFileExtension(SEXEC_FILE_EXTENSION); Resource resource = resourceSet.createResource(fileURI); resource.getContents().add(flow); try { diff --git a/src/org/yakindu/sct/generator/core/impl/AbstractSGraphModelGenerator.java b/src/org/yakindu/sct/generator/core/impl/AbstractSGraphModelGenerator.java index b59ec1bc87..44fe302f30 100644 --- a/src/org/yakindu/sct/generator/core/impl/AbstractSGraphModelGenerator.java +++ b/src/org/yakindu/sct/generator/core/impl/AbstractSGraphModelGenerator.java @@ -6,7 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * committers of YAKINDU - initial API and implementation + * Andreas Mülder - Initial API and implementation + * Alexaner Nyßen - Refactored to use overriding module instead of child injector */ package org.yakindu.sct.generator.core.impl; @@ -38,7 +39,7 @@ * abstract base class for all code generators that want to generate code based * on the {@link ExecutionFlow} * - * @author andreas muelder - Initial contribution and API + * @author Andreas Mülder - Initial contribution and API * */ public abstract class AbstractSGraphModelGenerator implements ISCTGenerator { @@ -73,7 +74,7 @@ public File getTargetProject(GeneratorEntry entry) { public File getTargetFolder(GeneratorEntry entry) { return GeneratorUtils.getTargetFolder(entry); } - + public File getLibraryTargetFolder(GeneratorEntry entry) { return GeneratorUtils.getLibraryTargetFolder(entry); } @@ -137,11 +138,11 @@ protected void finishGenerator(GeneratorEntry entry) { private Injector injector; protected Injector createInjector(GeneratorEntry entry) { - Injector sequencerInjector = DomainRegistry.getDomainDescriptor(entry.getElementRef()).getDomainInjectorProvider().getSequencerInjector(); - return sequencerInjector.createChildInjector(getChildInjectorModule(entry)); + return DomainRegistry.getDomainDescriptor(entry.getElementRef()).getDomainInjectorProvider() + .getSequencerInjector(getOverridesModule(entry)); } - protected Module getChildInjectorModule(GeneratorEntry entry) { + protected Module getOverridesModule(GeneratorEntry entry) { Module bridgeModule = new Module() { public void configure(Binder binder) { binder.bind(IGeneratorBridge.class).toInstance(bridge); @@ -180,7 +181,7 @@ private MessageConsole getConsole() { } } MessageConsole myConsole = new MessageConsole(SCT_GENERATOR_CONSOLE, null); - conMan.addConsoles(new IConsole[] { myConsole }); + conMan.addConsoles(new IConsole[]{myConsole}); return myConsole; } diff --git a/src/org/yakindu/sct/generator/core/impl/GenericJavaBasedGenerator.java b/src/org/yakindu/sct/generator/core/impl/GenericJavaBasedGenerator.java index b09071d061..0af1619f82 100644 --- a/src/org/yakindu/sct/generator/core/impl/GenericJavaBasedGenerator.java +++ b/src/org/yakindu/sct/generator/core/impl/GenericJavaBasedGenerator.java @@ -10,8 +10,8 @@ */ package org.yakindu.sct.generator.core.impl; -import static org.yakindu.sct.generator.core.features.ICoreFeatureConstants.OUTLET_FEATURE_TARGET_FOLDER; import static org.yakindu.sct.generator.core.features.ICoreFeatureConstants.OUTLET_FEATURE_LIBRARY_TARGET_FOLDER; +import static org.yakindu.sct.generator.core.features.ICoreFeatureConstants.OUTLET_FEATURE_TARGET_FOLDER; import static org.yakindu.sct.generator.core.features.impl.IGenericJavaFeatureConstants.CONFIGURATION_MODULE; import static org.yakindu.sct.generator.core.features.impl.IGenericJavaFeatureConstants.GENERATOR_CLASS; import static org.yakindu.sct.generator.core.features.impl.IGenericJavaFeatureConstants.GENERATOR_PROJECT; @@ -45,8 +45,8 @@ public class GenericJavaBasedGenerator extends AbstractSExecModelGenerator { @Override - protected Module getChildInjectorModule(final GeneratorEntry entry) { - Module defaultModule = super.getChildInjectorModule(entry); + protected Module getOverridesModule(final GeneratorEntry entry) { + Module defaultModule = super.getOverridesModule(entry); String overridingModuleClass = null; FeatureConfiguration featureConfiguration = entry.getFeatureConfiguration(TEMPLATE_FEATURE);