Copy class issue

Hello,

In IntelliJ, when you copy a .java class file from ClassA.java to ClassB.java, the name of the class in the file ClassB.java is automatically changed to ClassB. I would expect the same behavior in PhpStorm as it does not make sense to have 2 classes with the same name, at least not in the same namespace. But when I copy a class, either  with ctrl+c or F5, it just simply copy the file but does not rename the  class itself. I search the help and forum and did not find anything about this. Is there a way to force PhpStorm to rename the class in the new file please?

Thanks

3 comments
Comment actions Permalink

Hi there,

There is no such action as "Copy Class" in PhpStorm -- https://youtrack.jetbrains.com/issue/WI-22591

ATM all operations performed on files do not affect class names/namespaces inside them .. so, for example, if you want to move file from one folder to another (or rename file) while still keeping the namespace/class name in syn .. then you should use "Refactor | Rename" or "Refactor | Move" on actual class (invoking these actions on file in Project View panel will do one thing while invoking them in actual Editor while having caret on class name will do different thing).

0
Comment actions Permalink

Thanks for the answer. The thing is that I don't want to move it nor do I want to refactor it and have all its usages update. I just want to copy it as a new different class as it is done in IntelliJ for java classes. This is specially useful when mapping PDO query to classes and you have tables that are very similar except for one or two fields. I can still copy the file then update the name manually but it would be nice to have it done automatically. As you said "ATM" is there any plan in the future to have this?

0
Comment actions Permalink
As you said "ATM" is there any plan in the future to have this?

1) I gave you the link to a specific "Copy Class" ticket (which is not closed or declined) -- that should answer this question straight away. You can star/vote/comment to get notified on progress. Feel free to ask questions/describe your needs there -- maybe it will speed up implementation of that ticket. So far this is rather rarely use case + no votes .. therefore it's not in "implement this in next version" list.

2) My "ATM" was referring to actions when user manipulates files ("move"/"rename" -- no "copy" here) and explained about (more appropriate) alternatives to those actions. But yes -- there are tickets that ask to alter class names/namespaces when performing move/rename on files (e.g. https://youtrack.jetbrains.com/issue/WI-21208 ). ATM "copy" action is not one of them. I'd assume that if such behaviour will be implemented it would cover "copy" as well.

0

Please sign in to leave a comment.