How To Write a Custom Audit

Part 2: Creating the Audit Class

This part of the tutorial shows how to define a new audit class to use the Together API.

The easiest way to create an audit is to define a class that extends com.togethersoft.sca.plugin.audit.AuditRule. The AuditRule class contains stubs for the necessary check methods for the audit logic.

  1. Create a class on the CustomAudit diagram. Name it EmptyMethodRule.

  2. Select the class on the diagram. In the Properties View, click the extends field.

  3. At the right of that field, click the Selection dialog button to open the Selection dialog.

  4. Locate com.togethersoft.sca.plugin.audit.AuditRule from the Model elements on the left, and click Add to add it to the Selected list on the right. Your Selection dialog should look like the one shown below:

    Selection dialog for the parent class

  5. Click OK.

  6. The declaration of EmptyMethodRule is correct, but the class is missing two required methods. Right click on the class and choose Add Constructors from Superclass. You will modify this constructor later.

  7. Right click on the class and choose Override Methods. This opens the Override Methods dialog.

  8. Check checkMethod(AstMethod) as shown below. Then click OK.
    Override methods dialog
    When Together runs your audit, it automatically calls checkMethod(AstMethod) for each method in every class and interface. The actual method is one of the parameters.

  9. Go to the editor to see the resulting EmptyMethodRule code. If the editor indicates a syntax error, right click the source code and choose Source > Organize Imports.

  10. Save the EmptyMethodRule.java file.
Part 3: Writing the Audit