2

Eclipse has a powerful code formatter for Java, but I am wondering whether it is possible to define a code format on a per file basis, instead of defining the format for all java files?

Thanks!

3
  • Can you explain how this might be useful?
    – Karan
    Mar 31, 2013 at 17:08
  • Well, for example you could use some code from vendor, which uses a different coding style. But sometimes you may need to modify it a little bit. @Karan
    – xuhdev
    Apr 24, 2013 at 18:56
  • Well Eclipse is going to format as Java based on the file extension, so one possible way might be to rename the ones you want a different/custom format for to some other extension, then define your desired formatting rules for files with that new extension. Of course, changing extensions quite likely will cause issues, so I don't know how else one might do this without undesirable side-effects. Perhaps if there's a way to make Eclipse select different formatting rules based on some unique string inside the Java files. Maybe there's a plugin that does this...
    – Karan
    Apr 24, 2013 at 20:22

1 Answer 1

0

Don't know how to specify a formatter per-file, but there is at least a way to selectively turn formatter off so it doesn't mess up existing formatting, see here:

In short, you can configure Eclipse to look for comments like @formatter:on and @formatter:off, details here.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .