In this wiki page, we will present couple of analysis examples around a case study. In our case, we take ArgoUML, an open-source Java project.
The system contains some deprecated classes.
A typical question is which of these classes we can remove.
Essentially, this boils down to finding the classes annotated with
@Deprecated and then selecting those that are not used anywhere (we ignore reflection for this exercise).
This is an analysis.
We first need to build a model of our system, and for this we will use VerveineJ:
path/to/VerveineJ/verveinej.bat -format json -o ArgoUML-0-34.json -autocp ./libs ./src
You can also download the json file.
The result is that you will get an ArgoUML-0-34/ArgoUML-0-34.json file with the serialized model that can be loaded in Moose. Make sure you have Moose 9.0 or later.
Starting Moose you see a menu with various tools. Open the ‘Models browser’ tool.
Click on the JSON button on the top right and load the ArgoUML-0-34.json file. You need to tell Moose what Famix Meta-Model to use for this file. Here you want the Java Meta-Model, hence the FamixJavaModel.
An extra step is to point the model to the sources folder. To this end, right-click on the ArgoUML-0-34 model, choose Utilities/Set root folder, and point to the ArgoUML-0-34 folder.
Now we are ready to query our system.
We will first look at deprecated classes. Inspect the model with a right-click on the model and Inspect.
To retrieve the deprecated classes, select the
All model classes entry.
Then, open the script area and type the following script:
self select: [ :each | each isAnnotatedWith: 'Deprecated' ]
Select the script, and execute it with Ctrl + g
In the right pane, you get the list of the deprecated classes in ArgoUML
Just to make sure that we indeed got deprecated classes, let’s investigate one of them and select it to view its source code. Select one entity and open the ‘Source code’ browser (‘Specialized Browsers’ » ‘Famix’ » ‘Source code’).
Then, by clicking on the Propagate button of the inspector, you’ll get the source code of the selected class in the ‘Source code’ browser. Note that this depends on Moose knowing where the files reside on your disk, see the above how to point the model to the sources folder.
We have 28 classes that are deprecated in the system. Next, we need to check which of those are not used. Or if we think in terms of clients and providers, which of the deprecated classes do not have client classes. Go back to the inspector with the pane listing the 28 classes, open the script area again, and execute the following expression:
self select: [ :each | each clientTypes isEmpty]
We get 14 classes that can be removed immediately.
To retrive the other classes, execute the following expression:
self select: [ :each | each clientTypes isNotEmpty ]
This gives 14 classes that cannot be removed because they are still being used.
This wiki page was first created for the moosebook.