Analysing Java with VSCode
VSCode is an incredible editor tool. Thanks to its extensions, one can develop using plenty of programming languages. However, what about analyzing one software system using VSCode?
Even if we can perform some analysis from VSCode, using the Moose tool natively gives a better user experience. Still, I believe it might interest people using only the VSCode tool.
- Install VSCode and the Pharo Language Server extension
- Set up the analysis of a new project
Install VSCode and the Pharo Language Server extension
Download and install the required tools
To perform the analysis, we will use the insider version of VSCode. Currently, only this version supports the NoteBook feature we will use.
So, as a first step, install the last VSCode insider version.
We will also need a Moose image and a Pharo VM. For this blog post, we will use a Moose 8 image based on Pharo 8.
- Download the last Moose 8 image for VSCode and extract it.
- Download the corresponding Pharo VM and extract it.
Do not take the headless version (it has not been tested)
Once you have download VSCode, Moose 8, and the Pharo VM, we will install the extension in VSCode.
- Download the extension
- Open VSCode insider
- Open the folder in which the extension file is present
- Right-click on the file and execute
- Close VSCode
From now on, you must start VSCode insider with the following parameters (
It allows VSCode to use the Notebook API.
Execute the following command in a terminal:
Or in Windows:
We now need to configure the Pharo Language Server extension. To do so:
- go in the VSCode settings (
Ctrl + ,).
- Search Pharo settings
- Set the field
Path To Imagewith the path to the image you have downloaded
- Set the field
Path To VMwith the path to the VM you have downloaded
- Restart VSCode (to be sure the configuration is well saved)
If you use Windows, you might need to remove all space characters in the path.
Once the configuration is done, you can create a new file named
It should open as a VSCode notebook and a Pharo image (you can reduce the Pharo image, but do not close it).
Set up the analysis of a new project
Clone the Java project you want to analyze
First, we are going to download the GitHub project we want to analyze.
To do so, create a new
code cell in VSCode with the following code:
This piece of code will download the project under our Pharo image folder. To execute the cell, press the run arrow next to the cell. In case of success, a little tick appears and the path to the clone project has output of the cell.
Parse the Java code to make FAMIX model
As in the original blog post of Christopher, now we will parse the Java project and create a FAMIX model. To parse the Java project, we use VerveineJ v1.x.x (v1.x.x works with Moose 8, whereas v2.x.x is under modification to work with the future Moose 9).
Contrary to the original blog post, we will download VerveineJ v1.0.2 (and not v1.0.1). It includes nice fixes.
Create a new code cell with the following piece of code to download the last VerveineJ version and extract it
Then, we will ask
MooseEasyFamixMakerto parse the Java project using VerveineJ, and create a
.msefile for us. Again, in another cell, execute the following snippet of code.
.mseis a file format used by Moosetechnology to represent its model and meta-model. Other formats exist.
Load the model
The last step is to load the model in the Moose image (the one we are controlling using VSCode). In a new cell, execute:
The output of the cell should be
a MooseModel #HFDP(30946).
Congrats! You have set up everything. Now it is time to analyze the project 🚀
Visualize a Java package in PlantUML
To visualize Java packages using PlantUML.
We first install the PlantUML connector of Pharo (
To do so, simply create a new code cell with the installation script and execute it.
Then, you can visualize the classes of a package by executing a Pharo Script.
In the above example, as in the original blog post, we focus on the package:
headfirst::designpatterns::combining::decorator and we show the classes attributes, inheritances, and aggregation.
Executing the code gives the following image as the output of the VSCode cell.
Perform a Moose analysis using Pharo
It is also possible to execute some classic Pharo code. We can request the list of classes that implement more than one interface.
Visualisation with Roassal
It is possible to use pre-built visualization coming from Moose, such as the System Nesting map:
Or every other Roassal visualization!