Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 437063 - [formatter]Java Code Style Formatter tags not working in when included in block comments
Summary: [formatter]Java Code Style Formatter tags not working in when included in blo...
Status: RESOLVED DUPLICATE of bug 303519
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.3.2   Edit
Hardware: PC Windows 7
: P3 trivial (vote)
Target Milestone: 4.18 M3   Edit
Assignee: Mateusz Matela CLA
QA Contact:
URL:
Whiteboard: To be verified for 4.18 M3
Keywords:
Depends on:
Blocks:
 
Reported: 2014-06-10 11:07 EDT by Jay Catelli CLA
Modified: 2020-10-25 17:19 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jay Catelli CLA 2014-06-10 11:07:59 EDT
Within a current Eclipse workspace I have a project with its only Java Code Style.   As part of that Java Code Style I have the Off/On tags enabled.   The off tag is set to '@formatter:off' and the on tag is set to '@formatter:on'.   The Java Code Style also has a rule regarding Maximum line width (currently set to 100).

As part of my Java Code I have the following SVN file information surrounded by the formatter tags.

(pre save file)
/*
 * @formatter:off
 * FileURL: $HeadURL: https://xxxforge.app.xxx.com/svn/xxxxx/trunk/xxxxxxx.java_src/com/xxxxxxx/xxx/xxxxxxx/teststation/global/designpatterns/Singleton.java $
 * @formatter:on
 */

As one can imaging the FileURL is longer than 100 characters thus I would like to disable auto formatting of that line.

When I save the file Eclipse auto formats the pre save file due to Java Editor->Save Actions the FileURL in the header is not broken up into multiple lines which is undesirable and against the formatting rules.   It appears that the formatter tags are being ignored or overruled by some other setting which is undesirable.

(results of save)
/*
 * @formatter:off
 * FileURL: $HeadURL:
 * https://xxforge.app.ray.com/svn/xxxxx/trunk/xxxxxxx.java_src/com/xxxxxxx/xxx
 * /xxxxx/teststation/global/designpatterns/Singleton.java $
 * 
 * @formatter:on
 */
Comment 1 Timo Kinnunen CLA 2014-06-10 14:38:10 EDT
I looked at the code in passing while fixing bug 431532 and this is what I think is happening: the Off/On tags apply to the full comment they are found in, so in your case the whole comment first has the formatter turned off and then almost straight away the whole comment has the formatter turned back on again. So that's a no-op! Changing the formatter code to work with regions within a single comment is probably not trivial, but I'm sure a patch would always be welcome.

As a workaround, you could try switching from the block comment to using single-line comments instead.
Comment 2 Jay Catelli CLA 2014-06-10 15:55:07 EDT
(In reply to Timo Kinnunen from comment #1)
> I looked at the code in passing while fixing bug 431532 and this is what I
> think is happening: the Off/On tags apply to the full comment they are found
> in, so in your case the whole comment first has the formatter turned off and
> then almost straight away the whole comment has the formatter turned back on
> again. So that's a no-op! Changing the formatter code to work with regions
> within a single comment is probably not trivial, but I'm sure a patch would
> always be welcome.
> 
> As a workaround, you could try switching from the block comment to using
> single-line comments instead.

It workaround provided does work.
Comment 3 Erick Hagstrom CLA 2014-12-01 19:05:12 EST
(In reply to Timo Kinnunen from comment #1)
> I looked at the code in passing while fixing bug 431532 and this is what I
> think is happening: the Off/On tags apply to the full comment they are found
> in, so in your case the whole comment first has the formatter turned off and
> then almost straight away the whole comment has the formatter turned back on
> again. So that's a no-op!

The "Off/On Tags" preferences screen advertises a different reality. There it says, "- Each time the formatter sees an off tag, it disables formatting for that comment and the source after it." and "- Each time the formatter sees an on tag, it enables formatting for the source after that comment." So the Off tag is properly turning off formatting for the comment, but the On tag is not supposed to turn on formatting until after the comment.

My preference, FWIW, is for the code to do what the preferences screen says it does. That seems like reasonable behavior and doesn't run into the complexities you mention for regions (or so I would imagine).

Sorry, can't submit a patch yet. Working on getting a CLA, but it's slow going.
Comment 4 Eclipse Genie CLA 2020-09-06 17:32:58 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 5 Mateusz Matela CLA 2020-10-25 17:19:23 EDT
Just checked in 4.5 and 4.18.
This bug no longer occurs after the formatter redesign.

*** This bug has been marked as a duplicate of bug 303519 ***