How to "automate refactoring" of code
For example: How to modify the method name of the code and its invocation?
#!/usr/bin/env pythondef test(): test = 'test()' print test[:-2]test()
Note:
1. The IDE generally has such a function, it is hoped that the automated completion of the batch operation.
2. Methods such as regular are not considered here, such as strings in the code with the same name can easily be replaced.
3. The practice of the master is to make use of Python-rope [Https://github.com/python-rope/rope]
To refactor, but only to find a way to modify the variable. Is there any experience in providing methods or other similar tools?
4. Tools that are not necessarily limited to Python refactoring other languages can also be shared.
5. The "automated refactoring" here means that I do not need to do it manually. When I write the refactoring rules, I can refactor some projects in batches. Similar Python-rope
Reply content:
How to "automate refactoring" of code
For example: How to modify the method name of the code and its invocation?
#!/usr/bin/env pythondef test(): test = 'test()' print test[:-2]test()
Note:
1. The IDE generally has such a function, it is hoped that the automated completion of the batch operation.
2. Methods such as regular are not considered here, such as strings in the code with the same name can easily be replaced.
3. The practice of the master is to make use of Python-rope [Https://github.com/python-rope/rope]
To refactor, but only to find a way to modify the variable. Is there any experience in providing methods or other similar tools?
4. Tools that are not necessarily limited to Python refactoring other languages can also be shared.
5. The "automated refactoring" here means that I do not need to do it manually. When I write the refactoring rules, I can refactor some projects in batches. Similar Python-rope
Using Automated refactoring Classes
Python-rope [Https://github.com/python-rope/rope]
Using the Headless IDE
Eclim
Https://github.com/ervandew/eclim
We usually use JetBrains a series of Ides, which have a series of IDE WebStorm
(JavaScript), ( Intellij
Java), Pycharm
(Python), and so on, these tools have their own refactoring capabilities. As in IntelliJ, there are some refactoring options that can be found in Martin's "refactoring" book.
Then, the function you need should be Rename
, the shortcut key is Shift
+F6
1. Check Test ()
2. Press SHIFT + F6 to pop up the dialog box
3. Enter a new method name
4. Select a section, or all the content that needs to be modified.
During the internship, I wrote a series of articles about how to use IDE refactoring: ThoughtWorks Practice--a tentative study of reconstruction and IntelliJ idea
Reply to the comments in the picture.
Refactoring automation is a pseudo proposition, to do automation, need to have a clear input, clear output, the desired output, so that you can compare the output of automation and you expect the output is consistent