Bug 52115 - [formatting] Distinction between Javadoc and Comment in formatter
Summary: [formatting] Distinction between Javadoc and Comment in formatter
Status: VERIFIED DUPLICATE of bug 49412
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: All All
: P3 enhancement with 6 votes (vote)
Target Milestone: 3.3 M5   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 55809 102784 154473 167834 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-02-15 20:54 EST by Joakim Erdfelt CLA
Modified: 2007-03-20 11:03 EDT (History)
10 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Joakim Erdfelt CLA 2004-02-15 20:54:01 EST
I'd like to see some kind of distinction between a Javadoc comment.

/** 
 * Construct a new <code>Foo</code> Object.
 */

and a non-javadoc comment in the formatter preferences.

/* typical code comment. */
// more of the same.

non-javadoc code comments can contain preformatted text and whatnot, but
wrapping them with HTML <pre> or <code> would be pointless as it's not
processed by the javadoc program (or ant task, or maven goal).

A simple checkbox "ignore non-javadoc comments" would be sufficient.

Idea: non-javadoc comment formatting could be limited to the max line 
width wrapping, while leaving new lines and spacing etc intact. 
(But I would guess that this would make things complicated.)
Comment 1 Dani Megert CLA 2004-02-16 03:25:00 EST
We should reconsider the bundling of comment formatting.
Comment 2 Dani Megert CLA 2004-03-24 06:25:01 EST
*** Bug 55809 has been marked as a duplicate of this bug. ***
Comment 3 David Witherspoon CLA 2005-05-18 11:28:21 EDT
I'd like to chime in. I have some code that must remain commented out except
during specific testing:

   /* Uncomment this code, as well as the call from init() to enable a socket-
      based command listener for testing */
   /*
   private void listenForCommands()
   {
      ServerSocket s = null;
      PrintStream out;
      s = new ServerSocket(888);
      System.out.println("Command listener is on port + getLocalPort());
      while (true)
      and so on...
   */

After I format, I get:
   /*
    * private void listenForCommands() { ServerSocket s = null; PrintStream out;
    * s = new ServerSocket(888); System.out.println("Command listener is
    * on port " + s.getLocalPort()); while (true) { Socket socket = s.accept();
    * out = new PrintStream(socket.getOutputStream()); out
    * .println("MessageDispatcher command listener awaits your bidding...");

So then I tried the approach of toggling the comment:

   /* Uncomment this code, as well as the call from init() to enable a socket-
      based command listener for testing */
//   
//    private void listenForCommands()
//    {
//       ServerSocket s = null;
//       PrintStream out;
//       s = new ServerSocket(888);
//       System.out.println("Command listener is on port " + s.getLocalPort());
//       while (true)
//       and so on

But then if I format the source, I get:

   /*
    * Uncomment this code, as well as the call from init() to enable a
    * socket-based command listener for testing
    */
   //   
   // private void listenForCommands()
   // {
   // ServerSocket s = null;
   // PrintStream out;
   // s = new ServerSocket(888);
   // System.out.println("Command listener is on port " + s.getLocalPort());
   //          while (true)

and all the leading white space/indention is collapsed.

So yes, I'd second a way to handle this sort of thing. 
Comment 4 Dani Megert CLA 2005-06-16 06:23:10 EDT
Resetting priority to P3. Will be reassessed for the next release.
Comment 5 Dani Megert CLA 2005-10-10 12:13:55 EDT
Ownership changed.
Comment 6 Gunnar Wagenknecht CLA 2006-04-20 09:06:58 EDT
I also like to see this feature addressed. The comment formatter is such a nice feature. But I's like to use it on for JavaDoc comments only. All other comments should not be formated.
Comment 7 James Kelley CLA 2006-05-04 16:54:16 EDT
I too would like this addressed.  It has been floating around Bugzilla in one form or another since 2003 and keeps getting rediscovered with each version by new users who find even new twists on how treating non-javadoc comments as if they were javadoc is messing them up.  (compiler directives and template settings being the big ones)

Block (/* */) and Line (//) comments almost never conform to the markup restrictions and formatting schemes that javadoc implies and uses.  They should be their own options or preferably not be javadoc formatted at all. 

A possible mid-term fix would be giving us a command line switch to just disable the formatting of non-Javadoc (/** */ comments in a session.

List of related issues in Bugzilla (ignoring ones marked dup):
49412  2003-12-30 [formatting] Offer comment formatting options per comment type
75516  2004-10-02 [formatting] Proposed comments formatting changes
75460  2004-10-01 [formatting] Java code snippet formatting only applied to Javadoc
102784 2005-07-05 Distinction between Javadoc and comment formatting
Comment 8 Dani Megert CLA 2006-08-22 02:32:39 EDT
*** Bug 154473 has been marked as a duplicate of this bug. ***
Comment 9 Piotr Wolny CLA 2006-09-15 07:24:12 EDT
This BUG is still present in Eclipse 3.2 and is very annoying because it practically makes the code formatter unusable for me - "destroying" my non-javadoc comments. Please address this issue ASAP.
Comment 10 Olivier Thomann CLA 2006-12-14 10:51:41 EST
*** Bug 102784 has been marked as a duplicate of this bug. ***
Comment 11 Olivier Thomann CLA 2006-12-14 10:52:25 EST
*** Bug 167834 has been marked as a duplicate of this bug. ***
Comment 12 John Ferguson CLA 2007-02-06 05:48:14 EST
I'd just like to second the previous comment. I would like to format multiple Java files at once, but because each of my files has a block comment at the top (our copyright notice) I cannot do it (the block comment is messed up by the formatter). Note: This happens EVEN IF COMMENT FORMATTING IS DISABLED!
A fix would be much appreciated! Thank you!
Comment 13 Andreas Zimmer CLA 2007-02-06 06:25:10 EST
Just to retain a requirement detail from Bug #102784, which has been marked as duplicate of this bug:

When this feature will be provided and COMMENT formatting can 
then be switched off independently from Javadoc formatting, the COMMENTS shall 
then really NOT BE TOUCHED AT ALL, even not with regard to indentation or 
other beautyfying. This is even true for such obvious things like inserting 
blanks in a comment like '/*comment*/' (--> '/* comment */') because we use 
simple comments for our code generator tags (like '/*>*/' and other similar 
ones) and such tags shall NOT BE TOUCHED by a formatter.
Comment 14 Olivier Thomann CLA 2007-02-06 08:35:25 EST
Not adjusting the indentation can result in really weird formatting.
What should happen if the initial indentation of the block comment is wrong?
Comment 15 Olivier Thomann CLA 2007-02-06 08:36:53 EST
(In reply to comment #12)
> A fix would be much appreciated! Thank you!
A patch would also be much appreciated :-).
Comment 16 Andreas Zimmer CLA 2007-02-06 10:30:03 EST
(In reply to comment #14)
> Not adjusting the indentation can result in really weird formatting.
> What should happen if the initial indentation of the block comment is wrong?
> 
What means wrong? Because there are no common rules how block comments may be aligned with surrounding code, right or wrong very much depends on the intention of the developer who wrote the comment, doesn't it? Otherwise more sophisticated options for the formatting of block comments may be required. So I would see two possibilities: Either just have an option to say "Don't format block comments" and then really don't format them at all (even no indentation), or introducing some more sophisticated options like "format block comment indentation yes/no" and so on.

What is most important to us, is NOT to fill in or leave out blanks for reasons of beautyfying. So, for example, "/*comment*/" shall NOT be re-formatted to "/* comment */". 
Comment 17 Andreas Zimmer CLA 2007-03-11 17:10:00 EDT
Is there an outlook, in which version this case will be finally adressed? We (as well as other users) are continuously struggling with this problem and it has a history now since February 2004 (!).  
Comment 18 Olivier Thomann CLA 2007-03-11 20:43:04 EDT
Since 3.3M5, it is possible to make the distinction between javadoc, block and single line comments.
So this might be a dup of the bug fixed for 3.3M5.
Did someone try the 3.3M5 build with regards to this issue?
Comment 19 Andreas Zimmer CLA 2007-03-12 05:27:23 EDT
(In reply to comment #18)
Thank you for the quick response. We've not yet installed and tried 3.3M5. We'll definitely have an immediate look at this (highly appreciated) new feature, when we move to 3.3. B.t.w. - when is 3.3 official release to be expected? I've briefly searched on the eclipse site for roadmap information, but did not find it (so far). Is there a page where road map information is provided? 

Comment 20 Dani Megert CLA 2007-03-12 06:01:21 EDT

*** This bug has been marked as a duplicate of bug 49412 ***
Comment 21 Dani Megert CLA 2007-03-12 06:04:05 EDT
>Is there a page where road map information is provided? 
http://wiki.eclipse.org/index.php/Europa_Simultaneous_Release#Milestones_and_Release_Candidates
Comment 22 Frederic Fusier CLA 2007-03-19 06:10:22 EDT
Set target as 3.3 M6 to verify this bug...
Please put back it to 3.3 M5 after the verification, thanks
Comment 23 Olivier Thomann CLA 2007-03-20 11:03:11 EDT
Set target to 3.3M5.