Analyzing AUTOSAR model with Xbase
AUTOSAR models can grow to be quite complex and finding your way around the model is often not very easy. A simple search within a model is often not sufficient for a complex analysis.
For Artop-based tools, a simple solution based on Xtext's Xbase support is readily available at virtually no cost. It just extends your Eclipse-based product with a few plugins to add powerful scripting capability.
The core is Christian Dietrich's mql project in github.
Let's assume that we have a very simple AUTOSAR model in Artop such as:
Assume that we would like to find all the software components that have a provided port that reference an interface named "if". You could create a .mql file in the workspace with the following content:
import autosar40.swcomponent.components.PPortPrototype import autosar40.swcomponent.components.ApplicationSwComponentType val arModel = SphinxUtil.getAutosarModel("blog") val swCs = arModel.filter(ApplicationSwComponentType).filter[ports .filter(PPortPrototype).exists[providedInterface.shortName == "if"]] swCs.toList
The first two lines are just import statement, the next line retrieves the Autosar model from project 'blog'. After that, the first simple assignment is our actual query:
- We traverse the model, filtering all ApplicationSwComponentType
- From those we filter those, who have a PPortPrototype whose providedInterface.shortName equals "if"
And the last line prints the result. No Pressing CTRL-Shift-I starts the interpreter (no compiling or building a new application is required!) and opens a Window showing the results of your script:
swCs.toList // ArrayList: [autosar40.swcomponent.components.impl.ApplicationSwComponentTypeImpl@31ab743f (shortName: ac) (shortNamePattern: <unset>)]
This is quite bare-metal, showing the Java objects that come from your query. But in a specific setting (not part of Christian's code, because it applies to the Sphinx framework), we also show the results in the Eclipse Sphinx search view.
And from here you can:
- Navigate to the found elements in the Model explorer
- Open the element in the editor
- Find References in the Sphinx references view (if your application uses the latest version of Sphinx).
Of course, there is almost no limit about what you can do in the script language. You can:
- Load more than one model
- Load any kind of model and their combinations (e.g. AUTOSAR and non-AUTOSAR)
- Access Artop's new convenient interface for ECUC configurations
- Access any Java class (e.g. Apache String helpers, Google's Guava collections, Guice, ...)
All in all, it is a gem that provides tremendous help when working with AUTOSAR models.