1.3. Advanced Analysis

The following steps describe how the scripting functionality can be used for advanced analysis of a code base:

  1. 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".

  2. Open the Files view and open the scripts in the Script view. Run them and examine the results.

  3. Check the script content and examine the usage of the visitor pattern.

  4. 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.

  5. Write a script that finds all "deprecated" methods and classes. Check "Java/BadSmells/FindDeadCode.xml" for the logic to examine dependencies to annotations.

  6. Create issues for the found elements.

  7. Use the Exploration view to verify your result.

  8. Make the annotation class a script parameter.

  9. Add the script to the automatically executed scripts via "System" -> "Configure..." -> "Script Runner".

  10. Check that the created issues show up in the Issues view.

  11. 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.

  12. 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.

  13. Compare the execution times of the two different approaches (visitor vs. search). Think about the pros and cons of each.

  14. 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: