Package jetbrains.mps.generator.impl
Class TemplateGenerator
- java.lang.Object
 - 
- jetbrains.mps.generator.impl.AbstractTemplateGenerator
 - 
- jetbrains.mps.generator.impl.TemplateGenerator
 
 
 
- 
- All Implemented Interfaces:
 GeneratorQueryProvider.Source,ITemplateGenerator
- Direct Known Subclasses:
 ParallelTemplateGenerator
public class TemplateGenerator extends AbstractTemplateGenerator
Created by: Sergey Dmitriev Date: Jan 23, 2007 Created once per micro-step. 
- 
- 
Field Summary
Fields Modifier and Type Field Description protected List<SNode>myOutputRoots- 
Fields inherited from class jetbrains.mps.generator.impl.AbstractTemplateGenerator
myInputModel, myOutputModel, myProgressMonitor 
 - 
 
- 
Constructor Summary
Constructors Constructor Description TemplateGenerator(GenerationSessionContext operationContext, SModel inputModel, SModel outputModel, jetbrains.mps.generator.impl.TemplateGenerator.StepArguments stepArgs) 
- 
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanapply(ProgressMonitor progressMonitor, boolean isPrimary)protected voidapplyCreateRoot(TemplateCreateRootRule rule)protected voidapplyCreateRoot(TemplateCreateRootRule rule, TemplateExecutionEnvironment environment)protected voidapplyReductions(boolean isPrimary)protected voidapplyRootRule(TemplateRootMappingRule rule, SNode inputNode, boolean copyRootOnFailure)booleanareMappingsAvailable()Generally, mapping labels are not available till the end ot structure transformation, which may run in parallel threads and thus access to label would be unpredictable.voidcheckIsExpectedLanguage(Iterable<SNode> nodes, SNodeReference templateNode, TemplateContext templateContext)protected voidcopyRootInputNode(SNode inputRootNode)protected voidcopyRootInputNode(SNode inputRootNode, TemplateExecutionEnvironmentImpl env)protected DeltaBuildercreateDeltaBuilder()protected voidcreateRootNodeByRule(TemplateRootMappingRule rule, SNode inputNode, TemplateExecutionEnvironmentImpl env, boolean copyRootOnFailure)voidexecuteScript(TemplateMappingScript script)SNodefindCopiedOutputNodeForInputNode(SNode inputNode)SNodefindOutputNode(SModel inputModel, String mappingName)SNodefindOutputNodeById(SNodeId nodeId)SNodefindOutputNodeByInputNodeAndMappingName(SNode inputNode, String mappingName)For a cross-mode reference, we expect inputNode to point either at original model (or external non-transient model), or one of checkpoint models.protected QueryExecutionContextgetDefaultExecutionContext()Executor for queries from primary/main thread.SNodegetOriginalRootByGenerated(SNode root)SModelgetOutputModel()TemplateSwitchMappinggetSwitch(SNodeReference switch_)booleanisStrict()protected TemplateExecutionEnvironmentImplnewExecutionEnvironment(QueryExecutionContext queryExecutor)distinct context for a reduction path/track/trail.PostponedReferenceregister(PostponedReference ref)voidregisterDynamicReference(SReference dr)Let generator know about dynamic references produced during generation.protected voidregisterRoot(jetbrains.mps.generator.impl.TemplateGenerator.GeneratedRootDescriptor rd)- 
Methods inherited from class jetbrains.mps.generator.impl.AbstractTemplateGenerator
addCopiedOutputNodeForInputNode, addOutputNodeByInputAndTemplateNode, checkMonitorCanceled, findAllOutputNodesByInputNodeAndMappingName, findCopiedOutputNodeForInputNode_unique, findOutputNodeByInputAndTemplateNode, findOutputNodeByTemplateNodeUnique, getChildRoleValidator, getGeneratorSessionContext, getInputModel, getLogger, getMappings, getQueryProvider, getReferentRoleValidator, registerMappingLabel 
 - 
 
 - 
 
- 
- 
Constructor Detail
- 
TemplateGenerator
public TemplateGenerator(GenerationSessionContext operationContext, SModel inputModel, SModel outputModel, jetbrains.mps.generator.impl.TemplateGenerator.StepArguments stepArgs)
 
 - 
 
- 
Method Detail
- 
apply
public boolean apply(@NotNull ProgressMonitor progressMonitor, boolean isPrimary) throws GenerationFailureException, GenerationCanceledException
 
- 
executeScript
public void executeScript(TemplateMappingScript script) throws GenerationFailureException
- Throws:
 GenerationFailureException
 
- 
applyReductions
protected void applyReductions(boolean isPrimary) throws GenerationCanceledException, GenerationFailureException 
- 
applyCreateRoot
protected void applyCreateRoot(TemplateCreateRootRule rule) throws GenerationFailureException, GenerationCanceledException
 
- 
applyCreateRoot
protected final void applyCreateRoot(TemplateCreateRootRule rule, TemplateExecutionEnvironment environment) throws GenerationFailureException, GenerationCanceledException
 
- 
applyRootRule
protected void applyRootRule(TemplateRootMappingRule rule, SNode inputNode, boolean copyRootOnFailure) throws GenerationCanceledException, GenerationFailureException
 
- 
createRootNodeByRule
protected final void createRootNodeByRule(TemplateRootMappingRule rule, SNode inputNode, TemplateExecutionEnvironmentImpl env, boolean copyRootOnFailure) throws GenerationCanceledException, GenerationFailureException
 
- 
copyRootInputNode
protected void copyRootInputNode(@NotNull SNode inputRootNode) throws GenerationFailureException, GenerationCanceledException
 
- 
copyRootInputNode
protected final void copyRootInputNode(@NotNull SNode inputRootNode, @NotNull TemplateExecutionEnvironmentImpl env) throws GenerationFailureException, GenerationCanceledException
 
- 
getOutputModel
public SModel getOutputModel()
- Specified by:
 getOutputModelin interfaceITemplateGenerator- Overrides:
 getOutputModelin classAbstractTemplateGenerator
 
- 
getDefaultExecutionContext
protected final QueryExecutionContext getDefaultExecutionContext()
Executor for queries from primary/main thread. If there's only one thread, this is the only query executor out there. For parallel execution,subclassshall provide an appropriate wrapper as needed and when needed (i.e. when a transformation task is executed in a distinct thread). Main thread is responsible for any transformation that expects sequential execution, like pre- and post- processing scripts, weaving rules (need complete output model, although likely we can apply weaving rules in parallel once reduction rules are over, i.e. need a sort of barrier), reference post-processing (macro queries are executed during transformation, but actual references are set from main thread), delayed changes (MAP-SRC postprocessing) and conditions for root mapping rules (there's reason to do so, see #createRootNodeByRule, above)- Returns:
 - never 
null 
 
- 
newExecutionEnvironment
protected final TemplateExecutionEnvironmentImpl newExecutionEnvironment(QueryExecutionContext queryExecutor)
distinct context for a reduction path/track/trail. So far, we may need PerformanceTrace in QueryExecutionContext only. If, however, some day we would like to access performance tracer from another code (e.g. from generated templates), we would need to pass per-thread PerformanceTracer here as well (and make sure the tracer for QEC and the one available from TEEI match).- Parameters:
 queryExecutor- not null- Returns:
 - never null
 
 
- 
createDeltaBuilder
protected DeltaBuilder createDeltaBuilder()
 
- 
findOutputNodeById
public SNode findOutputNodeById(SNodeId nodeId)
- Overrides:
 findOutputNodeByIdin classAbstractTemplateGenerator
 
- 
findCopiedOutputNodeForInputNode
public SNode findCopiedOutputNodeForInputNode(SNode inputNode)
- Specified by:
 findCopiedOutputNodeForInputNodein interfaceITemplateGenerator- Overrides:
 findCopiedOutputNodeForInputNodein classAbstractTemplateGenerator
 
- 
findOutputNodeByInputNodeAndMappingName
public SNode findOutputNodeByInputNodeAndMappingName(SNode inputNode, String mappingName)
For a cross-mode reference, we expect inputNode to point either at original model (or external non-transient model), or one of checkpoint models. There's no evidence one could get anything but that for a node referenced from another model during generation (i.e. no chances for inputNode to point to intermediate transient model).- Specified by:
 findOutputNodeByInputNodeAndMappingNamein interfaceITemplateGenerator- Overrides:
 findOutputNodeByInputNodeAndMappingNamein classAbstractTemplateGenerator- Parameters:
 inputNode- node from almost any model that may have served as an input for a generator. We tolerate null value now, indicating we are looking for conditional root (takes no input to create one)mappingName- label of the transformation of interest. Null value is tolerated but would yield no result instantly.- Returns:
 - node created from the specified input and marked with the label.
 
 
- 
findOutputNode
@Nullable public SNode findOutputNode(SModel inputModel, String mappingName)
- Parameters:
 inputModel- null is tolerated, mappings for the actual model are looked upmappingName- label of the transformation of interest. Null value is tolerated but would yield no result instantly.- Returns:
 - conditional root instantiated for the supplied model
 
 
- 
checkIsExpectedLanguage
public void checkIsExpectedLanguage(@NotNull Iterable<SNode> nodes, @NotNull SNodeReference templateNode, @NotNull TemplateContext templateContext)
 
- 
getSwitch
public TemplateSwitchMapping getSwitch(SNodeReference switch_)
 
- 
areMappingsAvailable
public boolean areMappingsAvailable()
Description copied from interface:ITemplateGeneratorGenerally, mapping labels are not available till the end ot structure transformation, which may run in parallel threads and thus access to label would be unpredictable. Use this method to control retrieve of labels only, it's not suitable to tell whether it's possible toadd new label- Returns:
 trueif it's proper time to query (!) for label
 
- 
isStrict
public boolean isStrict()
 
- 
register
public PostponedReference register(@NotNull PostponedReference ref)
 
- 
registerDynamicReference
public void registerDynamicReference(@NotNull SReference dr)
Let generator know about dynamic references produced during generation. We might handleDynamicReferencein a special way as long as there's evading reason to keep references dynamic during generation (as it only slows down model access due to ongoing scope use.- Parameters:
 dr- DynamicReference instance
 
- 
registerRoot
protected void registerRoot(jetbrains.mps.generator.impl.TemplateGenerator.GeneratedRootDescriptor rd)
 
 - 
 
 -