Navigating AUTOSAR models with complex queries

In the previous blog posts I showed you how the basic features of Eclipse and Artop can be used to perform basic searches and navigation on AUTOSAR models. However, there are also often cases, where a user wants to perform more complex queries on AUTOSAR models. 

E.g. we might want to find PDUs with specific characteristis (number of signals, certain ID range). In the example for this blog post, we want to find all SenderReceiverInterfaces in our model, that actually don't have any data element.


Sphinx Workflows

With Sphinx we can create complex scripts in a running Artop, written in Java or (even better) in Xtend. Xtend in especially suited for the job, since it has nice concepts for complex model queries. The required steps are:

  • Create an Eclipse "Plugin"-Project. The plugin-project provides the mechanism for Java/Xtend compilation and the setup of all the required dependencies.
  • Implement the query
  • Create a "Run configuration" and execute the query.

Creating the code

To execute dynamic code from the workspace, Sphinx will look for implementations of WorkspaceWorkflow classes in the project, so we need a small implementation:

public class Query extends  WorkspaceWorkflow {    
    new() {
        children += new QueryComponent

The actual action happens in the Query component:

class QueryComponent extends AbstractModelWorkflowComponent {
    override protected invokeInternal(WorkflowContext arg0, ProgressMonitor arg1, Issues arg2) {
        val m = arg0.get(IModelWorkflowSlots.MODEL_SLOT_NAME) as List<EObject>
        val c = m.get(0).eResource.resourceSet.allContents.filter(SenderReceiverInterface).

The code for this example is actually very simple:

  • The workflow framework will invoke the invokeInternal method of all components in sequence.
  • Arguments to the workflow are passed in so-called "slots". The framework passes the elements that are selected in the Eclipse explorer in the slot with the name IModelWorkflowSlots.MODEL_SLOT_NAME
  • The next line contains our example query. For simplicity, we just use the ResourceSet of the selected object and filter the entire model for SenderReceiverInterface elements. The next filter statement looks for SenderReceiverInterfaces that have no data elements. A list is constructed out of that.
  • At this point, we could print the list of results to the console. However, since this is a full IDE, we would like to use the search view that Eclipse uses itself for search queries and which allows us to do further navigations. The code for that is in a dedicated method:
    def protected showResults(Collection<? extends EObject> coll) {
            val view =  NewSearchUI.getSearchResultView();
        val query = new ModelSearchQuery(null) {
            override getResultLabel(int nMatches) {
                "Script query"
        val searchResult = new ModelSearchResult(query);
        coll.forEach[searchResult.addMatch(new ModelSearchMatch(it))]
            (NewSearchUI.getSearchResultView() as SearchView).showSearchResult(searchResult)


Using run configurations to run the queries 

A workflow can be run either through the context menu of a element in the model explorer or through Eclipse run configurations. The context menu approach however does not support passing of arguments through an UI. So we will be using run configurations, even if we do not use workflow parameters right now (that will be shown in a later blog post). So we create a new "Sphinx workflow" and set the path to our Workflow class:


If we click the "Run" button, we will get the results in the search window. In our case, we are using the "Blueprint" model that is provided with Artop / AUTOSAR and find the following interfaces that have no data elements:



In the short series of three blog posts, we have shown how Eclipse and Artop can be used to configure a powerful tool for examining AUTOSAR models at no cost. In addition to the normal navigations and model searches, you can interactively use any Java-based language to write custom model queries - we recommend Xtend because of its powerful language features that support model navigation. The example above is quite simple, but it is very easy to write much more powerful queries.

In addition, you can use any Java-based libraries and frameworks to help you do the job. In a customer setting, we need to group PDUs according to various criteria and we make use of the  JGraphT library. 

About Andreas Graf

I am working at itemis as a project manager and business development manager (automotive) supporting and promoting the use of Eclipse and Open Source tooling for the implementation of integrated tool chains and the support of model driven (software) engineering.