CLion 2022.3 Help

Inline

CLion provides the following inline refactorings:

  • Inline Constant. This refactoring is opposite to the Extract constant refactoring.

  • Inline Define. This refactoring is opposite to the Extract define refactoring.

  • Inline Typedef. This refactoring is opposite to the Extract typedef refactoring.

  • Inline Parameter. This refactoring is opposite to the Extract parameter refactoring.

  • Inline Function. This refactoring is opposite to the Extract function refactoring.

Examples

Before

After

//This function will be inlined int fdiff(int x, int y, int factor); int main(){ int x = 10; int y = 9; int z = fdiff(x, y, 2); return 0; } int fdiff(int x, int y, int factor) { return (x-y) * factor; }
int main(){ int x = 10; int y = 9; int z = (x - y) * 2; return 0; }

Before

After

int main (int argc, const char * argv[]) { @autoreleasepool { float result; //The third parameter will be inlined result = mulfunc(10, 20, 2); } return 0; } float mulfunc(int x, int y, int factor) { return x * y * factor; }
int main (int argc, const char * argv[]) { @autoreleasepool { float result; result = mulfunc(10, 20); } return 0; } float mulfunc(int x, int y) { return x * y * 2; }

Before

After

import math class Solver: def demo(self): a = 3 b = 25 c = 46 #This variable will be inlined return_type_of_sqrt = math.sqrt(b ** 2 - 4 * a * c) root1 = (-b + return_type_of_sqrt) / (2*a) root2 = (-b - return_type_of_sqrt) / (2*a) print(root1,root2) Solver().demo()
import math class Solver: def demo(self): a = 3 b = 25 c = 46 root1 = (-b + math.sqrt(b**2 - 4*a*c)) / (2*a) root2 = (-b - math.sqrt(b**2 - 4*a*c)) / (2*a) print(root1,root2) Solver().demo()

Before

After

function GetCookie (name) { var arg = name + "="; var alen = arg.length; //This variable will be inlined var clen = document.cookie.length; var i = 0; while (i != clen) { var j = i + clen; ... } }
function GetCookie (name) { var arg = name + "="; var alen = arg.length; var i = 0; while (i != document.cookie.length) { var j = i + document.cookie.length; ... } }

Perform inline refactoring

  1. Position the caret at the desired symbol to be inlined.

  2. Do one of the following:

    • From the main menu or from the context menu, choose Refactor | Inline.

    • Press Ctrl+Alt+N.

  3. In the Inline dialog that corresponds to the selected symbol, confirm the inline refactoring or view the selected symbol usages in Find Refactoring Preview.

Last modified: 18 January 2023