public class TypeContext extends java.lang.Object implements 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<ContainableModelElementList> |
directContext |
private java.util.Map<IContainableElementsSorter,ContainableElementsMapAndComparator> |
elementSortMaps |
private ContainableModelElementList |
implicitDefinitions |
private MessageReceiver |
messageReceiver |
private Project |
project |
private java.util.Map<Compound,Self> |
selfPool |
private ContainableElementsMapAndComparator |
sortMap |
private java.util.Map<java.lang.String,java.util.List<Compound>> |
unresolvedCompoundRefinements |
private VariablePool |
variablePool |
| Constructor and Description |
|---|
TypeContext(Project project,
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) CustomDatatype |
addImplicitDefinition(CustomDatatype type)
Adds an implicit type definition.
|
void |
addToContext(AttributeAssignment assignment)
Adds an attribute assignment to the current context (layer).
|
void |
addToContext(Compound comp)
Adds a compound to the current context (layer).
|
private void |
addToContext(Compound comp,
java.util.Set<Compound> done)
Adds a compound to the current context (layer).
|
(package private) void |
addToContext(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(DecisionVariableDeclaration var)
Adds a variable declaration to the current context (layer).
|
void |
addToContext(OperationDefinition opDef)
Adds an operation definition to the current context (layer).
|
boolean |
addToProject(org.eclipse.emf.ecore.EObject key,
Comment comment,
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(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(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 ConstantValue |
createConstantValue(org.eclipse.emf.ecore.EObject object,
org.eclipse.emf.ecore.EStructuralFeature feature,
IDatatype type,
java.lang.Object... values)
Creates a constant value.
|
private ConstraintSyntaxTree |
createValueTree(java.lang.String sValue,
IDatatype type,
org.eclipse.emf.ecore.EObject object,
org.eclipse.emf.ecore.EStructuralFeature feature)
Creates a value tree for a given
type. |
private IModelElement |
findActualParent(IModelElement elt)
Returns the actual project or compound the
element is located in. |
Compound[] |
findCompounds(java.util.List<java.lang.String> names,
boolean nullOnFail)
Finds compounds according to the given
names. |
ContainableModelElement |
findElementByName(java.lang.String name,
java.lang.Class<? extends ModelElement> type)
Searches for a specified element.
|
IDatatype |
findRefType(IDatatype contained)
Finds a reference type (declaration or defines an implicit type) for a given contained type.
|
IDatatype |
findType(java.lang.String name,
java.lang.Class<? extends IDatatype> type)
Finds the specified data type definition.
|
AbstractVariable |
findVariable(java.lang.String name,
java.lang.Class<? extends AbstractVariable> type)
Searches for a specified variable.
|
IModelElement |
findVariableUse(java.lang.String name)
Searches for the use of a specified variable (declaration or compound access).
|
ContainableModelElement |
getElement(int index)
Returns a contained model element specified by
index. |
ContainableModelElement |
getElement(java.lang.String name)
Returns a contained model element specified by its
name. |
int |
getElementCount()
Returns the number of contained elements.
|
ProjectImport |
getImport(int index)
Returns the project import specified by
index. |
int |
getImportsCount()
Returns the number of imports.
|
java.lang.String |
getName()
Returns the (unqualified) name of the scope.
|
IModelElement |
getParent()
Returns the parent model element.
|
Project |
getProject()
Returns the project providing the root resolution scope.
|
private Self |
getSelf(Compound comp)
Returns a self instance from the self pool.
|
(package private) java.util.List<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()
Returns whether this scope has interfaces.
|
boolean |
isInterface()
Returns whether this scope is an interfaces.
|
Variable |
obtainVariable(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) 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(IModelElement parent)
Push a resolution layer in case that intermediary variables shell be considered, e.g.
|
int |
pushParent(DecisionVariableDeclaration decVar)
Pushes the enclosing parents of
decVar. |
private int |
pushParentRec(IModelElement elt)
Pushes the enclosing parents of
elt in a recursive manner. |
void |
registerSorter(IContainableElementsSorter sorter,
org.eclipse.emf.ecore.EObject key,
Comment comment,
ContainableModelElement element)
Registers an element to be sorted (later).
|
private ConstraintSyntaxTree |
resolveSelf(IModelElement parent,
org.eclipse.emf.ecore.EObject object,
org.eclipse.emf.ecore.EStructuralFeature feature)
Resolves "self" and returns the corresponding syntax tree (one node).
|
IDatatype |
resolveType(de.uni_hildesheim.sse.ivml.Type type)
Resolves a given type to a type representation in the IVML object model.
|
ConstraintSyntaxTree |
resolveValue(de.uni_hildesheim.sse.ivml.Value value,
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 ContainableModelElementList implicitDefinitions
private Project project
private MessageReceiver messageReceiver
private VariablePool variablePool
private java.util.Stack<ContainableModelElementList> directContext
private ContainableElementsMapAndComparator sortMap
private java.util.Map<IContainableElementsSorter,ContainableElementsMapAndComparator> elementSortMaps
private java.util.Map<java.lang.String,java.util.List<Compound>> unresolvedCompoundRefinements
public TypeContext(Project project, 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(IModelElement parent)
parent - the parent (scope, may be null - in this case the parent scope of the previous
layer is considered)public int pushParent(DecisionVariableDeclaration decVar)
decVar.decVar - the variable to pushprivate int pushParentRec(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(Compound comp)
#pushLayer() before.comp - the compound for which all contained variables shall be addedprivate void addToContext(Compound comp, java.util.Set<Compound> done)
#pushLayer() before.comp - the compound for which all contained variables shall be addeddone - already added compoundspublic void addToContext(AttributeAssignment assignment)
#pushLayer() before.assignment - the assignment for which all contained variables shall be addedvoid addToContext(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<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(OperationDefinition opDef)
#pushLayer() before.opDef - the operation definition which shall be addedpublic void addToContext(DecisionVariableDeclaration var)
#pushLayer() before.var - the decision variable declaration which shall be addedpublic Project getProject()
public final Variable obtainVariable(AbstractVariable decl)
decl - the declarationpublic IDatatype resolveType(de.uni_hildesheim.sse.ivml.Type type) throws TranslatorException
type - the type to be resolvedTranslatorException - in case that the given type cannot be resolvedpublic IDatatype findRefType(IDatatype contained)
contained - the contained typepublic ContainableModelElement findElementByName(java.lang.String name, java.lang.Class<? extends ModelElement> type) throws ModelQueryException
name - the name of the element to search for (may be qualified)type - the specific element to be returnedModelQueryException - in case of semantic problemspublic AbstractVariable findVariable(java.lang.String name, java.lang.Class<? extends AbstractVariable> type) throws 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 nullModelQueryException - in case of semantic problemsprivate IModelElement findActualParent(IModelElement elt)
element is located in.elt - the elementpublic IModelElement findVariableUse(java.lang.String name) throws ModelQueryException
name - the name of the variable to search for (may be qualified)ModelQueryException - in case of semantic problemspublic IDatatype findType(java.lang.String name, java.lang.Class<? extends IDatatype> type) throws 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 nullModelQueryException - in case of semantic problemspublic Compound[] findCompounds(java.util.List<java.lang.String> names, boolean nullOnFail) throws ModelQueryException
names.names - the names of the compoundsnullOnFail - if null shall be returned on failing resolutionnullOnFail,
else an array with null entries)ModelQueryException - in case of semantic problemspublic static boolean allResolved(IDatatype[] types)
types are resolved.types - the types to inspecttrue for all resolved, false for at least one not resolved or
null==typespublic ContainableModelElement getElement(int index)
index.getElement in interface IResolutionScopeindex - a 0-based index specifying the operation to be returnedjava.lang.IndexOutOfBoundsException - if
index<0 || index>=getElementCount()public int getElementCount()
getElementCount in interface IResolutionScopeCustomDatatype addImplicitDefinition(CustomDatatype type)
type - the implicitly defined typetypegetElement(int),
getElementCount()public ConstraintSyntaxTree resolveValue(de.uni_hildesheim.sse.ivml.Value value, IModelElement parent, org.eclipse.emf.ecore.EObject object, org.eclipse.emf.ecore.EStructuralFeature feature) throws 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 forTranslatorException - in case of any translation problemprivate static ConstantValue createConstantValue(org.eclipse.emf.ecore.EObject object, org.eclipse.emf.ecore.EStructuralFeature feature, IDatatype type, java.lang.Object... values) throws 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)TranslatorException - if creating the constant value failsprivate ConstraintSyntaxTree resolveSelf(IModelElement parent, org.eclipse.emf.ecore.EObject object, org.eclipse.emf.ecore.EStructuralFeature feature) throws TranslatorException
parent - the model parentobject - the grammar object this method is called forfeature - the grammar feature this method is called forTranslatorException - in case of any translation problemprivate Self getSelf(Compound comp)
comp - the compond to return the self instance forConstraintSyntaxTree processQValue(java.lang.String sValue, org.eclipse.emf.ecore.EObject object, org.eclipse.emf.ecore.EStructuralFeature feature) throws TranslatorException
sValue - the qualified name as stringobject - the grammar object this method is called forfeature - the grammar feature this method is called forTranslatorException - 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 ConstraintSyntaxTree createValueTree(java.lang.String sValue, IDatatype type, org.eclipse.emf.ecore.EObject object, org.eclipse.emf.ecore.EStructuralFeature feature) throws 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 forTranslatorException - in case of any translation problempublic int getImportsCount()
IResolutionScopegetImportsCount in interface IResolutionScopepublic ProjectImport getImport(int index)
IResolutionScopeindex.getImport in interface IResolutionScopeindex - a 0-based index specifying the import to be returnedpublic IModelElement getParent()
IResolutionScopegetParent in interface IResolutionScopepublic java.lang.String getName()
IResolutionScopegetName in interface IResolutionScopepublic boolean hasInterfaces()
IResolutionScopehasInterfaces in interface IResolutionScopetrue if it has interfaces, false elsepublic boolean isInterface()
IResolutionScopeisInterface in interface IResolutionScopetrue if it is an interface, false elsepublic boolean addToProject(org.eclipse.emf.ecore.EObject key,
Comment comment,
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(IContainableElementsSorter sorter, org.eclipse.emf.ecore.EObject key, Comment comment, 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(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 ContainableModelElement getElement(java.lang.String name)
IResolutionScopename.getElement in interface IResolutionScopename - the qualified or unqualified name to search forCopyright © 2009 - 2018 SSE. All Rights Reserved.