Class AbstractModelTranslator<M extends Script,L extends de.uni_hildesheim.sse.vilBuildLanguage.LanguageUnit>
- 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,VariableDeclaration,Resolver,ExpressionStatement,ExpressionTranslator>
-
- de.uni_hildesheim.sse.buildLanguageTranslation.AbstractModelTranslator<M,L>
-
- All Implemented Interfaces:
IMessageReceiver
- Direct Known Subclasses:
ModelTranslator
public abstract class AbstractModelTranslator<M extends Script,L extends de.uni_hildesheim.sse.vilBuildLanguage.LanguageUnit> extends ModelTranslator<M,VariableDeclaration,Resolver,ExpressionStatement,ExpressionTranslator>
Implements the translation from the DSL to the build model in the instantiator core. This class is intended for reuse.- Author:
- Holger Eichelberger
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classAbstractModelTranslator.AbstractRuleTranslator<D extends org.eclipse.emf.ecore.EObject,R extends Rule>An extensible rule translator.protected classAbstractModelTranslator.RuleTranslatorImplements a translator for VIL rules.
-
Field Summary
Fields Modifier and Type Field Description private ExpressionTranslatorexpressionTranslatorprivate Resolverresolverprivate AbstractModelTranslator.RuleTranslatorruleTranslator
-
Constructor Summary
Constructors Modifier Constructor Description AbstractModelTranslator()Creates a model translator.protectedAbstractModelTranslator(ExpressionTranslator expressionTranslator, Resolver resolver)Creates a model translator.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidaddVisibleDeclarationsToResolver(M model, Resolver resolver)Adds visible declarations ofmodeltoresolver.protected voidcheckConstants(Script project, L cause)Performs static tests on the constants.protected VariableDeclaration[]createArray(int len)Creates an array of .protected CompoundcreateCompound(CompoundTypeDescriptor type)Creates a compound object.protected abstract McreateScript(java.lang.String name, ModelImport<M> parent, Script.ScriptDescriptor<M> descriptor, TypeRegistry registry)Creates a script instance.protected McreateScript(L script, java.net.URI uri, boolean registerSuccessful, java.util.List<de.uni_hildesheim.sse.vilBuildLanguage.LanguageUnit> inProgress, Imports<M> imports, ImportResolver<M> impResolver)Creates a script instance from an EMF instance.protected TypedefcreateTypedef(java.lang.String name, TypeDescriptor<?> type)Creates a typdef object.(package private) voiderror(VilException exception, org.eclipse.emf.ecore.EObject cause, org.eclipse.emf.ecore.EStructuralFeature causeFeature)Turns a buildlang exception into a xText error.protected java.util.List<org.eclipse.emf.ecore.EObject>getContents(L script)Returns the actual contents ofscript.protected abstract ModelManagement<M>getManagementInstance()Returns the management instance.protected abstract IModelLoader<M>getModelLoader()private static booleanisProtected(de.uni_hildesheim.sse.vilBuildLanguage.RuleDeclaration rule)Returns whether a rule is protected.protected voidprocessAdditionalContents(L unit, java.util.List<org.eclipse.emf.ecore.EObject> elements, M result)Extension point forprocessContents(LanguageUnit, Script).protected voidprocessContents(L script, M result)Processes the contents of a language unit and stores the results inresult.protected voidprocessGlobalVariableDeclarations(java.util.List<org.eclipse.emf.ecore.EObject> elts, M result)Processes the global script variable declarations.protected Imports<M>processImports(org.eclipse.emf.common.util.EList<de.uni_hildesheim.sse.vil.expressions.expressionDsl.Import> imports, org.eclipse.emf.common.util.EList<de.uni_hildesheim.sse.vilBuildLanguage.Require> requires)Processes the imports and returns an summarizing instance.protected voidreProcessGlobalVariableDeclarations(M model)Re-processes global variable declarations to get rid of temporary "function pointer" expressions.private java.util.List<Expression>resolveExpressions(org.eclipse.emf.common.util.EList<de.uni_hildesheim.sse.vil.expressions.expressionDsl.LogicalExpression> expressions)Resolves a set of expressions.private voidresolveRuleExpressions(RuleDescriptor descriptor, Rule.Side side, org.eclipse.emf.common.util.EList<de.uni_hildesheim.sse.vil.expressions.expressionDsl.LogicalExpression> expressions)Resolves rule expressions.(package private) voidwarning(VilException exception, org.eclipse.emf.ecore.EObject cause, org.eclipse.emf.ecore.EStructuralFeature causeFeature)Turns a buildlang exception into a xText warning.-
Methods inherited from class de.uni_hildesheim.sse.vil.expressions.translation.ModelTranslator
convert, getExtensionImport, getResolver, postResolveImports, processAdvices, processCompoundContents, processCompounds, processImports, processTypedefContents, processTypedefs, processVariableDeclarations, processVariableDeclarations, resolveImports, resolveParameters, resolveParameters, warnVersionRestrictions
-
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
-
-
-
-
Field Detail
-
expressionTranslator
private ExpressionTranslator expressionTranslator
-
resolver
private Resolver resolver
-
ruleTranslator
private AbstractModelTranslator.RuleTranslator ruleTranslator
-
-
Constructor Detail
-
AbstractModelTranslator
public AbstractModelTranslator()
Creates a model translator.
-
AbstractModelTranslator
protected AbstractModelTranslator(ExpressionTranslator expressionTranslator, Resolver resolver)
Creates a model translator.- Parameters:
expressionTranslator- the expression translator to useresolver- the resolver to use
-
-
Method Detail
-
createScript
protected M createScript(L script, java.net.URI uri, boolean registerSuccessful, java.util.List<de.uni_hildesheim.sse.vilBuildLanguage.LanguageUnit> inProgress, Imports<M> imports, ImportResolver<M> impResolver) throws TranslatorException
Creates a script instance from an EMF instance.- Parameters:
script- the EMF instance to work onuri- the URI of the project to resolve (in order to find the closest project, may be null)registerSuccessful- successfully created models shall be registeredinProgress- the scripts currently being translatedimports- the global importsimpResolver- the import resolver to use (may be null to use a new default import resolver)- Returns:
- the created script
- Throws:
TranslatorException- in case that a problem occurred
-
processContents
protected void processContents(L script, M result) throws TranslatorException
Processes the contents of a language unit and stores the results inresult. Calls#processAdditionalContents(LanguageUnit, Script)if the contents is processable.- Parameters:
script- the script language unit to be processedresult- the result instance to be modified- Throws:
TranslatorException- in case that processing fails
-
processGlobalVariableDeclarations
protected void processGlobalVariableDeclarations(java.util.List<org.eclipse.emf.ecore.EObject> elts, M result)Processes the global script variable declarations.- Parameters:
script- the script language unit to be processedresult- the result instance to be modified
-
reProcessGlobalVariableDeclarations
protected void reProcessGlobalVariableDeclarations(M model)
Re-processes global variable declarations to get rid of temporary "function pointer" expressions.- Parameters:
model- the model to be processed
-
getContents
protected java.util.List<org.eclipse.emf.ecore.EObject> getContents(L script)
Returns the actual contents ofscript.- Parameters:
script- the script to return the contents for- Returns:
- the script contents
-
processAdditionalContents
protected void processAdditionalContents(L unit, java.util.List<org.eclipse.emf.ecore.EObject> elements, M result) throws TranslatorException
Extension point forprocessContents(LanguageUnit, Script).- Parameters:
unit- the language unit to processscript- the script language unit to be processedresult- the result instance to be modified- Throws:
TranslatorException- in case that processing fails
-
createScript
protected abstract M createScript(java.lang.String name, ModelImport<M> parent, Script.ScriptDescriptor<M> descriptor, TypeRegistry registry)
Creates a script instance.- Parameters:
name- Name of the project.parent- the super script to inherit from (as a script import, may be null, shall be member ofimportsor also null)descriptor- the descriptor carrying parameters, advices and imports (may be null)registry- the responsible type registry
-
processImports
protected Imports<M> processImports(org.eclipse.emf.common.util.EList<de.uni_hildesheim.sse.vil.expressions.expressionDsl.Import> imports, org.eclipse.emf.common.util.EList<de.uni_hildesheim.sse.vilBuildLanguage.Require> requires) throws TranslatorException
Processes the imports and returns an summarizing instance.- Parameters:
imports- the imports to be processed- Returns:
- the summarizing instance
- Throws:
TranslatorException- in case that processing the imports fails
-
getManagementInstance
protected abstract ModelManagement<M> getManagementInstance()
Returns the management instance.- Specified by:
getManagementInstancein classModelTranslator<M extends Script,VariableDeclaration,Resolver,ExpressionStatement,ExpressionTranslator>- Returns:
- the management instance
-
getModelLoader
protected abstract IModelLoader<M> getModelLoader()
-
checkConstants
protected void checkConstants(Script project, L cause)
Performs static tests on the constants.- Parameters:
project- the project createdcause- the causing ECore element- Throws:
TranslatorException- in case that a problem occurred
-
resolveExpressions
private java.util.List<Expression> resolveExpressions(org.eclipse.emf.common.util.EList<de.uni_hildesheim.sse.vil.expressions.expressionDsl.LogicalExpression> expressions) throws TranslatorException
Resolves a set of expressions.- Parameters:
expressions- the expressions to be resolved- Returns:
- the resolved expression (may be less than the elements in
expressionsin case of errors) or null in case of errors - Throws:
TranslatorException
-
resolveRuleExpressions
private void resolveRuleExpressions(RuleDescriptor descriptor, Rule.Side side, org.eclipse.emf.common.util.EList<de.uni_hildesheim.sse.vil.expressions.expressionDsl.LogicalExpression> expressions) throws TranslatorException
Resolves rule expressions.- Parameters:
descriptor- the rule descriptor as target for the dataside- the rule sideexpressions- the expressions to be resolved- Throws:
TranslatorException- in case of resolution problems
-
createArray
protected VariableDeclaration[] createArray(int len)
Description copied from class:ModelTranslatorCreates an array of .- Specified by:
createArrayin classModelTranslator<M extends Script,VariableDeclaration,Resolver,ExpressionStatement,ExpressionTranslator>- Parameters:
len- the length of the array- Returns:
- the array
-
isProtected
private static boolean isProtected(de.uni_hildesheim.sse.vilBuildLanguage.RuleDeclaration rule)
Returns whether a rule is protected.- Parameters:
rule- the rule to be tested- Returns:
trueif it is protected,falseelse
-
error
void error(VilException exception, org.eclipse.emf.ecore.EObject cause, org.eclipse.emf.ecore.EStructuralFeature causeFeature)
Turns a buildlang exception into a xText error.- Parameters:
exception- the exception to usedcause- the cause (as instance of the EMF grammar model)causeFeature- the cause of the feature
-
warning
void warning(VilException exception, org.eclipse.emf.ecore.EObject cause, org.eclipse.emf.ecore.EStructuralFeature causeFeature)
Turns a buildlang exception into a xText warning.- Parameters:
exception- the exception to usedcause- the cause (as instance of the EMF grammar model)causeFeature- the cause of the feature
-
addVisibleDeclarationsToResolver
protected void addVisibleDeclarationsToResolver(M model, Resolver resolver)
Description copied from class:ModelTranslatorAdds visible declarations ofmodeltoresolver. This method shall not consider imports as it is called byModelTranslator.addImportedVariablesToResolver(IModel, boolean, Set).- Specified by:
addVisibleDeclarationsToResolverin classModelTranslator<M extends Script,VariableDeclaration,Resolver,ExpressionStatement,ExpressionTranslator>- Parameters:
model- the model to considerresolver- the resolver to add variables to
-
createTypedef
protected Typedef createTypedef(java.lang.String name, TypeDescriptor<?> type) throws VilException
Description copied from class:ModelTranslatorCreates a typdef object.- Specified by:
createTypedefin classModelTranslator<M extends Script,VariableDeclaration,Resolver,ExpressionStatement,ExpressionTranslator>- Parameters:
name- the name of the typdef/aliastype- the the type- Returns:
- the typedef
- Throws:
VilException
-
createCompound
protected Compound createCompound(CompoundTypeDescriptor type) throws VilException
Description copied from class:ModelTranslatorCreates a compound object.- Specified by:
createCompoundin classModelTranslator<M extends Script,VariableDeclaration,Resolver,ExpressionStatement,ExpressionTranslator>- Parameters:
type- the the compound type- Returns:
- the typedef
- Throws:
VilException
-
-