Automatic Refactoring of Classes

조회 수: 8 (최근 30일)
Jose Gonzalez
Jose Gonzalez 2018년 5월 22일
답변: per isakson 2019년 12월 18일
I am working in a project that is using multiple classes and I have the need to refactor (rename) some of the classes and functions within those classes. Using an example, I will illustrate the problem that I am facing.
• Let us say that I have two classes in the project. One is called “Class1” and another one is called “Class2”. “Class1” calls ““Class2” and some of its functions.
• I have the need to rename “Class2” to “Class3”. If I do so, that creates a problem in “Class1”. “Class1” will still be referencing “Class2”. Therefore my code does not compile.
• In order to solve this issue I need to go to “Class1” and rename every instance that was referring to “Class2” and substitute it for “Class3”.
• Other languages (or their IDEs) automatically make the change for you. I wanted to know if there was a way to do the same in Matlab.
• If the class is used several times in different classes of the project, refactoring can become a burdensome / extremely difficult task.
Matlab has similar functionality for renaming variables within the same file. Renaming and then pressing “Shift + Enter” does the trick within the same file. Therefore, I am looking for an equivalent solution when you are working with different classes/files in the same project.

채택된 답변

Guillaume
Guillaume 2018년 5월 22일
Unfortunately, the refactoring tools are very limited in matlab. I'm afraid you're left with search and replace. You'll have the same problem if you rename packages.
The other issue you may run into is that you won't be able to reload old class instances stored in mat files, even if you try to overload loadobj.

추가 답변 (1개)

per isakson
per isakson 2019년 12월 18일
There are some submission in the File Exchange that should be useful for renaming names over many files. Search for replace in files.
I have successfully used Find and Replace in Files by Robyn Jackey [Staff] to change names in many files.

카테고리

Help CenterFile Exchange에서 Software Development Tools에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by