Class ModelTranslator
- java.lang.Object
-
- net.ssehub.easy.dslCore.translation.MessageReceiver
-
- net.ssehub.easy.dslCore.translation.ModelTranslator<E>
-
- de.uni_hildesheim.sse.vil.expressions.translation.ModelTranslator<Template,VariableDeclaration,Resolver,ExpressionStatement,ExpressionTranslator>
-
- de.uni_hildesheim.sse.vil.templatelang.templateLanguageTranslation.ModelTranslator
-
- All Implemented Interfaces:
IMessageReceiver
public class ModelTranslator extends ModelTranslator<Template,VariableDeclaration,Resolver,ExpressionStatement,ExpressionTranslator>
Translates a parsed template language in ECore instances into instances of the template language model and performs semantic analysis.- Author:
- Holger Eichelberger
-
-
Field Summary
Fields Modifier and Type Field Description private ExpressionTranslatorexpressionTranslatorprivate Resolverresolver
-
Constructor Summary
Constructors Constructor Description ModelTranslator()Creates the model translator.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddVisibleDeclarationsToResolver(Template model, Resolver resolver)Adds visible declarations ofmodeltoresolver.protected VariableDeclaration[]createArray(int len)Creates an array of .protected CompoundcreateCompound(CompoundTypeDescriptor type)Creates a compound object.TemplatecreateModel(de.uni_hildesheim.sse.vil.templatelang.templateLang.LanguageUnit tpl, java.net.URI uri, boolean registerSuccessful, ImportResolver<Template> impResolver)Creates a build model from a given implementation unit.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.static java.lang.StringgetJavaQualifiedNameString(de.uni_hildesheim.sse.vil.templatelang.templateLang.JavaQualifiedName name)Returns a string representing a qualified name.protected ModelManagement<Template>getManagementInstance()Returns the management instance.private AlternativeStatementprocessAlternative(de.uni_hildesheim.sse.vil.templatelang.templateLang.Alternative alt)Processes an alternative statement.private ITemplateElement[]processBlock(de.uni_hildesheim.sse.vil.templatelang.templateLang.StmtBlock block)Processes a block of rule elements.private ContentStatementprocessContent(de.uni_hildesheim.sse.vil.templatelang.templateLang.Content content, Resolver resolver)Processes a content statement.private DefprocessDef(de.uni_hildesheim.sse.vil.templatelang.templateLang.VilDef def, Template template)Processes a (sub-)template definition header.private voidprocessDefBody(DefInfo info)Processes a (sub-)template body.protected voidprocessDefs(java.util.List<org.eclipse.emf.ecore.EObject> elts, Template template)Processes all template defs considering dependencies and terminates with an error if not all can be resolved.private FlushStatementprocessFlush()Processes a content flush statement.private FormattingConfigurationprocessFormattingHint(de.uni_hildesheim.sse.vil.templatelang.templateLang.FormattingHint hint)Processes the formatting hint.protected voidprocessGlobalVariableDeclarations(java.util.List<org.eclipse.emf.ecore.EObject> elts, Template result)Processes the global script variable declarations.private IndentationConfigurationprocessIndentHint(de.uni_hildesheim.sse.vil.templatelang.templateLang.IndentationHint hint)Processes an indentation hint and returns the indentation configuration.private JavaExtensionprocessJavaExtension(de.uni_hildesheim.sse.vil.templatelang.templateLang.Extension ext, java.util.Set<java.lang.String> knownTypes, java.util.Set<java.lang.String> knownSignatures)Processes a Java extension.private JavaExtensionprocessJavaExtension(JavaExtension javaExt, java.util.Set<java.lang.String> knownTypes, java.util.Set<java.lang.String> knownSignatures, org.eclipse.emf.ecore.EObject cause, org.eclipse.emf.ecore.EStructuralFeature causingFeature)Processes a Java extension.private voidprocessJavaExtensions(de.uni_hildesheim.sse.vil.templatelang.templateLang.LanguageUnit tpl, TemplateDescriptor desc)Processes the Java extensions.private LoopStatementprocessLoop(de.uni_hildesheim.sse.vil.templatelang.templateLang.Loop loop)Processes a loop expression.private ExpressionprocessSeparatorExpression(de.uni_hildesheim.sse.vil.expressions.expressionDsl.PrimaryExpression ex)Processes a separator expression.private ITemplateElementprocessStatement(de.uni_hildesheim.sse.vil.templatelang.templateLang.Stmt stmt)Processes a statement.private ITemplateElementprocessStatementOrStmtBlock(de.uni_hildesheim.sse.vil.templatelang.templateLang.Stmt stmt, de.uni_hildesheim.sse.vil.templatelang.templateLang.StmtBlock block)Processes an alternative statement or statement block.private SwitchStatementprocessSwitch(de.uni_hildesheim.sse.vil.templatelang.templateLang.Switch swtch)Processes a switch statement.private WhileStatementprocessWhile(de.uni_hildesheim.sse.vil.templatelang.templateLang.While loop)Processes a while statement.protected voidreProcessGlobalVariableDeclarations(Template model)Re-processes global variable declarations to get rid of temporary "function pointer" 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
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
-
-
Method Detail
-
createModel
public Template createModel(de.uni_hildesheim.sse.vil.templatelang.templateLang.LanguageUnit tpl, java.net.URI uri, boolean registerSuccessful, ImportResolver<Template> impResolver)
Creates a build model from a given implementation unit. This is the top-level entry method.- Parameters:
tpl- the language unit to be translateduri- the URI of the project to resolve (in order to find the closest project, may be null)registerSuccessful- successfully created models shall be registeredimpResolver- the import resolver to use (may be null to use a new default import resolver)- Returns:
- the corresponding build model
-
processGlobalVariableDeclarations
protected void processGlobalVariableDeclarations(java.util.List<org.eclipse.emf.ecore.EObject> elts, Template result)Processes the global script variable declarations.- Parameters:
script- the script language unit to be processedresult- the result instance to be modified
-
processIndentHint
private IndentationConfiguration processIndentHint(de.uni_hildesheim.sse.vil.templatelang.templateLang.IndentationHint hint)
Processes an indentation hint and returns the indentation configuration.- Parameters:
hint- the hint- Returns:
- the indentation configuration (may be null if there is no indentation hint)
-
processFormattingHint
private FormattingConfiguration processFormattingHint(de.uni_hildesheim.sse.vil.templatelang.templateLang.FormattingHint hint)
Processes the formatting hint.- Parameters:
hint- the hint to be processed- Returns:
- the related formatting configuration (may be null if there is no formatting hint)
-
reProcessGlobalVariableDeclarations
protected void reProcessGlobalVariableDeclarations(Template model)
Re-processes global variable declarations to get rid of temporary "function pointer" expressions.- Parameters:
model- the model to be processed
-
processJavaExtensions
private void processJavaExtensions(de.uni_hildesheim.sse.vil.templatelang.templateLang.LanguageUnit tpl, TemplateDescriptor desc) throws TranslatorExceptionProcesses the Java extensions.- Parameters:
tpl- the template to be processeddesc- the template descriptor to put the information into- Throws:
TranslatorException- in case that resolving/processing/adding the Java extensions fails
-
processJavaExtension
private JavaExtension processJavaExtension(de.uni_hildesheim.sse.vil.templatelang.templateLang.Extension ext, java.util.Set<java.lang.String> knownTypes, java.util.Set<java.lang.String> knownSignatures) throws TranslatorException
Processes a Java extension.- Parameters:
ext- the extension to be processedknownTypes- known type names (may be modified as a side effect)knownSignatures- known signatures due to Java extensions (may be modified as a side effect)- Returns:
- the Java extension
- Throws:
TranslatorException- in case that resolving/processing/adding the Java extension fails
-
processJavaExtension
private JavaExtension processJavaExtension(JavaExtension javaExt, java.util.Set<java.lang.String> knownTypes, java.util.Set<java.lang.String> knownSignatures, org.eclipse.emf.ecore.EObject cause, org.eclipse.emf.ecore.EStructuralFeature causingFeature) throws TranslatorException
Processes a Java extension.- Parameters:
ext- the extension to be processedknownTypes- known type names (may be modified as a side effect)knownSignatures- known signatures due to Java extensions (may be modified as a side effect)cause- the causing EObjectcausingFeature- the causing language feature- Returns:
- the Java extension
- Throws:
TranslatorException- in case that resolving/processing/adding the Java extension fails
-
getJavaQualifiedNameString
public static java.lang.String getJavaQualifiedNameString(de.uni_hildesheim.sse.vil.templatelang.templateLang.JavaQualifiedName name)
Returns a string representing a qualified name. (May change in future to structured qualified names.)- Parameters:
name- the qualified name- Returns:
- the corresponding string representation
-
getManagementInstance
protected ModelManagement<Template> getManagementInstance()
Returns the management instance.- Specified by:
getManagementInstancein classModelTranslator<Template,VariableDeclaration,Resolver,ExpressionStatement,ExpressionTranslator>- Returns:
- the management instance
-
processDefs
protected void processDefs(java.util.List<org.eclipse.emf.ecore.EObject> elts, Template template)Processes all template defs considering dependencies and terminates with an error if not all can be resolved.- Parameters:
defs- the defs to be processedtemplate- the target template to store the defs in
-
processDef
private Def processDef(de.uni_hildesheim.sse.vil.templatelang.templateLang.VilDef def, Template template) throws TranslatorException
Processes a (sub-)template definition header.- Parameters:
def- the sub-templatetemplate- the target template to store the def in- Returns:
- the model instance
- Throws:
TranslatorException- in case that processing the definition fail
-
processDefBody
private void processDefBody(DefInfo info) throws TranslatorException
Processes a (sub-)template body.- Parameters:
info- the def information object relating Ecore and model instance- Throws:
TranslatorException- in case that processing the definition fail
-
processBlock
private ITemplateElement[] processBlock(de.uni_hildesheim.sse.vil.templatelang.templateLang.StmtBlock block)
Processes a block of rule elements.- Parameters:
block- the block to be resolved- Returns:
- the resolved elements
- Throws:
TranslatorException- in case that the translation fails due to semantic reasons
-
processStatement
private ITemplateElement processStatement(de.uni_hildesheim.sse.vil.templatelang.templateLang.Stmt stmt) throws TranslatorException
Processes a statement.- Parameters:
stmt- the statement to be resolved- Returns:
- the resolved elements
- Throws:
TranslatorException- in case that the translation fails due to semantic reasons
-
processStatementOrStmtBlock
private ITemplateElement processStatementOrStmtBlock(de.uni_hildesheim.sse.vil.templatelang.templateLang.Stmt stmt, de.uni_hildesheim.sse.vil.templatelang.templateLang.StmtBlock block) throws TranslatorException
Processes an alternative statement or statement block.- Parameters:
stmt- the statement (may be null)block- the statement block (may be null)- Returns:
- the respective processed VTL element or null
- Throws:
TranslatorException- in case that the translation fails due to semantic reasons
-
processAlternative
private AlternativeStatement processAlternative(de.uni_hildesheim.sse.vil.templatelang.templateLang.Alternative alt) throws TranslatorException
Processes an alternative statement.- Parameters:
alt- the alternative element from the language- Returns:
- the object representation of the alternative statement
- Throws:
TranslatorException- in case that the translation fails due to semantic reasons
-
processSeparatorExpression
private Expression processSeparatorExpression(de.uni_hildesheim.sse.vil.expressions.expressionDsl.PrimaryExpression ex) throws TranslatorException
Processes a separator expression.- Parameters:
ex- the ECore expression tree- Returns:
- the VIL/VTL expression tree
- Throws:
TranslatorException- in case that the translation fails
-
processWhile
private WhileStatement processWhile(de.uni_hildesheim.sse.vil.templatelang.templateLang.While loop) throws TranslatorException
Processes a while statement.- Parameters:
loop- the ECore loop representation- Returns:
- the VTL while statement
- Throws:
TranslatorException- in case that the translation fails
-
processFlush
private FlushStatement processFlush() throws TranslatorException
Processes a content flush statement.- Returns:
- the VTL flush statement
- Throws:
TranslatorException- in case that the translation fails
-
processLoop
private LoopStatement processLoop(de.uni_hildesheim.sse.vil.templatelang.templateLang.Loop loop) throws TranslatorException
Processes a loop expression.- Parameters:
loop- the loop expression to be processed- Returns:
- the loop object model instance
- Throws:
TranslatorException- in case that the translation fails due to semantic reasons
-
processSwitch
private SwitchStatement processSwitch(de.uni_hildesheim.sse.vil.templatelang.templateLang.Switch swtch) throws TranslatorException
Processes a switch statement.- Parameters:
swtch- the switch statement from the language- Returns:
- the switch object model instance
- Throws:
TranslatorException- in case that the translation fails due to semantic reasons
-
processContent
private ContentStatement processContent(de.uni_hildesheim.sse.vil.templatelang.templateLang.Content content, Resolver resolver) throws TranslatorException
Processes a content statement.- Parameters:
content- the statement- Returns:
- the model object
- Throws:
TranslatorException
-
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 causing feature (as part ofcause)
-
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 causing feature (as part ofcause)
-
createArray
protected VariableDeclaration[] createArray(int len)
Description copied from class:ModelTranslatorCreates an array of .- Specified by:
createArrayin classModelTranslator<Template,VariableDeclaration,Resolver,ExpressionStatement,ExpressionTranslator>- Parameters:
len- the length of the array- Returns:
- the array
-
addVisibleDeclarationsToResolver
protected void addVisibleDeclarationsToResolver(Template 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<Template,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<Template,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<Template,VariableDeclaration,Resolver,ExpressionStatement,ExpressionTranslator>- Parameters:
type- the the compound type- Returns:
- the typedef
- Throws:
VilException
-
-