We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

Only Essential Cookies
Accept All
GuidesCoding and DebuggingWriting CodeCode Generation/Completion

Code Generation/Completion

Intelligent Code Completion

With the intelligent code completion feature, the editor displays context-sensitive suggestions – fuzzy matching supported – for names of classes, methods, fields, keywords, and more.

By default, items in the suggestion list are sorted by the shortest path. To sort them by recency, choose File > Settings (DevEco Studio > Preferences/Settings on macOS) > Editor > General > Code Completion and select Sort suggestions by recently used.

NOTE

If the settings do not take effect, make sure Sort suggestions alphabetically is deselected on the Code Completion page.

Overriding Methods of a Parent Class

The Override Methods feature helps you quickly generate methods from the predefined template of a parent class. Place the caret within the class where you want to override members from the base class, press Ctrl+O (Control+O on macOS), or right-click Generate..., choose Override Methods from the shortcut menu, specify the member (such as method and variable) to override, and click OK. The code of the overridden member is automatically generated.

Quickly Generating Constructors

The editor can quickly generate a constructor for a class.

Place the caret within the target class and press Alt+Insert (Command+N on macOS). Alternatively, right-click the class and choose Generate... from the shortcut menu. When prompted, select Constructor, select one or more parameters to be initialized in the new constructor, and click OK. If you select Select None, a constructor without parameters is generated.

Quickly Generating Getters and Setters

The editor can quickly generate a getter and setter for a class member variable or object attribute.

Place the caret within the target class, right-click and choose Generate... > Getter and Setter, or press Alt+Insert (Command+N on macOS) and select Getter and Setter.

Quickly Generating Declaration Information to an Index File

The editor enables the batch declaration of information in HSP and HAR modules that needs to be exposed externally, such as variables, methods, interfaces, and classes, in the Index.ets file, to facilitate calls from other modules.

To use this feature, in the file editing window of an HSP or a HAR module, right-click anywhere and choose Generate... > Declarations, or press Alt+Insert (Command+N on macOS) and select Declarations from the drop-down menu. While pressing and holding the Ctrl key, select the variables, methods, APIs, and classes that you need to declare. The corresponding declaration information will be batch generated in the module's Index.ets file.

Search in Guides
Enter a keyword.