Moving a non-public class in its own file

Hi. What is the easiest way (in Ariadna) to move a non-public class - currently defined in the same file with a public class - in its own file? The Move refactoring does not seem to address this case.

Thanks,
Vlad

6 comments
Comment actions Permalink

I usually do create a new file and then replace whole text (except package
statement) with copy/paste.

--

Best regards,
Maxim Shafirov
JetBrains, Inc / IntelliJ Software
http://www.intellij.com
"Develop with pleasure!"


"vlad" <no_mail@jetbrains.com> wrote in message
news:27809127.1059598586857.JavaMail.javamailuser@localhost...

Hi. What is the easiest way (in Ariadna) to move a non-public class -

currently defined in the same file with a public class - in its own file?
The Move refactoring does not seem to address this case.
>

Thanks,
Vlad



0
Comment actions Permalink

Maxim, thanks for the answer.

That's exactly what I did: I created a new file (with "New File"), then selected the whole class (with Ctrl-W) and moved it to the new file. Suddenly, all the references to my class became invalid - it took me several good minutes to realize that I had forgot to add a package statement to the new file containing the class. (IDEA did not offer any helpful hint.)

Two questions:

1) Should I submit a request to automatically support the refactoring I described?

2) What about IDEA warning you somehow that a Java file is missing a package declaration? (If it can already do this, please tell me the details.)

0
Comment actions Permalink

Another solution will be to make the class public and accept quick fix intention "Move public class to the corresponding file"

--
regards,
Alexey Kudravtsev.
JetBrains, Inc
http://www.intellij.com
"Develop with pleasure!"


"vlad" <no_mail@jetbrains.com> wrote in message news:6551758.1059652167121.JavaMail.javamailuser@localhost...

Maxim, thanks for the answer.

>

That's exactly what I did: I created a new file (with "New File"), then selected the whole class (with Ctrl-W) and moved it to the

new file. Suddenly, all the references to my class became invalid - it took me several good minutes to realize that I had forgot to
add a package statement to the new file containing the class. (IDEA did not offer any helpful hint.)
>

Two questions:

>

1) Should I submit a request to automatically support the refactoring I described?

>

2) What about IDEA warning you somehow that a Java file is missing a package declaration? (If it can already do this, please tell

me the details.)
>
>


0
Comment actions Permalink

Thanks for the tip, Alexey. This solution is more straightforward and it has the advantage that I do not have to worry about the package statement. I still have to remember, though, to go in the new file and remove the public class modifier.

I am wondering: couldn't the existing Move refactoring be slightly modified to accomodate package-level classes? It would require only one thing: when I invoke Move on a package-level class, the dialog would simply ask: "To File:" rather than "To Package:". It would suggest by default: <current_package>.<name_of_the_class>.java

I expect that it would be very simple to implement this. What do you say?

0
Comment actions Permalink

I'd rather prefer the checkbox "Move other classes in this file as well" when performing Move class refactoring.
You are welcome to post the request into the www.intellij.net/tracker
Let's see how many votes it will get
--
regards,
Alexey Kudravtsev.
JetBrains, Inc
http://www.intellij.com
"Develop with pleasure!"


"vlad" <no_mail@jetbrains.com> wrote in message news:14021656.1059662201462.JavaMail.javamailuser@localhost...

Thanks for the tip, Alexey. This solution is more straightforward and it has the advantage that I do not have to worry about the

package statement. I still have to remember, though, to go in the new file and remove the public class modifier.
>

I am wondering: couldn't the existing Move refactoring be slightly modified to accomodate package-level classes? It would require

only one thing: when I invoke Move on a package-level class, the dialog would simply ask: "To File:" rather than "To Package:". It
would suggest by default: <current_package>.<name_of_the_class>.java
>

I expect that it would be very simple to implement this. What do you say?



0

Please sign in to leave a comment.