public class TypeContext
extends java.lang.Object
implements net.ssehub.easy.varModel.model.datatypes.IResolutionScope
context.pushLayer();
context.addToContext(...);
try {
// resolve some types or expressions
} catch (TranslatorException e) {
throw e;
} finally {
context.popLayer();
}
Please note that layers must properly be cleared (popLayer()
. Further, a type context provides a resolution scope for its implicit
definitions (without providing interfaces or a name).| Modifier and Type | Field and Description |
|---|---|
private java.util.Stack<net.ssehub.easy.varModel.model.ContainableModelElementList> |
directContext |
private java.util.Map<net.ssehub.easy.varModel.model.datatypes.IContainableElementsSorter,ContainableElementsMapAndComparator> |
elementSortMaps |
private net.ssehub.easy.varModel.model.ContainableModelElementList |
implicitDefinitions |
private net.ssehub.easy.dslCore.translation.MessageReceiver |
messageReceiver |
private net.ssehub.easy.varModel.model.Project |
project |
private java.util.Map<net.ssehub.easy.varModel.model.datatypes.Compound,net.ssehub.easy.varModel.cst.Self> |
selfPool |
private ContainableElementsMapAndComparator |
sortMap |
private java.util.Map<java.lang.String,java.util.List<net.ssehub.easy.varModel.model.datatypes.Compound>> |
unresolvedCompoundRefinements |
private net.ssehub.easy.varModel.cst.VariablePool |
variablePool |
| Constructor and Description |
|---|
TypeContext(net.ssehub.easy.varModel.model.Project project,
net.ssehub.easy.dslCore.translation.MessageReceiver messageReceiver)
Creates a type context for a given project.
|
TypeContext(TypeContext context)
Creates a local type context.
|
| Modifier and Type | Method and Description |
|---|---|
(package private) net.ssehub.easy.varModel.model.datatypes.CustomDatatype |
addImplicitDefinition(net.ssehub.easy.varModel.model.datatypes.CustomDatatype type)
Adds an implicit type definition.
|
void |
addToContext(net.ssehub.easy.varModel.model.AttributeAssignment assignment)
Adds an attribute assignment to the current context (layer).
|
void |
addToContext(net.ssehub.easy.varModel.model.datatypes.Compound comp)
Adds a compound to the current context (layer).
|
private void |
addToContext(net.ssehub.easy.varModel.model.datatypes.Compound comp,
java.util.Set<net.ssehub.easy.varModel.model.datatypes.Compound> done)
Adds a compound to the current context (layer).
|
(package private) void |
addToContext(net.ssehub.easy.varModel.model.datatypes.Compound compound,
java.lang.String unresolvedParentCompound)
Stores a refined compound where the parent/super compound could not be loaded at the current time.
|
void |
addToContext(net.ssehub.easy.varModel.model.DecisionVariableDeclaration var)
Adds a variable declaration to the current context (layer).
|
void |
addToContext(net.ssehub.easy.varModel.model.OperationDefinition opDef)
Adds an operation definition to the current context (layer).
|
boolean |
addToProject(org.eclipse.emf.ecore.EObject key,
net.ssehub.easy.varModel.model.Comment comment,
net.ssehub.easy.varModel.model.ContainableModelElement element)
Adds a containable element to the root resolution scope as well as
a mapping from
key to comment (optional)
and element. |
static boolean |
allResolved(net.ssehub.easy.varModel.model.datatypes.IDatatype[] types)
Returns whether all types in
types are resolved. |
void |
checkEnumOclCompliance(java.lang.String qName,
org.eclipse.emf.ecore.EObject object,
org.eclipse.emf.ecore.EStructuralFeature feature)
Checks a (potentially) qualified enum literal name for OCL compliance if enabled.
|
void |
clear()
Clears this type context (for possible reuse).
|
(package private) void |
clearUnresolvedCompounds(java.lang.String parentCompound)
Clears the list of incomplete compounds, where the parent/super compound of a refinement was missing.
|
void |
closeSorter(net.ssehub.easy.varModel.model.datatypes.IContainableElementsSorter sorter,
java.util.List<org.eclipse.emf.ecore.EObject> elements)
Closes an elements sorter (regarding the stored data) and sorts the elements
within the compound.
|
private static net.ssehub.easy.varModel.cst.ConstantValue |
createConstantValue(org.eclipse.emf.ecore.EObject object,
org.eclipse.emf.ecore.EStructuralFeature feature,
net.ssehub.easy.varModel.model.datatypes.IDatatype type,
java.lang.Object... values)
Creates a constant value.
|
private net.ssehub.easy.varModel.cst.ConstraintSyntaxTree |
createValueTree(java.lang.String sValue,
net.ssehub.easy.varModel.model.datatypes.IDatatype type,
org.eclipse.emf.ecore.EObject object,
org.eclipse.emf.ecore.EStructuralFeature feature)
Creates a value tree for a given
type. |
private net.ssehub.easy.varModel.model.IModelElement |
findActualParent(net.ssehub.easy.varModel.model.IModelElement elt)
Returns the actual project or compound the
element is located in. |
net.ssehub.easy.varModel.model.datatypes.Compound[] |
findCompounds(java.util.List<java.lang.String> names,
boolean nullOnFail)
Finds compounds according to the given
names. |
net.ssehub.easy.varModel.model.ContainableModelElement |
findElementByName(java.lang.String name,
java.lang.Class<? extends net.ssehub.easy.varModel.model.ModelElement> type)
Searches for a specified element.
|
net.ssehub.easy.varModel.model.datatypes.IDatatype |
findRefType(net.ssehub.easy.varModel.model.datatypes.IDatatype contained)
Finds a reference type (declaration or defines an implicit type) for a given contained type.
|
net.ssehub.easy.varModel.model.datatypes.IDatatype |
findType(java.lang.String name,
java.lang.Class<? extends net.ssehub.easy.varModel.model.datatypes.IDatatype> type)
Finds the specified data type definition.
|
net.ssehub.easy.varModel.model.AbstractVariable |
findVariable(java.lang.String name,
java.lang.Class<? extends net.ssehub.easy.varModel.model.AbstractVariable> type)
Searches for a specified variable.
|
net.ssehub.easy.varModel.model.IModelElement |
findVariableUse(java.lang.String name)
Searches for the use of a specified variable (declaration or compound access).
|
net.ssehub.easy.varModel.model.ContainableModelElement |
getElement(int index)
Returns a contained model element specified by
index. |
net.ssehub.easy.varModel.model.ContainableModelElement |
getElement(java.lang.String name) |
int |
getElementCount()
Returns the number of contained elements.
|
net.ssehub.easy.varModel.model.ProjectImport |
getImport(int index) |
int |
getImportsCount() |
java.lang.String |
getName() |
net.ssehub.easy.varModel.model.IModelElement |
getParent() |
net.ssehub.easy.varModel.model.Project |
getProject()
Returns the project providing the root resolution scope.
|
private net.ssehub.easy.varModel.cst.Self |
getSelf(net.ssehub.easy.varModel.model.datatypes.Compound comp)
Returns a self instance from the self pool.
|
(package private) java.util.List<net.ssehub.easy.varModel.model.datatypes.Compound> |
getUnresolvedCompoundRefinments(java.lang.String parentCompound)
Returns a list of compounds where the given compound was specified as a super/parent compound, but could not be
set, as it was not available during parsing the child compound.
|
boolean |
hasInterfaces() |
boolean |
isInterface() |
net.ssehub.easy.varModel.cst.Variable |
obtainVariable(net.ssehub.easy.varModel.model.AbstractVariable decl)
Obtains a CTS variable node for a given variable declaration, i.e., creates it
or returns it from the variable pool of this context.
|
void |
popLayer()
Pop a resolution layer in case that intermediary variables shell be considered, e.g.
|
void |
popLayer(int count)
Pops
count layers. |
(package private) net.ssehub.easy.varModel.cst.ConstraintSyntaxTree |
processQValue(java.lang.String sValue,
org.eclipse.emf.ecore.EObject object,
org.eclipse.emf.ecore.EStructuralFeature feature)
Processes a qualified name as value.
|
void |
pushLayer(net.ssehub.easy.varModel.model.IModelElement parent)
Push a resolution layer in case that intermediary variables shell be considered, e.g.
|
int |
pushParent(net.ssehub.easy.varModel.model.DecisionVariableDeclaration decVar)
Pushes the enclosing parents of
decVar. |
private int |
pushParentRec(net.ssehub.easy.varModel.model.IModelElement elt)
Pushes the enclosing parents of
elt in a recursive manner. |
void |
registerSorter(net.ssehub.easy.varModel.model.datatypes.IContainableElementsSorter sorter,
org.eclipse.emf.ecore.EObject key,
net.ssehub.easy.varModel.model.Comment comment,
net.ssehub.easy.varModel.model.ContainableModelElement element)
Registers an element to be sorted (later).
|
private net.ssehub.easy.varModel.cst.ConstraintSyntaxTree |
resolveSelf(net.ssehub.easy.varModel.model.IModelElement parent,
org.eclipse.emf.ecore.EObject object,
org.eclipse.emf.ecore.EStructuralFeature feature)
Resolves "self" and returns the corresponding syntax tree (one node).
|
net.ssehub.easy.varModel.model.datatypes.IDatatype |
resolveType(Type type)
Resolves a given type to a type representation in the IVML object model.
|
net.ssehub.easy.varModel.cst.ConstraintSyntaxTree |
resolveValue(Value value,
net.ssehub.easy.varModel.model.IModelElement parent,
org.eclipse.emf.ecore.EObject object,
org.eclipse.emf.ecore.EStructuralFeature feature)
Resolves a value and returns the corresponding syntax tree (one node).
|
private static void |
setIndexes(java.util.List<org.eclipse.emf.ecore.EObject> elements,
ContainableElementsMapAndComparator map)
Transfers the index positions of
elements to map. |
void |
sortProjectElements(java.util.List<org.eclipse.emf.ecore.EObject> topLevelElements)
Sorts the elements in the root resolution scope according to the
the given list of top-level elements.
|
private net.ssehub.easy.varModel.model.ContainableModelElementList implicitDefinitions
private net.ssehub.easy.varModel.model.Project project
private net.ssehub.easy.dslCore.translation.MessageReceiver messageReceiver
private net.ssehub.easy.varModel.cst.VariablePool variablePool
private java.util.Map<net.ssehub.easy.varModel.model.datatypes.Compound,net.ssehub.easy.varModel.cst.Self> selfPool
private java.util.Stack<net.ssehub.easy.varModel.model.ContainableModelElementList> directContext
private ContainableElementsMapAndComparator sortMap
private java.util.Map<net.ssehub.easy.varModel.model.datatypes.IContainableElementsSorter,ContainableElementsMapAndComparator> elementSortMaps
private java.util.Map<java.lang.String,java.util.List<net.ssehub.easy.varModel.model.datatypes.Compound>> unresolvedCompoundRefinements
public TypeContext(net.ssehub.easy.varModel.model.Project project,
net.ssehub.easy.dslCore.translation.MessageReceiver messageReceiver)
project - the project representing the root resolution scope of this type contextmessageReceiver - instance for receiving, storing and passing messages to Eclipsepublic TypeContext(TypeContext context)
context - the global type context to take basic information frompublic void pushLayer(net.ssehub.easy.varModel.model.IModelElement parent)
parent - the parent (scope, may be null - in this case the parent scope of the previous
layer is considered)public int pushParent(net.ssehub.easy.varModel.model.DecisionVariableDeclaration decVar)
decVar.decVar - the variable to pushprivate int pushParentRec(net.ssehub.easy.varModel.model.IModelElement elt)
elt in a recursive manner.elt - the element to push the parents forpublic void popLayer(int count)
count layers.count - the amount of layers to poppushParent(DecisionVariableDeclaration)public void popLayer()
public void addToContext(net.ssehub.easy.varModel.model.datatypes.Compound comp)
#pushLayer() before.comp - the compound for which all contained variables shall be addedprivate void addToContext(net.ssehub.easy.varModel.model.datatypes.Compound comp,
java.util.Set<net.ssehub.easy.varModel.model.datatypes.Compound> done)
#pushLayer() before.comp - the compound for which all contained variables shall be addeddone - already added compoundspublic void addToContext(net.ssehub.easy.varModel.model.AttributeAssignment assignment)
#pushLayer() before.assignment - the assignment for which all contained variables shall be addedvoid addToContext(net.ssehub.easy.varModel.model.datatypes.Compound compound,
java.lang.String unresolvedParentCompound)
compound - A refined compound where the super compound was not set so far (i.e. is set to null).unresolvedParentCompound - The name of the super/parent compound, which was not found so far.java.util.List<net.ssehub.easy.varModel.model.datatypes.Compound> getUnresolvedCompoundRefinments(java.lang.String parentCompound)
parentCompound - The parent/super compound of a refinement.void clearUnresolvedCompounds(java.lang.String parentCompound)
parentCompound - The name of the super/parent compound.public void addToContext(net.ssehub.easy.varModel.model.OperationDefinition opDef)
#pushLayer() before.opDef - the operation definition which shall be addedpublic void addToContext(net.ssehub.easy.varModel.model.DecisionVariableDeclaration var)
#pushLayer() before.var - the decision variable declaration which shall be addedpublic net.ssehub.easy.varModel.model.Project getProject()
public final net.ssehub.easy.varModel.cst.Variable obtainVariable(net.ssehub.easy.varModel.model.AbstractVariable decl)
decl - the declarationpublic net.ssehub.easy.varModel.model.datatypes.IDatatype resolveType(Type type)
throws net.ssehub.easy.dslCore.translation.TranslatorException
type - the type to be resolvednet.ssehub.easy.dslCore.translation.TranslatorException - in case that the given type cannot be resolvedpublic net.ssehub.easy.varModel.model.datatypes.IDatatype findRefType(net.ssehub.easy.varModel.model.datatypes.IDatatype contained)
contained - the contained typepublic net.ssehub.easy.varModel.model.ContainableModelElement findElementByName(java.lang.String name,
java.lang.Class<? extends net.ssehub.easy.varModel.model.ModelElement> type)
throws net.ssehub.easy.varModel.model.ModelQueryException
name - the name of the element to search for (may be qualified)type - the specific element to be returnednet.ssehub.easy.varModel.model.ModelQueryException - in case of semantic problemspublic net.ssehub.easy.varModel.model.AbstractVariable findVariable(java.lang.String name,
java.lang.Class<? extends net.ssehub.easy.varModel.model.AbstractVariable> type)
throws net.ssehub.easy.varModel.model.ModelQueryException
name - the name of the variable to search for (may be qualified)type - the specific variable of datatype to be returned,
AbstractVariable is used if nullnet.ssehub.easy.varModel.model.ModelQueryException - in case of semantic problemsprivate net.ssehub.easy.varModel.model.IModelElement findActualParent(net.ssehub.easy.varModel.model.IModelElement elt)
element is located in.elt - the elementpublic net.ssehub.easy.varModel.model.IModelElement findVariableUse(java.lang.String name)
throws net.ssehub.easy.varModel.model.ModelQueryException
name - the name of the variable to search for (may be qualified)net.ssehub.easy.varModel.model.ModelQueryException - in case of semantic problemspublic net.ssehub.easy.varModel.model.datatypes.IDatatype findType(java.lang.String name,
java.lang.Class<? extends net.ssehub.easy.varModel.model.datatypes.IDatatype> type)
throws net.ssehub.easy.varModel.model.ModelQueryException
name - the name of the type to search for (may be qualified)type - the specific type of datatype to be returned,
IDatatype is used if nullnet.ssehub.easy.varModel.model.ModelQueryException - in case of semantic problemspublic net.ssehub.easy.varModel.model.datatypes.Compound[] findCompounds(java.util.List<java.lang.String> names,
boolean nullOnFail)
throws net.ssehub.easy.varModel.model.ModelQueryException
names.names - the names of the compoundsnullOnFail - if null shall be returned on failing resolutionnullOnFail,
else an array with null entries)net.ssehub.easy.varModel.model.ModelQueryException - in case of semantic problemspublic static boolean allResolved(net.ssehub.easy.varModel.model.datatypes.IDatatype[] types)
types are resolved.types - the types to inspecttrue for all resolved, false for at least one not resolved or
null==typespublic net.ssehub.easy.varModel.model.ContainableModelElement getElement(int index)
index.getElement in interface net.ssehub.easy.varModel.model.datatypes.IResolutionScopeindex - a 0-based index specifying the operation to be returnedjava.lang.IndexOutOfBoundsException - if
index<0 || index>=getElementCount()public int getElementCount()
getElementCount in interface net.ssehub.easy.varModel.model.datatypes.IResolutionScopenet.ssehub.easy.varModel.model.datatypes.CustomDatatype addImplicitDefinition(net.ssehub.easy.varModel.model.datatypes.CustomDatatype type)
type - the implicitly defined typetypegetElement(int),
getElementCount()public net.ssehub.easy.varModel.cst.ConstraintSyntaxTree resolveValue(Value value,
net.ssehub.easy.varModel.model.IModelElement parent,
org.eclipse.emf.ecore.EObject object,
org.eclipse.emf.ecore.EStructuralFeature feature)
throws net.ssehub.easy.dslCore.translation.TranslatorException
value - the value to be convertedparent - the model parentobject - the grammar object this method is called forfeature - the grammar feature this method is called fornet.ssehub.easy.dslCore.translation.TranslatorException - in case of any translation problemprivate static net.ssehub.easy.varModel.cst.ConstantValue createConstantValue(org.eclipse.emf.ecore.EObject object,
org.eclipse.emf.ecore.EStructuralFeature feature,
net.ssehub.easy.varModel.model.datatypes.IDatatype type,
java.lang.Object... values)
throws net.ssehub.easy.dslCore.translation.TranslatorException
object - the grammar object this method is called forfeature - the grammar feature this method is called fortype - the type to create the value forvalues - the actual value(s) (may be null)net.ssehub.easy.dslCore.translation.TranslatorException - if creating the constant value failsprivate net.ssehub.easy.varModel.cst.ConstraintSyntaxTree resolveSelf(net.ssehub.easy.varModel.model.IModelElement parent,
org.eclipse.emf.ecore.EObject object,
org.eclipse.emf.ecore.EStructuralFeature feature)
throws net.ssehub.easy.dslCore.translation.TranslatorException
parent - the model parentobject - the grammar object this method is called forfeature - the grammar feature this method is called fornet.ssehub.easy.dslCore.translation.TranslatorException - in case of any translation problemprivate net.ssehub.easy.varModel.cst.Self getSelf(net.ssehub.easy.varModel.model.datatypes.Compound comp)
comp - the compond to return the self instance fornet.ssehub.easy.varModel.cst.ConstraintSyntaxTree processQValue(java.lang.String sValue,
org.eclipse.emf.ecore.EObject object,
org.eclipse.emf.ecore.EStructuralFeature feature)
throws net.ssehub.easy.dslCore.translation.TranslatorException
sValue - the qualified name as stringobject - the grammar object this method is called forfeature - the grammar feature this method is called fornet.ssehub.easy.dslCore.translation.TranslatorException - in case of any translation problempublic void checkEnumOclCompliance(java.lang.String qName,
org.eclipse.emf.ecore.EObject object,
org.eclipse.emf.ecore.EStructuralFeature feature)
qName - the qualified nameobject - the grammar object this method is called forfeature - the grammar feature this method is called forprivate net.ssehub.easy.varModel.cst.ConstraintSyntaxTree createValueTree(java.lang.String sValue,
net.ssehub.easy.varModel.model.datatypes.IDatatype type,
org.eclipse.emf.ecore.EObject object,
org.eclipse.emf.ecore.EStructuralFeature feature)
throws net.ssehub.easy.dslCore.translation.TranslatorException
type.sValue - the string representation of the valuetype - the target typeobject - the grammar object this method is called forfeature - the grammar feature this method is called fornet.ssehub.easy.dslCore.translation.TranslatorException - in case of any translation problempublic int getImportsCount()
getImportsCount in interface net.ssehub.easy.varModel.model.datatypes.IResolutionScopepublic net.ssehub.easy.varModel.model.ProjectImport getImport(int index)
getImport in interface net.ssehub.easy.varModel.model.datatypes.IResolutionScopepublic net.ssehub.easy.varModel.model.IModelElement getParent()
getParent in interface net.ssehub.easy.varModel.model.datatypes.IResolutionScopepublic java.lang.String getName()
getName in interface net.ssehub.easy.varModel.model.datatypes.IResolutionScopepublic boolean hasInterfaces()
hasInterfaces in interface net.ssehub.easy.varModel.model.datatypes.IResolutionScopepublic boolean isInterface()
isInterface in interface net.ssehub.easy.varModel.model.datatypes.IResolutionScopepublic boolean addToProject(org.eclipse.emf.ecore.EObject key,
net.ssehub.easy.varModel.model.Comment comment,
net.ssehub.easy.varModel.model.ContainableModelElement element)
key to comment (optional)
and element.key - the key object as parsed by xText from the input file (may
be null then no mapping is added, e.g. when adding a comment only)comment - the comment instance (may be null)element - the element instancetrue if the addition was successful,
false else due to duplicated namesContainableElementsMapAndComparator.put(EObject, Comment, ContainableModelElement)public void sortProjectElements(java.util.List<org.eclipse.emf.ecore.EObject> topLevelElements)
topLevelElements - the top-level elements from the grammarprivate static void setIndexes(java.util.List<org.eclipse.emf.ecore.EObject> elements,
ContainableElementsMapAndComparator map)
elements to map.elements - the list representing the positionsmap - the target map to set the values topublic void registerSorter(net.ssehub.easy.varModel.model.datatypes.IContainableElementsSorter sorter,
org.eclipse.emf.ecore.EObject key,
net.ssehub.easy.varModel.model.Comment comment,
net.ssehub.easy.varModel.model.ContainableModelElement element)
sorter - the element being sorted laterkey - the key object as parsed by xText from the input file (may
be null then no mapping is added, e.g. when adding a comment only)comment - the comment instance (may be null)element - the element instancepublic void closeSorter(net.ssehub.easy.varModel.model.datatypes.IContainableElementsSorter sorter,
java.util.List<org.eclipse.emf.ecore.EObject> elements)
sorter - the element being sortedelements - the grammar elements within the compound defining the sort orderpublic void clear()
public net.ssehub.easy.varModel.model.ContainableModelElement getElement(java.lang.String name)
getElement in interface net.ssehub.easy.varModel.model.datatypes.IResolutionScopeCopyright © 2009 - 2018 SSE. All Rights Reserved.