1

My professor hands out one massive .java file, which makes development a pain. Does anyone know of a script/macro/etc. which would automatically move each class to its own Java file? I think it would have to be a bit more clever than a simple regex, since you'll need to deal with nested classes, copying the imports etc.

I'm fine with any of the (nix) shell languages, and I use emacs if there's a plugin for that.

Xodarap
  • 11,581
  • 11
  • 56
  • 94

2 Answers2

2

Try Eclipse or pretty much any other Java IDE. The built-in refactoring support makes short work of moving the classes around and updating references.

Konstantin Komissarchik
  • 28,879
  • 6
  • 61
  • 61
  • Sorry to be thick, but what specifically would I do in Eclipse? I select my class in the outline, then what? I've tried all the things in the "refactor" menu and none of them seem to do what I want. – Xodarap Apr 23 '11 at 17:25
2

Something like the Eclipse Refactoring option "Convert Member Type to Top Level"?

Isaac Truett
  • 8,734
  • 1
  • 29
  • 48
  • I want something like this, but not exactly. It's not a nested class, it's top-level, but I just want to move it to a different file. Is there a way to do that in eclipse? – Xodarap Apr 23 '11 at 17:27
  • @xodarap: cut out the non-main file. Eclipse will show an error due to missing code. Click on the error's light bulb and then click on new class. Paste your code in the new class. – Hovercraft Full Of Eels Apr 23 '11 at 18:08
  • @Hovercraft: yeah, that's not really a "macro" though, more like me manually doing it. I guess it works... – Xodarap Apr 23 '11 at 18:29
  • 1
    @xodarap: yep, you're right. I don't know of any macro for Eclipse that does this, but I'm no pro. I just know what I do when the situation arises. :) – Hovercraft Full Of Eels Apr 23 '11 at 18:38
  • 1
    Have you looked through the answers to this question? http://stackoverflow.com/questions/103202/is-there-a-macro-recorder-for-eclipse – Isaac Truett Apr 23 '11 at 19:45