The following steps describe how the scripting functionality can be used for advanced analysis of a code base:
-
Select menu "File" -> "Import Quality Model" and choose some scripts from the Java quality model, e.g. "Java/DesignPatterns/Singleton.xml" and "Java/BadSmells/FindDeadCode.xml".
-
Open the Files view and open the scripts in the Script view. Run them and examine the results.
-
Check the script content and examine the usage of the visitor pattern.
-
Click F1 to open the context help. Select the JavaDoc for the Script API. Detach the Help view for better usability and examine the available functionality.
-
Write a script that finds all "deprecated" methods and classes. Check "Java/BadSmells/FindDeadCode.xml" for the logic to examine dependencies to annotations.
-
Create issues for the found elements.
-
Use the Exploration view to verify your result.
-
Make the annotation class a script parameter.
-
Add the script to the automatically executed scripts via "System" -> "Configure..." -> "Script Runner".
-
Check that the created issues show up in the Issues view.
-
Modify the issue text in the script. Note that the button "Update Automated Script" is now enabled in the Script view. Transfer the modified content to the automated script and check in the Issues view that the description is changed.
-
Check the CoreAccess.find*() methods in the JavaDoc. Modify the script to search for the @Deprecated annotation and find all incoming dependencies. You can copy from the script UsageOfSystemOutPrintln, contained in the Java quality model.
-
Compare the execution times of the two different approaches (visitor vs. search). Think about the pros and cons of each.
-
Open the Sonargraph system "step2_crm-domain-example.sonargraph" and examine the script "FindMethodWithAnnotationValue". Think about annotation values in your own projects that you want to check.
End of Step 2 (step2_crm-domain-example.sonargraph).
Related topics: