Community
Participate
Working Groups
When I hit Ctlr+Shift+F this : final Pattern doubleSlash = Pattern.compile("\\t|\\n|\\r"); final Pattern slash = Pattern.compile("\\t|\\n|\\r"); System.out.println(slash.equals(doubleSlash)); // Prints false ! uses Object's equals - even when the patterns are identical :slash = Pattern.compile("\\t|\\n|\\r"); becomes : final Pattern doubleSlash = Pattern.compile("\\t|\\n|\\r"); final Pattern slash = Pattern.compile("\\t|\\n|\\r"); System.out.println(slash.equals(doubleSlash)); // Prints false ! uses // Object's equals - // even when the // patterns are // identical :slash = // Pattern.compile("\\t|\\n|\\r"); It should become : final Pattern doubleSlash = Pattern.compile("\\t|\\n|\\r"); final Pattern slash = Pattern.compile("\\t|\\n|\\r"); System.out.println(slash.equals(doubleSlash)); // Prints false ! uses // Object's equals - even when the patterns are identical :slash = // Pattern.compile("\\t|\\n|\\r"); Please fix this - it is a constant annoyance See also https://bugs.eclipse.org/bugs/show_bug.cgi?id=75516 for other changes in comments formatter
It's a matter of style/taste whether one wants to align those comments on the code or the comment start offset.
(In reply to comment #1) > It's a matter of style/taste whether one wants to align those comments on > the code or the comment start offset. Well yes - then solution would be to add a preference for it Although the situation is really bad when a comment starts near the line wrapping column. I mean whatever your aesthetic dispositions are this : long resetTime = operLimitStatus.getResetTimeInSeconds(); // I // had // int // and // it // overflowed // - // duh looks horrible (and is fairly common I assure you)
Sorry for double posting - what I thought also when I first saw this is that a way to treat it would be to exclude // comments from line wrapping - could be an option. Needs some discussion - ideas ?
(In reply to comment #3) > Sorry for double posting - what I thought also when I first saw this is that > a way to treat it would be to exclude // comments from line wrapping - could > be an option. Needs some discussion - ideas ? As a first step you could just disable to format them.
(In reply to comment #4) > As a first step you could just disable to format them. Not really - it is the line wrapping that I mind (when done as illustrated - when the comment is on a line on it's own it is very welcome and usually perfectly presentable). In general I need the comments formatted as anything else. And simply disabling it will break the style in several projects anyway.
Which class is responsible for formatting the comments in the jdt ? Have some difficulty finding it Thanks
(In reply to Palmer Eldritch from comment #6) > Which class is responsible for formatting the comments in the jdt ? Have > some difficulty finding it That would be org.eclipse.jdt.internal.formatter.CommentsPreparator in jdt-core. Also, org.eclipse.jdt.internal.formatter.linewrap.CommentWrapExecutor. You may find this useful to understand the formatter in general: https://github.com/mateusz-matela/eclipse.jdt.core/wiki Note that my intention while rewriting the formatter was that it would wrap the main code to leave a lot of space for the comment and minimize additional lines, for example: System.out.println(slash.equals( doubleSlash)); /* Prints false ! uses Object's equals - even * when the patterns are identical :slash = * Pattern.compile("\\t|\\n|\\r"); */ But now I see this doesn't work for line comments or when "Never join lines" option is turned on, which may be considered a bug.
Thanks a lot for feedback ! Yes when line wrapping is on it ends up turning this: someStatement(); // and a long comment that should be wrapped to: someStatement(); // and // a long // comment // that // should // be wrapped Which is a nono Should become: someStatement(); // and // a long comment that // should be wrapped (or at least some sort of preference added) Thanks again