Package net.ssehub.easy.varModel.model
Class ModelQuery
- java.lang.Object
-
- net.ssehub.easy.varModel.model.ModelQuery
-
- Direct Known Subclasses:
IvmlModelQuery
public class ModelQuery extends java.lang.ObjectProvides an interface to query models.- Author:
- Holger Eichelberger
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classModelQuery.FirstDeclTypeSelectorSelects the first declaration with the given type.static interfaceModelQuery.IDeclarationSelectorDefines the interface of a declaration selector.private static classModelQuery.IncrementalNamespaceRepresents an incrementally resolved namespace.private static classModelQuery.MqDatatypeVisitorA private quick datatype visitor.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringMQ_SHORT_REFERENCEstatic java.lang.StringMQ_SHORT_SEQUENCEstatic java.lang.StringMQ_SHORT_SETprivate static QualifiedNameModeTYPE_SEARCH_MODEprivate static java.util.List<ModelQuery.MqDatatypeVisitor>VIS_INSTANCES
-
Constructor Summary
Constructors Constructor Description ModelQuery()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static ContainableModelElementcheckElement(ContainableModelElement element, java.lang.String name, java.lang.Class<?> type)Checks a containable model element.private static IResolutionScopecheckInterfaceImport(IResolutionScope scope, ModelQuery.IncrementalNamespace ispace, java.lang.String namespace, IResolutionScope project)Performs final checks on accessing an imported interface.private static booleancheckScopeForImport(java.lang.String name, ProjectImport imp, java.lang.String namespace)Check the validity of the scope being imported.static ValueenumLiteralAsValue(IResolutionScope elements, java.lang.String name)Finds a referenced enum literal inproject.static AttributefindAttribute(IModelElement scope, java.lang.String name)Finds an attribute withinscopeor enclosing parentscopes, i.e., search in inverted direction along attribute application/inheritance.private static IModelElementfindCompoundOrAttributeAccess(IResolutionScope elements, java.lang.String name, java.lang.String innerName, IModelElement result)Finds a variable by compound/attribute access as part offindVariable(IResolutionScope, String, Class).static DecisionVariableDeclarationfindDeclaration(IResolutionScope scope, ModelQuery.IDeclarationSelector selector)Searches a givenscopefor a variable declaration oftypeand returns the declaration determined byselector.static ContainableModelElementfindElementByName(IResolutionScope elements, java.lang.String name, java.lang.Class<?> type)Finds an element by its given name inelements.private static ContainableModelElementfindElementByName(IResolutionScope elements, java.lang.String name, java.lang.Class<?> type, java.util.Set<IResolutionScope> done)Finds an element by its given name inelements.static IDatatypefindElementByTypeName(IResolutionScope elements, java.lang.String typeName, java.lang.Class<? extends IDatatype> type)Finds the specified data type definition in the givenelements.static IDatatypefindElementByTypeName(IResolutionScope elements, java.lang.String typeName, java.lang.Class<? extends IDatatype> type, java.util.Set<IResolutionScope> done)Finds the specified data type definition in the givenelements.static IDatatypefindElementByTypeName(IDecisionVariableContainer container, java.lang.String typeName)Finds the specified data type definition in the givencontainer.static EnumfindEnum(IResolutionScope elements, java.lang.String name)Finds a referenced enum literal inproject.static ProjectfindProject(Project project, java.lang.String name)Finds a project with given name.private static ProjectfindProject(Project project, java.lang.String name, java.lang.String path, java.util.Set<Project> done)Finds a project with given name.static java.util.List<Compound>findRefining(IResolutionScope scope, Compound compound)Returns all (reachable) compounds (transitively) refining the givencompoundstarting atscopealso considering imported scopes.private static voidfindRefining(IResolutionScope scope, Compound compound, java.util.List<Compound> result, java.util.Set<IResolutionScope> done)Returns all (reachable) compounds (transitively) refining the givencompoundstarting atscopealso considering imported scopes.private static IDatatypefindType(IResolutionScope elements, java.lang.String name, boolean considerVariableDeclarations, java.lang.Class<? extends IDatatype> type, java.util.Set<IResolutionScope> done)Finds the specified data type definition in the givenproject.static IDatatypefindType(IResolutionScope elements, java.lang.String name, java.lang.Class<? extends IDatatype> type)Finds the specified data type definition in the givenproject.private static AbstractVariablefindVariable(Compound compound, java.lang.String name)Searches for a variable ofnamein a givencompound.static AbstractVariablefindVariable(IResolutionScope elements, java.lang.String name, java.lang.Class<? extends AbstractVariable> type)Searches for a specified variable.static IModelElementfindVariableUse(IResolutionScope elements, java.lang.String name, java.lang.Class<?> type)Searches for a specified variable or variable use.private static IModelElementfindVariableUse(IResolutionScope elements, java.lang.String name, java.lang.Class<?> type, java.util.Set<IResolutionScope> done)Searches for a specified variable or variable use.static java.util.List<Attribute>getAllAttributes(IResolutionScope scope)Returns all attributes inscope.private static voidgetAllAttributes(IResolutionScope scope, java.util.List<Attribute> attributes, java.util.Set<IResolutionScope> done)Collects all attributes inscopeand imported scopes.private static AbstractVariablegetAttribute(IAttributableElement element, java.lang.String name)Finds an attribute withnameonelement.private static ModelQuery.MqDatatypeVisitorgetDatatypeVisitorInstance(QualifiedNameMode mode)Returns a pooled datatype visitor instance.static java.util.List<SearchResult>getElementsByNamePrefix(ModelElement element, java.lang.String namePrefix, DatatypeVisitor datatypeVisitor, SearchContext context, java.lang.Class<?>... restrictions)Searches a given set of elements by a name prefix starting atelement.private static IResolutionScopegetImportedScope(IResolutionScope scope, java.lang.String namespace)Returns the current scope due to imports.static java.lang.StringgetReferenceTypeSearchName(IDatatype type)Returns the name to be used for searching for a reference with contained typetype.private static IResolutionScopegetScope(IResolutionScope scope, java.lang.String name)Returns the resolution scope determined by the qualifiednamerelative to the givenscope.private static java.lang.StringgetType(ContainableModelElement element, QualifiedNameMode mode)Returns the textual representation of the given element.private static java.lang.StringgetType(IDatatype type, QualifiedNameMode mode)Returns the textual representation of the given type.private static voidreleaseDatatypeVisitor(ModelQuery.MqDatatypeVisitor vis)Releases a datatype visitor instance.private static java.lang.StringremoveNamespace(java.lang.String name)Removes a namespace prefix fromname.private static ProjectsearchImportedProject(java.lang.String namespace, IResolutionScope scope, java.util.Set<Project> done)Searches for an indirectly imported project in depth-first search.
-
-
-
Field Detail
-
MQ_SHORT_SET
public static final java.lang.String MQ_SHORT_SET
- See Also:
- Constant Field Values
-
MQ_SHORT_SEQUENCE
public static final java.lang.String MQ_SHORT_SEQUENCE
- See Also:
- Constant Field Values
-
MQ_SHORT_REFERENCE
public static final java.lang.String MQ_SHORT_REFERENCE
- See Also:
- Constant Field Values
-
TYPE_SEARCH_MODE
private static final QualifiedNameMode TYPE_SEARCH_MODE
-
VIS_INSTANCES
private static final java.util.List<ModelQuery.MqDatatypeVisitor> VIS_INSTANCES
-
-
Method Detail
-
getDatatypeVisitorInstance
private static final ModelQuery.MqDatatypeVisitor getDatatypeVisitorInstance(QualifiedNameMode mode)
Returns a pooled datatype visitor instance.- Parameters:
mode- the name mode- Returns:
- the visitor instance
- See Also:
releaseDatatypeVisitor(net.ssehub.easy.varModel.model.ModelQuery.MqDatatypeVisitor)
-
releaseDatatypeVisitor
private static final void releaseDatatypeVisitor(ModelQuery.MqDatatypeVisitor vis)
Releases a datatype visitor instance.- Parameters:
vis- the instance to be released
-
getType
private static final java.lang.String getType(ContainableModelElement element, QualifiedNameMode mode)
Returns the textual representation of the given element.- Parameters:
element- the element to be representedmode- the name mode- Returns:
- the textual representation
-
getType
private static final java.lang.String getType(IDatatype type, QualifiedNameMode mode)
Returns the textual representation of the given type.- Parameters:
type- the type to be representedmode- the name mode- Returns:
- the textual representation
-
getReferenceTypeSearchName
public static final java.lang.String getReferenceTypeSearchName(IDatatype type)
Returns the name to be used for searching for a reference with contained typetype.- Parameters:
type- the contained type- Returns:
- the search name
-
findRefining
public static java.util.List<Compound> findRefining(IResolutionScope scope, Compound compound)
Returns all (reachable) compounds (transitively) refining the givencompoundstarting atscopealso considering imported scopes.- Parameters:
scope- the scope to search the refining compounds withincompound- the compound that must be part of the refinement hierarchy of all result compounds- Returns:
- the refining compounds, may be empty
-
findRefining
private static void findRefining(IResolutionScope scope, Compound compound, java.util.List<Compound> result, java.util.Set<IResolutionScope> done)
Returns all (reachable) compounds (transitively) refining the givencompoundstarting atscopealso considering imported scopes. [initial implementation]- Parameters:
scope- the scope to search the refining compounds withincompound- the compound that must be part of the refinement hierarchy of all result compoundsresult- the list of refining result compounds (modified as a side effect)done- already processed scopes to prevent import circles
-
findProject
public static Project findProject(Project project, java.lang.String name)
Finds a project with given name.- Parameters:
project- the project to start the search at (including imports)name- the name to search for- Returns:
- the found project or null if there is none
-
findProject
private static Project findProject(Project project, java.lang.String name, java.lang.String path, java.util.Set<Project> done)
Finds a project with given name.- Parameters:
project- the project to start the search at (including imports)name- the name to search forpath- the current qualified search pathdone- already processed projects- Returns:
- the found project or null if there is none
-
findType
public static IDatatype findType(IResolutionScope elements, java.lang.String name, java.lang.Class<? extends IDatatype> type) throws ModelQueryException
Finds the specified data type definition in the givenproject.- Parameters:
elements- the elements to search forname- the name of the type to search for (may be qualified)type- the specific type of datatype to be returned,IDatatypeis used if null- Returns:
- the corresponding type or null
- Throws:
ModelQueryException- in case of violated project access restrictions- See Also:
#findType(IResolutionScope, String, boolean, Class)
-
findType
private static IDatatype findType(IResolutionScope elements, java.lang.String name, boolean considerVariableDeclarations, java.lang.Class<? extends IDatatype> type, java.util.Set<IResolutionScope> done) throws ModelQueryException
Finds the specified data type definition in the givenproject.- Parameters:
elements- the elements to search forname- the name of the type to search for (may be qualified)considerVariableDeclarations- take the types of variable declarations into accounttype- the specific type of datatype to be returned,IDatatypeis used if nulldone- already done resolution scopes- Returns:
- the corresponding type or null
- Throws:
ModelQueryException- in case of violated project access restrictions
-
findElementByTypeName
public static IDatatype findElementByTypeName(IResolutionScope elements, java.lang.String typeName, java.lang.Class<? extends IDatatype> type) throws ModelQueryException
Finds the specified data type definition in the givenelements.- Parameters:
elements- the elements to search fortypeName- the name of the type to search for (may be qualified)type- the specific type of datatype to be returned,IDatatypeis used if null- Returns:
- the corresponding type or null
- Throws:
ModelQueryException- in case of violated project access restrictions
-
findElementByTypeName
public static IDatatype findElementByTypeName(IResolutionScope elements, java.lang.String typeName, java.lang.Class<? extends IDatatype> type, java.util.Set<IResolutionScope> done) throws ModelQueryException
Finds the specified data type definition in the givenelements.- Parameters:
elements- the elements to search fortypeName- the name of the type to search for (may be qualified)type- the specific type of datatype to be returned,IDatatypeis used if nulldone- the already processed resolution scopes- Returns:
- the corresponding type or null
- Throws:
ModelQueryException- in case of violated project access restrictions
-
findElementByTypeName
public static IDatatype findElementByTypeName(IDecisionVariableContainer container, java.lang.String typeName) throws ModelQueryException
Finds the specified data type definition in the givencontainer.- Parameters:
container- the container to search fortypeName- the name of the type to search for (may be qualified)- Returns:
- the corresponding type or null
- Throws:
ModelQueryException- in case of violated project access restrictions
-
getScope
private static IResolutionScope getScope(IResolutionScope scope, java.lang.String name) throws ModelQueryException
Returns the resolution scope determined by the qualifiednamerelative to the givenscope.- Parameters:
scope- the scope to start withname- the (qualified) name of the relative scope to return- Returns:
- the relative scope
- Throws:
ModelQueryException- in case of violated project access restrictions
-
getImportedScope
private static IResolutionScope getImportedScope(IResolutionScope scope, java.lang.String namespace) throws ModelQueryException
Returns the current scope due to imports.- Parameters:
scope- the scope to start withnamespace- the namespace of the resulting scope- Returns:
- the relative scope
- Throws:
ModelQueryException- in case of violated project access restrictions
-
searchImportedProject
private static Project searchImportedProject(java.lang.String namespace, IResolutionScope scope, java.util.Set<Project> done)
Searches for an indirectly imported project in depth-first search.- Parameters:
namespace- the namespace to search forscope- the scope to search withindone- already visited projects (avoid cycles)- Returns:
- the project matching the namespace or null
-
checkInterfaceImport
private static IResolutionScope checkInterfaceImport(IResolutionScope scope, ModelQuery.IncrementalNamespace ispace, java.lang.String namespace, IResolutionScope project) throws ModelQueryException
Performs final checks on accessing an imported interface.- Parameters:
scope- the scope containing the interface being imported (may be null)ispace- the current state in resolving the namespacenamespace- the initial namespace (for error messages)project- the containing project- Returns:
scope- Throws:
ModelQueryException- in case of interface access errors, i.e.scopedoes not contain the expected/specified interface inispace
-
checkScopeForImport
private static boolean checkScopeForImport(java.lang.String name, ProjectImport imp, java.lang.String namespace) throws ModelQueryExceptionCheck the validity of the scope being imported.- Parameters:
name- the name of the element being importedimp- the import model elementnamespace- the total namespace being accessed- Returns:
trueif the scope matches the import,falseelse- Throws:
ModelQueryException- in case of illegal accesses
-
removeNamespace
private static java.lang.String removeNamespace(java.lang.String name)
Removes a namespace prefix fromname.- Parameters:
name- the name to remove the namespace from- Returns:
- the stripped name (or
nameifnamedoes not contain a namespace prefix)
-
findVariable
public static AbstractVariable findVariable(IResolutionScope elements, java.lang.String name, java.lang.Class<? extends AbstractVariable> type) throws ModelQueryException
Searches for a specified variable.- Parameters:
elements- the elements to search forname- the name of the variable to search for (may be qualified)type- the specific variable of datatype to be returned,AbstractVariableis used if null- Returns:
- the corresponding variable or null
- Throws:
ModelQueryException- in case of ambiguities
-
findVariableUse
public static IModelElement findVariableUse(IResolutionScope elements, java.lang.String name, java.lang.Class<?> type) throws ModelQueryException
Searches for a specified variable or variable use.- Parameters:
elements- the elements to search forname- the name of the variable to search for (may be qualified)type- the specific variable of datatype to be returned,AbstractVariableis used if null- Returns:
- the corresponding variable or
CompoundAccessStatement, null else - Throws:
ModelQueryException- in case of ambiguities
-
findVariableUse
private static IModelElement findVariableUse(IResolutionScope elements, java.lang.String name, java.lang.Class<?> type, java.util.Set<IResolutionScope> done) throws ModelQueryException
Searches for a specified variable or variable use.- Parameters:
elements- the elements to search forname- the name of the variable to search for (may be qualified)type- the specific variable of datatype to be returned,AbstractVariableis used if nulldone- already processed scopes- Returns:
- the corresponding variable or
CompoundAccessStatement, null else - Throws:
ModelQueryException- in case of ambiguities
-
findCompoundOrAttributeAccess
private static IModelElement findCompoundOrAttributeAccess(IResolutionScope elements, java.lang.String name, java.lang.String innerName, IModelElement result) throws ModelQueryException
Finds a variable by compound/attribute access as part offindVariable(IResolutionScope, String, Class).- Parameters:
elements- the elements to search forname- the name of the variable to search forinnerName- the name of the compound element/attributeresult- the result determined so far- Returns:
- the subsequent compound, compound access or attribute access
- Throws:
ModelQueryException- in case of ambiguities
-
getAttribute
private static AbstractVariable getAttribute(IAttributableElement element, java.lang.String name)
Finds an attribute withnameonelement.- Parameters:
element- the attributable elementname- the name of the attribute to search for- Returns:
- the attribute or null if none was found
-
findVariable
private static AbstractVariable findVariable(Compound compound, java.lang.String name)
Searches for a variable ofnamein a givencompound. This method takes refined compounds (super compounds) into account.- Parameters:
compound- the compound to search forname- the name of the variable to search for (may be qualified)- Returns:
- the variable or null
-
findElementByName
public static ContainableModelElement findElementByName(IResolutionScope elements, java.lang.String name, java.lang.Class<?> type) throws ModelQueryException
Finds an element by its given name inelements.- Parameters:
elements- the elements to search forname- the name of the element to search fortype- the specific type of element to be returned- Returns:
- the found element or null
- Throws:
ModelQueryException- in case of violated project access restrictions
-
findElementByName
private static ContainableModelElement findElementByName(IResolutionScope elements, java.lang.String name, java.lang.Class<?> type, java.util.Set<IResolutionScope> done) throws ModelQueryException
Finds an element by its given name inelements.- Parameters:
elements- the elements to search forname- the name of the element to search fortype- the specific type of element to be returneddone- already processed resolution scopes- Returns:
- the found element or null
- Throws:
ModelQueryException- in case of violated project access restrictions
-
checkElement
private static ContainableModelElement checkElement(ContainableModelElement element, java.lang.String name, java.lang.Class<?> type)
Checks a containable model element.- Parameters:
element- the element to checkname- the name to check fortype- the specific type of element to be returned- Returns:
elementif found or null
-
findEnum
public static Enum findEnum(IResolutionScope elements, java.lang.String name) throws ModelQueryException
Finds a referenced enum literal inproject.- Parameters:
elements- the elements to search forname- the name (may be qualified)- Returns:
- the found literal or null if not found
- Throws:
ModelQueryException- in case of project access restriction violations
-
enumLiteralAsValue
public static Value enumLiteralAsValue(IResolutionScope elements, java.lang.String name) throws IvmlException, ModelQueryException
Finds a referenced enum literal inproject.- Parameters:
elements- the elements to search forname- the name (may be qualified)- Returns:
- the found literal as value or null if not found
- Throws:
IvmlException- in case of type compliance problems when creating the valueModelQueryException- in case of project access restriction violations
-
getElementsByNamePrefix
public static java.util.List<SearchResult> getElementsByNamePrefix(ModelElement element, java.lang.String namePrefix, DatatypeVisitor datatypeVisitor, SearchContext context, java.lang.Class<?>... restrictions)
Searches a given set of elements by a name prefix starting atelement.- Parameters:
element- the element to start searching atnamePrefix- the name prefixdatatypeVisitor- a visitor for resolving type namescontext- additional information to include or exclude locally defined model elementsrestrictions- type restrictions on the elements to include into the search- Returns:
- the search results
-
getAllAttributes
public static java.util.List<Attribute> getAllAttributes(IResolutionScope scope)
Returns all attributes inscope.- Parameters:
scope- the scope to be searched- Returns:
- the attributes in
scope, may be empty
-
getAllAttributes
private static void getAllAttributes(IResolutionScope scope, java.util.List<Attribute> attributes, java.util.Set<IResolutionScope> done)
Collects all attributes inscopeand imported scopes.- Parameters:
scope- the scope to be considered for collectingattributes- the contained attributes (modified as a side effect)done- already processed scopes
-
findDeclaration
public static DecisionVariableDeclaration findDeclaration(IResolutionScope scope, ModelQuery.IDeclarationSelector selector)
Searches a givenscopefor a variable declaration oftypeand returns the declaration determined byselector.- Parameters:
scope- the scope to searchselector- the variable selector- Returns:
- the selected variable declaration or null if none was found
-
findAttribute
public static Attribute findAttribute(IModelElement scope, java.lang.String name)
Finds an attribute withinscopeor enclosing parentscopes, i.e., search in inverted direction along attribute application/inheritance.- Parameters:
scope- the scope (may be null, leads to null as result)name- the name of the attribute- Returns:
- the attribute declaration or null for none
-
-