Class ModelTranslator<M extends net.ssehub.easy.basics.modelManagement.IModel,I extends net.ssehub.easy.instantiation.core.model.common.VariableDeclaration,R extends net.ssehub.easy.instantiation.core.model.expressions.Resolver<I>,S extends net.ssehub.easy.instantiation.core.model.common.ExpressionStatement,E extends ExpressionTranslator<I,R,S>>

java.lang.Object
net.ssehub.easy.dslCore.translation.MessageReceiver
net.ssehub.easy.dslCore.translation.ModelTranslator<E>
de.uni_hildesheim.sse.vil.expressions.translation.ModelTranslator<M,I,R,S,E>
Type Parameters:
I - the variable declaration type
R - the resolver type
E - the expression translator type
All Implemented Interfaces:
net.ssehub.easy.dslCore.translation.IMessageReceiver

public abstract class ModelTranslator<M extends net.ssehub.easy.basics.modelManagement.IModel,I extends net.ssehub.easy.instantiation.core.model.common.VariableDeclaration,R extends net.ssehub.easy.instantiation.core.model.expressions.Resolver<I>,S extends net.ssehub.easy.instantiation.core.model.common.ExpressionStatement,E extends ExpressionTranslator<I,R,S>> extends net.ssehub.easy.dslCore.translation.ModelTranslator<E>
A reusable model translator.
Author:
Holger Eichelberger
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private R
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    ModelTranslator(E expressionTranslator, R resolver)
    Creates a new model translator.
  • Method Summary

    Modifier and Type
    Method
    Description
    private void
    addImportedVariablesToResolver(M model, boolean addModel, Set<M> done)
    Adds (transitively) imported variables to the actual resolver.
    protected abstract void
    Adds visible declarations of model to resolver.
    private void
    buildLocalTypeRegistry(net.ssehub.easy.instantiation.core.model.common.Advice advice)
    Builds a local type registry for advice.
    protected <O extends net.ssehub.easy.instantiation.core.model.common.IResolvableOperation<I>>
    void
    checkOperationAnnotations(O op, org.eclipse.emf.ecore.EObject cause, org.eclipse.emf.ecore.EStructuralFeature causingFeature)
    Checks operation annotation consistency and emits warnings/errors.
    static net.ssehub.easy.basics.modelManagement.Version
    convert(VersionStmt versionStatement)
    Converts a grammar version statement into a model version object.
    protected abstract I[]
    createArray(int len)
    Creates an array of .
    protected abstract net.ssehub.easy.instantiation.core.model.common.Compound
    createCompound(net.ssehub.easy.instantiation.core.model.vilTypes.CompoundTypeDescriptor type)
    Creates a compound object.
    protected abstract net.ssehub.easy.instantiation.core.model.common.Typedef
    createTypedef(String name, net.ssehub.easy.instantiation.core.model.vilTypes.TypeDescriptor<?> type)
    Creates a typdef object.
    protected net.ssehub.easy.basics.modelManagement.ModelImport<M>
    getExtensionImport(String name, net.ssehub.easy.instantiation.core.model.common.Imports<M> imports, org.eclipse.emf.ecore.EObject cause, org.eclipse.emf.ecore.EStructuralFeature causingFeature)
    Returns an extension import (super script, super template).
    protected abstract net.ssehub.easy.basics.modelManagement.ModelManagement<M>
    Returns the management instance.
    protected R
    Returns the resolver instance.
    protected List<net.ssehub.easy.basics.messages.IMessage>
    postResolveImports(M model, URI uri, List<net.ssehub.easy.basics.messages.IMessage> resolutionMessages)
    Is called in case of resolution problems.
    protected net.ssehub.easy.instantiation.core.model.common.Advice[]
    processAdvices(org.eclipse.emf.common.util.EList<Advice> advices, URI modelURI)
    Processes the advices (of a script).
    protected void
    processCompoundContents(List<org.eclipse.emf.ecore.EObject> elts, net.ssehub.easy.instantiation.core.model.common.ICompoundReceiver receiver)
    Processes the compounds in elts.
    protected void
    processCompounds(List<Compound> cmps, net.ssehub.easy.instantiation.core.model.common.ICompoundReceiver receiver)
    Processes the given compounds.
    private void
    processCompounds(List<Compound> cmps, net.ssehub.easy.instantiation.core.model.common.ICompoundReceiver receiver, boolean force)
    Processes the given typedefs.
    protected net.ssehub.easy.instantiation.core.model.common.Imports<M>
    processImports(org.eclipse.emf.common.util.EList<Import> imports)
    Processes the imports and returns an summarizing instance.
    protected void
    processTypedefContents(List<org.eclipse.emf.ecore.EObject> elts, net.ssehub.easy.instantiation.core.model.common.ITypedefReceiver receiver)
    Processes the typedefs in elts.
    protected void
    processTypedefs(List<TypeDef> defs, net.ssehub.easy.instantiation.core.model.common.ITypedefReceiver receiver)
    Processes the given typedefs.
    private void
    processTypedefs(List<TypeDef> defs, net.ssehub.easy.instantiation.core.model.common.ITypedefReceiver receiver, boolean force)
    Processes the given typedefs.
    protected void
    processVariableDeclarations(List<VariableDeclaration> decls, net.ssehub.easy.instantiation.core.model.common.IVariableDeclarationReceiver<I> receiver)
    Processes all variable declarations considering dependencies and terminates with an error if not all can be resolved.
    protected void
    processVariableDeclarations(List<VariableDeclaration> decls, net.ssehub.easy.instantiation.core.model.common.IVariableDeclarationReceiver<I> receiver, boolean addToResolver)
    Processes all variable declarations considering dependencies and terminates with an error if not all can be resolved.
    private void
    processVariableDeclarations(List<VariableDeclaration> decls, net.ssehub.easy.instantiation.core.model.common.IVariableDeclarationReceiver<I> receiver, boolean force, boolean addToResolver)
    Processes a set of variable declarations and adds successfully processed ones to the current resolver level.
    protected void
    resolveImports(LanguageUnit input, org.eclipse.emf.ecore.EStructuralFeature inputFeature, M model, URI uri, List<? extends LanguageUnit> inProgress, net.ssehub.easy.basics.modelManagement.ImportResolver<M> impResolver)
    Resolves the imports.
    protected I[]
    resolveParameters(ParameterList pList, org.eclipse.emf.ecore.EObject cause, org.eclipse.emf.ecore.EStructuralFeature paramListFeature, R resolver)
    Resolves the parameters in pList.
    protected I[]
    resolveParameters(org.eclipse.emf.common.util.EList<Parameter> parameters, org.eclipse.emf.ecore.EObject cause, org.eclipse.emf.ecore.EStructuralFeature paramListFeature, R resolver)
    Resolves the parameters in parameters.
    protected void
    Issues implementation warnings about version restrictions.

    Methods inherited from class net.ssehub.easy.dslCore.translation.ModelTranslator

    addMessage, collect, copy, error, error, getErrorCount, getExpressionTranslator, getMessage, getMessageCount, select, warning

    Methods inherited from class net.ssehub.easy.dslCore.translation.MessageReceiver

    error

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • resolver

      private R extends net.ssehub.easy.instantiation.core.model.expressions.Resolver<I> resolver
  • Constructor Details

    • ModelTranslator

      public ModelTranslator(E expressionTranslator, R resolver)
      Creates a new model translator.
      Parameters:
      expressionTranslator - the expression translator instance
      resolver - the resolver instance
  • Method Details

    • getResolver

      protected R getResolver()
      Returns the resolver instance.
      Returns:
      the resolver
    • processImports

      protected net.ssehub.easy.instantiation.core.model.common.Imports<M> processImports(org.eclipse.emf.common.util.EList<Import> imports) throws net.ssehub.easy.dslCore.translation.TranslatorException
      Processes the imports and returns an summarizing instance.
      Parameters:
      imports - the imports to be processed
      Returns:
      the summarizing instance
      Throws:
      net.ssehub.easy.dslCore.translation.TranslatorException - in case that processing the imports fails
    • getExtensionImport

      protected net.ssehub.easy.basics.modelManagement.ModelImport<M> getExtensionImport(String name, net.ssehub.easy.instantiation.core.model.common.Imports<M> imports, org.eclipse.emf.ecore.EObject cause, org.eclipse.emf.ecore.EStructuralFeature causingFeature) throws net.ssehub.easy.dslCore.translation.TranslatorException
      Returns an extension import (super script, super template).
      Parameters:
      name - the name of the model
      imports - the known imports
      cause - the causing ECore element (in case of throwing an exception)
      causingFeature - the causing feature (in case of throwing an exception)
      Returns:
      the found import
      Throws:
      net.ssehub.easy.dslCore.translation.TranslatorException - in case that the import cannot be found
    • processTypedefContents

      protected void processTypedefContents(List<org.eclipse.emf.ecore.EObject> elts, net.ssehub.easy.instantiation.core.model.common.ITypedefReceiver receiver)
      Processes the typedefs in elts.
      Parameters:
      elts - the elements
      receiver - the typedef receiver
    • processCompoundContents

      protected void processCompoundContents(List<org.eclipse.emf.ecore.EObject> elts, net.ssehub.easy.instantiation.core.model.common.ICompoundReceiver receiver)
      Processes the compounds in elts.
      Parameters:
      elts - the elements
      receiver - the compound receiver
    • processTypedefs

      protected void processTypedefs(List<TypeDef> defs, net.ssehub.easy.instantiation.core.model.common.ITypedefReceiver receiver)
      Processes the given typedefs.
      Parameters:
      defs - the typedefs
      receiver - the typedef receiver
    • processCompounds

      protected void processCompounds(List<Compound> cmps, net.ssehub.easy.instantiation.core.model.common.ICompoundReceiver receiver)
      Processes the given compounds.
      Parameters:
      receiver - the compozbd receiver
      defs - the compounds
    • processTypedefs

      private void processTypedefs(List<TypeDef> defs, net.ssehub.easy.instantiation.core.model.common.ITypedefReceiver receiver, boolean force)
      Processes the given typedefs.
      Parameters:
      defs - the typedefs
      receiver - the typedef receiver
      force - force processing typedefs not resolved so far
    • processCompounds

      private void processCompounds(List<Compound> cmps, net.ssehub.easy.instantiation.core.model.common.ICompoundReceiver receiver, boolean force)
      Processes the given typedefs.
      Parameters:
      receiver - the typedef receiver
      force - force processing typedefs not resolved so far
      defs - the typedefs
    • createTypedef

      protected abstract net.ssehub.easy.instantiation.core.model.common.Typedef createTypedef(String name, net.ssehub.easy.instantiation.core.model.vilTypes.TypeDescriptor<?> type) throws net.ssehub.easy.instantiation.core.model.common.VilException
      Creates a typdef object.
      Parameters:
      name - the name of the typdef/alias
      type - the the type
      Returns:
      the typedef
      Throws:
      net.ssehub.easy.instantiation.core.model.common.VilException
    • createCompound

      protected abstract net.ssehub.easy.instantiation.core.model.common.Compound createCompound(net.ssehub.easy.instantiation.core.model.vilTypes.CompoundTypeDescriptor type) throws net.ssehub.easy.instantiation.core.model.common.VilException
      Creates a compound object.
      Parameters:
      type - the the compound type
      Returns:
      the typedef
      Throws:
      net.ssehub.easy.instantiation.core.model.common.VilException
    • processVariableDeclarations

      protected void processVariableDeclarations(List<VariableDeclaration> decls, net.ssehub.easy.instantiation.core.model.common.IVariableDeclarationReceiver<I> receiver)
      Processes all variable declarations considering dependencies and terminates with an error if not all can be resolved.
      Parameters:
      decls - the declarations to be processed
      receiver - a receiver for the created instances
    • processVariableDeclarations

      protected void processVariableDeclarations(List<VariableDeclaration> decls, net.ssehub.easy.instantiation.core.model.common.IVariableDeclarationReceiver<I> receiver, boolean addToResolver)
      Processes all variable declarations considering dependencies and terminates with an error if not all can be resolved.
      Parameters:
      decls - the declarations to be processed
      receiver - a receiver for the created instances
      addToResolver - add the newly created variables to the resolver instance
    • processVariableDeclarations

      private void processVariableDeclarations(List<VariableDeclaration> decls, net.ssehub.easy.instantiation.core.model.common.IVariableDeclarationReceiver<I> receiver, boolean force, boolean addToResolver)
      Processes a set of variable declarations and adds successfully processed ones to the current resolver level.
      Parameters:
      decls - the declarations to be processed (successfully processed declarations will be removed, may be modified as a side effect)
      receiver - a receiver for the created instances
      force - if true a failing variable creation will be recorded as an error, false failing creations will be ignored
      addToResolver - add the newly created variable to the resolver instance
    • processAdvices

      protected net.ssehub.easy.instantiation.core.model.common.Advice[] processAdvices(org.eclipse.emf.common.util.EList<Advice> advices, URI modelURI)
      Processes the advices (of a script).
      Parameters:
      advices - the advices to be processed
      modelURI - the URI to the model being processed
      Returns:
      the processed advices
    • buildLocalTypeRegistry

      private void buildLocalTypeRegistry(net.ssehub.easy.instantiation.core.model.common.Advice advice)
      Builds a local type registry for advice.
      Parameters:
      advice - the advice to build the local type registry for
    • warnVersionRestrictions

      protected void warnVersionRestrictions(VersionSpec spec)
      Issues implementation warnings about version restrictions.
      Parameters:
      spec - the version specification (may be null)
    • resolveParameters

      protected I[] resolveParameters(ParameterList pList, org.eclipse.emf.ecore.EObject cause, org.eclipse.emf.ecore.EStructuralFeature paramListFeature, R resolver) throws net.ssehub.easy.dslCore.translation.TranslatorException
      Resolves the parameters in pList.
      Parameters:
      pList - the parameter list to be resolved
      cause - the causing object containing the parameters
      paramListFeature - the param list feature on cause
      resolver - the resolver instance
      Returns:
      the resolved parameters (may actually be less then in pList in case of name or type failures
      Throws:
      net.ssehub.easy.dslCore.translation.TranslatorException - in case that a problem occurred
    • resolveParameters

      protected I[] resolveParameters(org.eclipse.emf.common.util.EList<Parameter> parameters, org.eclipse.emf.ecore.EObject cause, org.eclipse.emf.ecore.EStructuralFeature paramListFeature, R resolver) throws net.ssehub.easy.dslCore.translation.TranslatorException
      Resolves the parameters in parameters.
      Parameters:
      parameters - the parameters to be resolved
      cause - the causing object containing the parameters
      paramListFeature - the param list feature on cause
      resolver - the resolver instance
      Returns:
      the resolved parameters (may actually be less then in pList in case of name or type failures
      Throws:
      net.ssehub.easy.dslCore.translation.TranslatorException - in case that a problem occurred
    • createArray

      protected abstract I[] createArray(int len)
      Creates an array of .
      Parameters:
      len - the length of the array
      Returns:
      the array
    • convert

      public static net.ssehub.easy.basics.modelManagement.Version convert(VersionStmt versionStatement)
      Converts a grammar version statement into a model version object.
      Parameters:
      versionStatement - the version statement to be converts
      Returns:
      the resulting model version object
    • getManagementInstance

      protected abstract net.ssehub.easy.basics.modelManagement.ModelManagement<M> getManagementInstance()
      Returns the management instance.
      Returns:
      the management instance
    • resolveImports

      protected void resolveImports(LanguageUnit input, org.eclipse.emf.ecore.EStructuralFeature inputFeature, M model, URI uri, List<? extends LanguageUnit> inProgress, net.ssehub.easy.basics.modelManagement.ImportResolver<M> impResolver)
      Resolves the imports.
      Parameters:
      input - the input language element
      inputFeature - the EMF feature this resolution happens on
      model - the model being created
      uri - the physical URI of the project
      inProgress - the other projects being resolved at once (in order to avoid loops)
    • addImportedVariablesToResolver

      private void addImportedVariablesToResolver(M model, boolean addModel, Set<M> done)
      Adds (transitively) imported variables to the actual resolver.
      Parameters:
      model - the model to consider
      addModel - whether the variables of model shall be added (true) or whether only its imports shall be traversed
      done - collects models that are already processed
      See Also:
    • addVisibleDeclarationsToResolver

      protected abstract void addVisibleDeclarationsToResolver(M model, R resolver)
      Adds visible declarations of model to resolver. This method shall not consider imports as it is called by addImportedVariablesToResolver(IModel, boolean, Set).
      Parameters:
      model - the model to consider
      resolver - the resolver to add variables to
    • postResolveImports

      protected List<net.ssehub.easy.basics.messages.IMessage> postResolveImports(M model, URI uri, List<net.ssehub.easy.basics.messages.IMessage> resolutionMessages)
      Is called in case of resolution problems.
      Parameters:
      model - the model to be resolved
      uri - the physical URI of the project
      resolutionMessages - the messages collected so far
      Returns:
      the new resolution messages
    • checkOperationAnnotations

      protected <O extends net.ssehub.easy.instantiation.core.model.common.IResolvableOperation<I>> void checkOperationAnnotations(O op, org.eclipse.emf.ecore.EObject cause, org.eclipse.emf.ecore.EStructuralFeature causingFeature)
      Checks operation annotation consistency and emits warnings/errors.
      Type Parameters:
      O - the operation type
      Parameters:
      op - the operation to check
      cause - the causing ECore element (in case of throwing an exception)
      causingFeature - the causing feature (in case of throwing an exception)