Refactor: renaming file name results in renaming my class name

Answered

Hello,

I have a problem/difficulty using refactor-> rename. I would very appreciate if someone could help with that!

I have a class MyCar implemented in the file named MyCar.cpp (Note that there is no MyCar.h)

I want to rename the file MyCar.cpp to my_car.cpp and I did it using Refactor -> Rename ( or using Shift+F6). It works BUT CLion also renamed the name of the class inside that file: the class MyCar became my_car, which I don't want and CLion is supposed not doing that.

Could you please help how to fix this?

The same thing also happens for the header file. For example, I have a header file MyBike.h, and a class MyBike inside that header file. Then Shif+F6 to rename the file MyBike.h also results in renaming the class name inside.

Here is the screen shoot: 

  • Project before refactor-> rename

 

  • Project after renaming:

0
3 comments

Hi! Thanks a lot for the detailed description.

We have the related issue in our tracker: https://youtrack.jetbrains.com/issue/CPP-2724. Feel free to comment or upvote, follow it to get updates.

0
Avatar
Permanently deleted user

Hi, thanks for the comment. But this is a new/ different problem comparing with the one in your link. 

  • The one mentioned in your link was fixed. That said, if you have both .h and .cpp files, then renaming the filename does not result in renaming the Class name. 
  • In the case I reported, the problem occurs when you  have only one .h file  or  only one .cpp file, in which the class is defined. Note again that the problem does not occur if you have both .h and .cpp file.
0
Avatar
Permanently deleted user

Use CMakeLists.txt like this:

project(my_project)
aux_source_directory(. SRC_LIST)
add_executable(${PROJECT_NAME} ${SRC_LIST})

0

Please sign in to leave a comment.