java, eclipse, code style, formatter settings profile

75 views
Skip to first unread message

Guenther Grau

unread,
Apr 25, 2013, 5:54:18 PM4/25/13
to zx...@googlegroups.com
Hi,

I'm using eclipse for my zxing development and wonder if anyone has defined a formatting profile (preference->java->code style/formatter) which matches the zxing formatting style. I've tried several settings but all of them result in formatting changes if applied to the existing sources. It would be great if someone could share their settings (and also update the existing source formatting if it is inconsistent).

Best regards,

  Guenther

Sean Owen

unread,
Apr 25, 2013, 6:40:24 PM4/25/13
to zx...@googlegroups.com
I use IntelliJ, but, the formatting rule I use is pretty much summarized by: "2 spaces to indent". The rest is just standard old Sun style and you can get a sense of it just by looking at the rest of the code. 
It's not hard to fix on my side. I will look at your changes tomorrow.

Guenther Grau

unread,
Apr 25, 2013, 7:09:51 PM4/25/13
to zx...@googlegroups.com
Hi Sean,

yeah, the 2 spaces to indent bit is easy. The problem is wrapping. What is the maximum line length which is not wrapped?

Sometimes parameters and expressions are wrapped, sometimes they are not.

  private static void addArgumentToInputs(String argument, Config config, Queue<String> inputs) throws IOException {
  private static void writeResultImage(int stride, int height, int[] pixels, URI uri, String inputName, String suffix) {

vs

  private static int[] findGuardPattern(BitMatrix matrix,
                                        int column,
                                        int row,
                                        int width,
                                        boolean whiteFirst,
                                        int[] pattern,
                                        int[] counters) {

Wrapping for array constants doesn't seem to match the wrapping rules of the other lines.

Eclipse likes to add a few spaces here and there, e.g.   {0x1025e vs  { 0x1025e. Same for generics Map<DecodeHintType,Object> vs Map<DecodeHintType, Object>.

A few files have more than one blank lines between methods.

Some lines have extra spaces at the end (Ok, I can turn a check for that off, but I don't think lines should have extra spaces at the end).

It would make my life easier if we could agree on sth. that is configurable in eclipse and IntelliJ and then reformat the existing sources consistently.

Best regards,

  Guenther

Sean Owen

unread,
Apr 26, 2013, 4:52:23 AM4/26/13
to zx...@googlegroups.com
I wrap at 120 columns, and then tend to wrap things like long declarations like you show. For everything else... maybe there's a certain logic but it's kind of made up. Just wrap however seems to make sense.

I tend to write Foo<X,Y> not Foo<X, Y> but I don't care.

Removing dead spaces is fine but I wouldn't put it in a patch if it's avoidable, just for clarity. I think IntelliJ cleans that up on edited lines only.

Guenther Grau

unread,
Apr 26, 2013, 5:12:15 AM4/26/13
to zx...@googlegroups.com
ok, I'll set wrapping to 120 columns. I've found a setting for the spaces for generics and array initializers.

I'm trying to not include white space changes in my patches (I removed most of them in my last patch, only very few were left in), but I'd like my code to be auto formatted. Therefore I'm looking for a setting which keeps the format as closely to the existing one as possible. If I succeed, then I'll submit a formatting patch and maybe even an eclipse formatting setting config file that other eclipse using contributors can use.

Best regards,

  Guenther
Reply all
Reply to author
Forward
0 new messages