Declaring Transformations as Quickfix

Running a transformation and rewriting the code can be time-consuming. This section explains how to declare a transformation as quickfix and link them to an analysis.

Transformations of program elements returned as analysis results are declared using the multifile predicate transformation_api:transformation/5. Its arguments are:

  • Group is a Group term returned from an analysis (see → Wrapping Analysis Results for the GUI).
  • Role is a Role term returned from an analysis (see → Generating a Result Term).
  • CTHead is the head of a CT that implements this transformation. It may also be a list of CT heads that should be executed sequentially.
  • Description is a text shown in the GUI when suggesting the transformation.
  • Options is a list. Possible options are:
    • preview: Show a preview even when applying this transformation to just one result.
    • global: Apply this transformation to all results that play the same role.

This predicate is called by JTransformer with the mode (+, +, -, -, -), i.e. Group and RoleTerm are bound.

The following listing shows the transformation defined for the “Singleton Constructor not private” analysis from our Tutorial project.

1: :- multifile(transformation_api:transformation/5).     % Don't forget the declaration!
3: transformation_api:transformation(
4:     _,                                                 % Individual result (No group)
5:     sysout_call(CallId),                               % RoleTerm
6:     replaceSysoutWithLogging(CallId),                  % CTHead
7:     'Replace by call to logging method',               % Description
8:     [preview]).                                        % Option: Show Preview

Presentation of Declared Transformations

The declared transformations for a particular analysis result are shown in the Java editor. The screenshot below shows the transformations for a result of the “System.out.println” detector. The first two offered transformations result from the transformation definition shown above.

  • The first one simply executes the specified CT and applies the changes to the Java source code without further user interaction. This suggestion is always generated, independent of the options set in the transformation declaration.
  • The second one opens a wizard that shows the changes of the Java source code before applying them. This suggestion is generated if the 'preview' or the 'global' option is set in the transformation declaration (for analyses that apply globally, a preview is always generated).

The last four transformations are always offered for each result. For further information see Viewing Results.

  • The accept and reject suggestions can be used to assess the analysis results as correct or incorrect. They trigger transformations that add a special comment to the respective code element.
  • The suppress suggestion deactivates reporting this particular result. This also boils down to adding a special comment to the respective code element.
  • The deactivate suggestion deactivates running this analysis. It is equivalent to deactivating the analysis by unchecking it in the Control Center.

Last modified: 2016/04/18 03:19