Built-in refactorings

Introduction

The Refactoring Toolkit offers a comprehensive set of optimization features designed to improve code quality, maintainability, and efficiency. These tools automatically identify and apply enhancements, such as optimizing conditional logic, eliminating redundancies and refining structural elements of the codebase.
By adhering to established best practices such as SonarQube quality guidelines, the toolkit ensures consistent and reliable code transformations across all development projects. Below is a list of built-in refactorings available in the toolkit, each addressing specific optimization needs:

  • MQConstantsRefactoring: Reorganizes IBM MQ constants into grouped categories based on their prefixes.
  • EmptyIfRefactoring: Removes unnecessary “if” statements that contain only comments.
  • IdenticalConditionExpressionsRefactoring: Eliminates redundant conditions in logical AND/OR expressions.
  • IfTrueNoElseRefactoring: Simplifies code by removing unnecessary if(true) constructs without else clauses.
  • SameConditionMultifRefactoring: Removes duplicate condition clauses in multi-branch if statements.

Using Built-in Refactorings

In the Refactor.java class, you are required to import the built-in classes. This can be accomplished as follows:

import com.netfective.bluage.reverse.gapwalk.refactoring.java.api.builtins.*;

Subsequently, you will have the capability to use any built-in class within the getRefactorings() method. In the following example we will use the built-in MQConstantsRefactoring:

    public static List<Supplier<? extends IGapwalkRefactoring>> getRefactorings() {
List<Supplier<? extends IGapwalkRefactoring>> refactorings = new ArrayList<>();
refactorings.add(() -> new MQConstantsRefactoring());
return refactorings;
}