How does renaming files work?!

One aspect of IDEA that I constantly struggle with is that some of its operations are "logical" (i.e. work on classes and packages), and others are "physical" (i.e. work on files and directories). Even though I always use Project view rather then Packages View, I'm often asked if I want to perform an operation on a package or a directory, which is annoying. At other times IDEA just does the wrong thing: I ask it to run all tests in a directory (Project view!), but it runs all tests in the package instead.
Right now I'm trying to rename a file Foo.groovy that contains a class named Bar, but I can't figure out how to do it. I've tried with Refactor->Rename in Project View, editor file tab, and breadcrumb, but every time the class gets renamed instead of the file. Where is the command to rename the file? IDEA9, latest EAP.

Cheers,
Peter

7 comments

I'm using IDEA for many years and never has thought that in Project Viewit shows real directories/files instead of virtual
for me the Project View shows exactly the same as Package View but with grouping similar to real directory structure
that's why for me it's quite strange to hear "I ask it to run all tests in a directory (Project view!), but it runs  all tests in the package instead. "

0

If you edit the file, you should see the class name underlined as an error, and if you put the caret on it and press Alt-Enter, you should get the option to rename the class or the file.

0

Why would the class name be underlined in red? Groovy classes don't have to match the file name (and neither do non-public Java classes).

0

Sorry, my mistake - I was referring to public Java classes that don't match their file name (the problem wouldn't apply to non-public Java classes).

0

On 2010-03-05 18:45:51 +0100, Peter Niederwieser <no_reply@jetbrains.com> said:

Where is the command to rename the file? IDEA9, latest EAP.


Try selecting the file and press Shift+F6. That does the trick for me.


0

Right, that works if the file contains multiple classes. But if it contains just one class, IDEA doesn't show me the file.

0

Unfortunately there's no such action now (IMHO it ought to be). With
Groovy classes, there's a workaround. Type some statement outside the
class to make the file a script and then press Shift+F6. Rename the
file, and remove those fake statements back. Sorry

0

Please sign in to leave a comment.