SDA SE Wiki

Software Engineering for Smart Data Analytics & Smart Data Analytics for Software Engineering

User Tools

Site Tools


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.

:- multifile(transformation_api:transformation/5).     % Don't forget the declaration!

transformation_api:transformation(
    _,                                                 % Individual result (No group)
    sysout_call(CallId),                               % RoleTerm
    replaceSysoutWithLogging(CallId),                  % CTHead
    'Replace by call to logging method',               % Description
    [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.

research/jtransformer/tutorial/quickfix.txt · Last modified: 2018/05/09 01:59 (external edit)

SEWiki, © 2024