【Journey of HarmonyOS Next】DevEco Studio User Guide (16) -> C++ Code Refactoring (2)



This content originally appeared on DEV Community and was authored by ZHZL-m

Image description

1 -> Define the constructor

The editor provides refactoring capabilities and allows you to generate default constructors for member variables of classes.

Specification limitations

Classes that do not initialize member variables are not supported
Triggering in positions other than (class flags, class names, curly braces) is not supported
A constructor with input parameters is not supported
How to use: Right-click Generate…, select Constructor, and click Define in the pop-up box to define a constructor for the member variables.

Image description

2 -> Extract expressions to variables

In the editor, select the range of expressions to be extracted, right-click Refactor, and select Extract Variable to extract expressions to variables.

Image description

3 -> Remove namespace

Hover over the namespace to be removed, right-click Refactor, and select Remove Using Namespace to avoid naming conflicts and improve code readability.

Image description

4 -> Add a using declaration

In the editor, hover over the area where you want to add a using declaration, right-click Refactor, and select Add Using to define a type alias.

Image description

5 -> auto auto unfolds

Right-click the auto keyword Refactor and select Expand Auto Type.

Image description

6 -> Declare implicit members

The editor supports declaring implicit copy/move members in a class. Hover over the class you want to generate…, and select Copy/Move Members.

Image description


This content originally appeared on DEV Community and was authored by ZHZL-m