CLion 2018.1 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.

Inline Function Refactoring Examples

BeforeAfter
//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; }
BeforeAfter
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; }
BeforeAfter
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()
BeforeAfter
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. Place the caret in the editor at the desired symbol to be inlined.
  2. Do one of the following:
    • On the main menu or on the context menu, choose Refactor | Inline.
    • Press Ctrl+Alt+N.
  3. In the Inline dialog box that corresponds to the selected symbol, confirm the inline refactoring or view the selected symbol usages in Find Refactoring Preview.
Last modified: 30 May 2018

See Also