Jump to content

KDevelop/RefactoringTools

From KDE Community Wiki
Revision as of 11:08, 11 March 2016 by Ochurlaud (talk | contribs) (Created page with "= Ideas for Refactoring Tools = * make a piece of code (selection?) into a function, optimally by default taking all local variables used but not declared in that piece of co...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Ideas for Refactoring Tools

  • make a piece of code (selection?) into a function, optimally by default taking all local variables used but not declared in that piece of code as arguments
   // before:
   int main() {
       int a = 1;
       int b = 2;
       // select the a + b and run refactoring
       int c = a + b;
   }
   // after:
   int sum(int a, int b)
   {
       return a + b;
   }
   int main() {
       int a = 1;
       int b = 2;
       int c = sum(a, b);
   }
  • make selected expression into a local variable
   // before:
   int main() {
       int a = 1;
       int b = 2;
       // select the a + b and run refactoring
       return a + b;
   }
   // after:
   int main() {
       int a = 1;
       int b = 2;
       int c = a + b;
       return c;
   }
  • when changing something from heap to stack or vice versa, change all

the attribute access tokens between . and ->

  • replace data types by auto in selected code (haha, some people aren't

going to like that)

  • move implementation from/to header
  • remove unused includes; sort includes; remove unused forward

declarations; replace includes in header by forward declarations if possible (is that detectable? I don't know)

  • Move functions to other classes, including either updating all callers or

leaving the original variant as a forwarding function

  • move functions up/down in the current class hierarchy (as a kind of

shortcut for the general move elsewhere)

  • change function signatures, removing/adding arguments, changing their

type etc.

  • Move nested classes to toplevel (i.e. class Foo { class Bar {}; };, move

Bar to a separate file)

  • Extract a list of members of one class into a datastructure (i.e.

bundling logically close data into a ne strcture)

  • Extract an interface from an existing class (i.e. create a base-class

with pure virtuals)

  • Extract methods into a base-class
  • Generate Getter/Setter's for members of a class
  • When having written a class declaration that inherits from an interface

class automatically generate implementations for the pure virtual functions

  • sort member functions and variables
  • when using a variable name without declaring it first provide a means to

setup either a local or a member variable of the 'right' type (if possible to extract)

  • same thing for functions including setting up the arguments and their

types