views:

414

answers:

4

I remember seeing in either IntelliJ or Eclipse the setting to reformat (cleanup) files whenever they are saved. How do I find it (didn't find it in the settings)

A: 

I thought there was something like that in IntelliJ, but I can't find it. The only clean-up that happens at save is that white space at the ends of lines is removed. I thought I had to specify that behavior at one point, but I don't see anything related at this point.

PanCrit
+2  A: 

I set it to automatically clean up on check-in, which is usually good enough for me. If something is too ugly, I'll just hit the shortcut (Ctrl-Alt-L, Return). And I see they have an option for auto-formatting pasted code, although I've never used that.

William Pietri
A: 

Ctrl + Alt + L is format file (includes the two below)

Ctrl + Alt + O is optimize imports

Ctrl + Alt + I will fix indentation on a particular line

I usually run Ctrl + Alt + L a few times before committing my work. I'd rather it do the cleanup/reformatting at my command instead of automatically.

joeslice
A: 

To configure Eclipse to format the code on save:

  • Properties on you project (File -> properties)
  • Java Editor (or what type of code you edit)
  • Save actions

Choose whether to configure for project or workspace.

stefan