Package net.ssehub.easy.varModel.model
Class ModelQuery
java.lang.Object
net.ssehub.easy.varModel.model.ModelQuery
- Direct Known Subclasses:
IvmlModelQuery
Provides an interface to query models.
- Author:
- Holger Eichelberger
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classSelects the first declaration with the given type.static interfaceDefines the interface of a declaration selector.private static classRepresents an incrementally resolved namespace.private static classA private quick datatype visitor. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringprivate static final QualifiedNameModeprivate static final List<ModelQuery.MqDatatypeVisitor> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static ContainableModelElementcheckElement(ContainableModelElement element, String name, Class<?> type) Checks a containable model element.private static IResolutionScopecheckInterfaceImport(IResolutionScope scope, ModelQuery.IncrementalNamespace ispace, String namespace, IResolutionScope project) Performs final checks on accessing an imported interface.private static booleancheckScopeForImport(String name, ProjectImport imp, String namespace) Check the validity of the scope being imported.static ValueenumLiteralAsValue(IResolutionScope elements, String name) Finds a referenced enum literal inproject.static AttributefindAttribute(IModelElement scope, String name) Finds an attribute withinscopeor enclosing parentscopes, i.e., search in inverted direction along attribute application/inheritance.private static IModelElementfindCompoundOrAttributeAccess(IResolutionScope elements, String name, 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, String name, Class<?> type) Finds an element by its given name inelements.private static ContainableModelElementfindElementByName(IResolutionScope elements, String name, Class<?> type, Set<IResolutionScope> done) Finds an element by its given name inelements.static IDatatypefindElementByTypeName(IResolutionScope elements, String typeName, Class<? extends IDatatype> type) Finds the specified data type definition in the givenelements.static IDatatypefindElementByTypeName(IResolutionScope elements, String typeName, Class<? extends IDatatype> type, Set<IResolutionScope> done) Finds the specified data type definition in the givenelements.static IDatatypefindElementByTypeName(IDecisionVariableContainer container, String typeName) Finds the specified data type definition in the givencontainer.static EnumfindEnum(IResolutionScope elements, String name) Finds a referenced enum literal inproject.static ProjectfindProject(Project project, String name) Finds a project with given name.private static ProjectFinds a project with given name.findRefining(IResolutionScope scope, Compound compound) Returns all (reachable) compounds (transitively) refining the givencompoundstarting atscopealso considering imported scopes.private static voidfindRefining(IResolutionScope scope, Compound compound, List<Compound> result, Set<IResolutionScope> done) Returns all (reachable) compounds (transitively) refining the givencompoundstarting atscopealso considering imported scopes.private static IDatatypefindType(IResolutionScope elements, String name, boolean considerVariableDeclarations, Class<? extends IDatatype> type, Set<IResolutionScope> done) Finds the specified data type definition in the givenproject.static IDatatypefindType(IResolutionScope elements, String name, Class<? extends IDatatype> type) Finds the specified data type definition in the givenproject.private static AbstractVariablefindVariable(Compound compound, String name) Searches for a variable ofnamein a givencompound.static AbstractVariablefindVariable(IResolutionScope elements, String name, Class<? extends AbstractVariable> type) Searches for a specified variable.static IModelElementfindVariableUse(IResolutionScope elements, String name, Class<?> type) Searches for a specified variable or variable use.private static IModelElementfindVariableUse(IResolutionScope elements, String name, Class<?> type, Set<IResolutionScope> done) Searches for a specified variable or variable use.getAllAttributes(IResolutionScope scope) Returns all attributes inscope.private static voidgetAllAttributes(IResolutionScope scope, List<Attribute> attributes, Set<IResolutionScope> done) Collects all attributes inscopeand imported scopes.private static AbstractVariablegetAttribute(IAttributableElement element, String name) Finds an attribute withnameonelement.private static final ModelQuery.MqDatatypeVisitorReturns a pooled datatype visitor instance.static List<SearchResult> getElementsByNamePrefix(ModelElement element, String namePrefix, DatatypeVisitor datatypeVisitor, SearchContext context, Class<?>... restrictions) Searches a given set of elements by a name prefix starting atelement.private static IResolutionScopegetImportedScope(IResolutionScope scope, String namespace) Returns the current scope due to imports.static final StringReturns the name to be used for searching for a reference with contained typetype.private static IResolutionScopegetScope(IResolutionScope scope, String name) Returns the resolution scope determined by the qualifiednamerelative to the givenscope.private static final StringgetType(ContainableModelElement element, QualifiedNameMode mode) Returns the textual representation of the given element.private static final StringgetType(IDatatype type, QualifiedNameMode mode) Returns the textual representation of the given type.private static final voidReleases a datatype visitor instance.private static StringremoveNamespace(String name) Removes a namespace prefix fromname.private static ProjectsearchImportedProject(String namespace, IResolutionScope scope, Set<Project> done) Searches for an indirectly imported project in depth-first search.
-
Field Details
-
MQ_SHORT_SET
- See Also:
-
MQ_SHORT_SEQUENCE
- See Also:
-
MQ_SHORT_REFERENCE
- See Also:
-
TYPE_SEARCH_MODE
-
VIS_INSTANCES
-
-
Constructor Details
-
ModelQuery
public ModelQuery()
-
-
Method Details
-
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
Releases a datatype visitor instance.- Parameters:
vis- the instance to be released
-
getType
Returns the textual representation of the given element.- Parameters:
element- the element to be representedmode- the name mode- Returns:
- the textual representation
-
getType
Returns the textual representation of the given type.- Parameters:
type- the type to be representedmode- the name mode- Returns:
- the textual representation
-
getReferenceTypeSearchName
Returns the name to be used for searching for a reference with contained typetype.- Parameters:
type- the contained type- Returns:
- the search name
-
findRefining
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, List<Compound> result, 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
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
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, String name, 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
private static IDatatype findType(IResolutionScope elements, String name, boolean considerVariableDeclarations, Class<? extends IDatatype> type, 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, String typeName, 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, String typeName, Class<? extends IDatatype> type, 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, 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, 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, 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(String namespace, IResolutionScope scope, 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, 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(String name, ProjectImport imp, String namespace) throws ModelQueryException Check 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
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, String name, 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, String name, 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, String name, Class<?> type, 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, String name, 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
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
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, String name, 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, String name, Class<?> type, 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, String name, 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
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, 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 List<SearchResult> getElementsByNamePrefix(ModelElement element, String namePrefix, DatatypeVisitor datatypeVisitor, SearchContext context, 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
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, List<Attribute> attributes, 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
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
-