Bug 233967 - [formatter] Cannot format several regions inside a comment
Summary: [formatter] Cannot format several regions inside a comment
Status: RESOLVED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 4.18 RC2   Edit
Assignee: Manoj N Palat CLA
QA Contact:
URL:
Whiteboard:
Keywords: readme
: 204091 (view as bug list)
Depends on: 234168
Blocks:
  Show dependency tree
 
Reported: 2008-05-26 11:23 EDT by Frederic Fusier CLA
Modified: 2020-11-24 23:48 EST (History)
8 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Frederic Fusier CLA 2008-05-26 11:23:35 EDT
Using 3.4RC2.

I got an IllegalArgumentException when calling CodeFormatter.format(int kind, String source, int offset, int length, int indentationLevel, String lineSeparator) method with kind equals CodeFormatter#K_JAVADOC, CodeFormatter#K_SINGLE_LINE_COMMENT or CodeFormatter#K_K_MULTI_LINE_COMMENT.

The spec says that these values are valid kinds, hence should be accepted and format the regions inside the provided comment snippet.
Comment 1 Frederic Fusier CLA 2009-06-25 09:21:22 EDT
*** Bug 241095 has been marked as a duplicate of this bug. ***
Comment 2 Frederic Fusier CLA 2009-06-25 11:41:24 EDT
*** Bug 204091 has been marked as a duplicate of this bug. ***
Comment 3 Frederic Fusier CLA 2010-02-18 04:11:27 EST
Unfortunately, this issue cannot be addressed while the formatter writes plain text for block and javadoc comments...
Comment 4 Dani Megert CLA 2011-10-24 11:39:29 EDT
Can someone please look at this for 3.8. This breaks the "format edited lines only" Save Action (bug 241095).
Comment 5 Srikanth Sankaran CLA 2011-10-24 12:14:04 EDT
Ayush, please follow up, I have set the milestone to M4 so this
is in the radar, but we may have to retarget it if needed as we
understand how much work is involved.
Comment 6 Srikanth Sankaran CLA 2011-11-20 22:12:29 EST
(In reply to comment #5)
> Ayush, please follow up, I have set the milestone to M4 so this
> is in the radar, but we may have to retarget it if needed as we
> understand how much work is involved.

I am moving this to M5 so as to allow Ayush to focus on the code review
and testing tasks associated with the null annotations work. If work on
this gets completed we can always pull it up.
Comment 7 Ayushman Jain CLA 2012-01-12 00:29:34 EST
Moving to M6.
Comment 8 Srikanth Sankaran CLA 2012-03-12 01:30:38 EDT
Ran out of time, Will look into this for M7.
Comment 9 Ayushman Jain CLA 2012-04-12 05:45:31 EDT
(In reply to comment #4)
> Can someone please look at this for 3.8. This breaks the "format edited lines
> only" Save Action (bug 241095).

Dani, I think this bug may be different. In the case of the save action, the kind is K_COMPILATION_UNIT, which is neither of the three that throw an IAE. I'll investigate a bit further and see if there's a simple fix for the save action (and also raise a new defect).
Comment 10 Dani Megert CLA 2012-04-12 08:45:01 EDT
(In reply to comment #9)
> (In reply to comment #4)
> > Can someone please look at this for 3.8. This breaks the "format edited lines
> > only" Save Action (bug 241095).
> 
> Dani, I think this bug may be different. In the case of the save action, the
> kind is K_COMPILATION_UNIT, which is neither of the three that throw an IAE.
> I'll investigate a bit further and see if there's a simple fix for the save
> action (and also raise a new defect).

Do you have a better "kind"? We can pass K_UNKNOWN if that helps, as long as the result is good :-).
Comment 11 Ayushman Jain CLA 2012-04-12 08:48:28 EDT
(In reply to comment #10)
>[..]
> Do you have a better "kind"? We can pass K_UNKNOWN if that helps, as long as
> the result is good :-).

I didn't mean the kind is wrong, I meant the kind being passed does not cause this bug (i.e. I don't see any IAE). So there must be a different bug in the formatter causing the breakage of the save action, and I'm trying to find that out. :)
Comment 12 Ayushman Jain CLA 2012-04-12 13:16:56 EDT
Dani, after some investigation I don't think that bug 241095 is a duplicate of this one at all, as I mentioned above. Secondly, I think the current behavior is a consequence of wrong adaptation of regions inside JDT/Core (Scribe.adaptRegions()), which was intentionally introduced in bug 232768. However, that bug does not seem to request that changing anything inside a comment should cause whole comment be to formatted. It rather requests the formatter to format the whole comment when too much is selected. I don't know why the fix was done this way. Dani, since you were part of the discussion, do you have more context on what went on there? I fail to see why formatter should expand the region to the complete comment when even only a word changed inside.
Comment 13 Frederic Fusier CLA 2012-04-12 14:27:10 EDT
(In reply to comment #12)
> Dani, after some investigation I don't think that bug 241095 is a duplicate of
> this one at all, as I mentioned above. Secondly, I think the current behavior
> is a consequence of wrong adaptation of regions inside JDT/Core
> (Scribe.adaptRegions()), which was intentionally introduced in bug 232768.
> However, that bug does not seem to request that changing anything inside a
> comment should cause whole comment be to formatted. It rather requests the
> formatter to format the whole comment when too much is selected. I don't know
> why the fix was done this way. Dani, since you were part of the discussion, do
> you have more context on what went on there? I fail to see why formatter should
> expand the region to the complete comment when even only a word changed inside.

My bad guys...

When rewritten the formatter to take into account comments in one pass, I missed 2 points (among others...):
1) that formatter should only replace with spaces. Hence, I thought it was better to rewrite the comment entirely formatted instead of only rewrite the spaces inside them (that was also easier... :-S)
2) the format might concern only one or several regions of the comment

The design I used make now these 2 points really difficult to reach without rewrite a part or most of the code (peculiarly for Javadoc comments).

Note two things though:
- only point 1) is really hurting. When fixed, point 2) would become obvious
- I already changed the design for line comments before I left, but I lacked time to do the same for block and Javadoc comments...

I'd say that fixing that for Block comments should be accessible, typically by doing a similar change which have been done for line comments. However, for Javadoc comments, that will take a big amount of time and, if really needed, then should be targeted for next version, not this one...

I can bring some help to understand the design of current implementation (but that was a long time ago...), however I'm afraid I won't have time to do more about this...

Sorry for that :-(

So, to workaround this issue, the solution was to select the *entire* block or Javadoc comment as soon as piece of it was select for formatting... If the rest of the comment was already formatted, user won't see any difference... If not, then it's sure that that can hurt.
Comment 14 Ayushman Jain CLA 2012-04-12 14:56:18 EDT
(In reply to comment #13)
> [..]
> My bad guys...
> 
> When rewritten the formatter to take into account comments in one pass, I
> missed 2 points (among others...):
> 1) that formatter should only replace with spaces. Hence, I thought it was
> better to rewrite the comment entirely formatted instead of only rewrite the
> spaces inside them (that was also easier... :-S)
> 2) the format might concern only one or several regions of the comment
Thanks for the explanation Frederic. :)

> The design I used make now these 2 points really difficult to reach without
> rewrite a part or most of the code (peculiarly for Javadoc comments).
> 
> Note two things though:
> - only point 1) is really hurting. When fixed, point 2) would become obvious
> - I already changed the design for line comments before I left, but I lacked
> time to do the same for block and Javadoc comments...
> 
> I'd say that fixing that for Block comments should be accessible, typically by
> doing a similar change which have been done for line comments. However, for
> Javadoc comments, that will take a big amount of time and, if really needed,
> then should be targeted for next version, not this one...
Could you point me to the bug or code which fixed the line comment formatting? I'll try to emulate it for block comments, and will ask you for clarifications if needed. Not sure if I'll be able to , but I can try fixing the block comments atleast for now, and will take care of Javadoc in 3.9.
Comment 15 Frederic Fusier CLA 2012-04-13 04:23:30 EDT
(In reply to comment #14)
> Could you point me to the bug or code which fixed the line comment formatting?
> I'll try to emulate it for block comments, and will ask you for clarifications
> if needed. Not sure if I'll be able to , but I can try fixing the block
> comments atleast for now, and will take care of Javadoc in 3.9.

The only bug I remember about this is bug 234168. I don't think I used a specific one for line comments. Unfortunately, I didn't attach any patch to that bug when I do the changes for line comments :-(

Hence, I'm afraid the only solution is to look at Scribe.java history. I hope it's still feasible despite the repository move from CVS to Git!?
Comment 16 Ayushman Jain CLA 2012-04-13 06:03:52 EDT
(In reply to comment #15)
> (In reply to comment #14)
> > Could you point me to the bug or code which fixed the line comment formatting?
> > I'll try to emulate it for block comments, and will ask you for clarifications
> > if needed. Not sure if I'll be able to , but I can try fixing the block
> > comments atleast for now, and will take care of Javadoc in 3.9.
> 
> The only bug I remember about this is bug 234168. I don't think I used a
> specific one for line comments. Unfortunately, I didn't attach any patch to
> that bug when I do the changes for line comments :-(
> 
> Hence, I'm afraid the only solution is to look at Scribe.java history. I hope
> it's still feasible despite the repository move from CVS to Git!?

While the history is still preserved, I'm not sure what to look for. The bug 234168 you mentioned is not fixed yet and I couldn't find any commit with that bug id or with any relevant comments. The last bug with comments "line comments" is bug 227043 but thats not the one we're looking for. Sigh. Probably I'll debug the code and see if I can find something.
Comment 17 Frederic Fusier CLA 2012-04-13 06:39:46 EDT
(In reply to comment #16)
> 
> While the history is still preserved, I'm not sure what to look for. The bug
> 234168 you mentioned is not fixed yet and I couldn't find any commit with that
> bug id or with any relevant comments. The last bug with comments "line
> comments" is bug 227043 but thats not the one we're looking for. Sigh. Probably
> I'll debug the code and see if I can find something.

The central point for the modification was Scribe.printLineComment(int, int), but I finally found the precise moment I fixed this for line comments:
bug 238210.

Hope that this will give you more clues...
Comment 18 Ayushman Jain CLA 2012-04-15 12:36:57 EDT
(In reply to comment #17)
> The central point for the modification was Scribe.printLineComment(int, int),
> but I finally found the precise moment I fixed this for line comments:
> bug 238210.
> 
> Hope that this will give you more clues...
Thanks for digging it up Frederic. This will help. :)
Comment 19 Ayushman Jain CLA 2012-04-15 12:38:04 EDT
Further discussion to be done on bug 241095
Comment 20 Eclipse Genie CLA 2020-06-30 09:55:48 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 21 Jay Arthanareeswaran CLA 2020-11-24 23:48:39 EST
There's not much chance of this being fixed. Hence marking accordingly.