Bug 75460 - [formatting] Java code snippet formatting only applied to Javadoc
Summary: [formatting] Java code snippet formatting only applied to Javadoc
Status: RESOLVED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 3.3 RC4   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 97202 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-10-01 11:03 EDT by Hansgeorg Schwibbe CLA
Modified: 2007-06-22 12:48 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 Hansgeorg Schwibbe CLA 2004-10-01 11:03:06 EDT
I tried to format the following code:
/*
            Object[] objects = new Object[3];
            objects[0] = new String("Hallo Welt !!!");
            objects[1] = new String("Test !!!");
            objects[2] = new Integer("1980");
            ObjectFile.write(pathname, objects);
            Object[] objs = ObjectFile.read(pathname);
            for(int i = 0; i < objs.length; i++)
            {
              System.out.println(objs[i].toString());
            }
*/

and got the following code:
/*
 * Object[] objects = new Object[3]; objects[0] = new String("Hallo Welt !!!");
 * objects[1] = new String("Test !!!"); objects[2] = new Integer("1980");
 * ObjectFile.write(pathname, objects); Object[] objs = ObjectFile.read(pathname);
 * for(int i = 0; i < objs.length; i++) { System.out.println(objs[i].toString()); }
 */

Im not sure that commented source code should be formated in a javadoc format.
Comment 1 Dani Megert CLA 2004-10-04 10:40:10 EDT
Two problems:
1) the format Java code snippets is in the general section of the prefs but only
applied to Javadoc
2) we should offer different settings for end of line, block and Javadoc
comments. This is already reported in bug 49412.

FYI:
If you have code inside a comment you should mark it as
<pre>
</pre>
and it will be formatted like code (if chosen in the formatter preferences).
Comment 2 Dani Megert CLA 2005-10-10 12:41:49 EDT
Ownership changed.
Comment 3 Olivier Thomann CLA 2007-02-01 13:31:50 EST
(In reply to comment #1)
> Two problems:
> 1) the format Java code snippets is in the general section of the prefs but only applied to Javadoc
We might want to put it in a section related to block and javadoc formatting.
I don't think it should apply to line comments.
I am working on getting bug 49412 fixed.
Comment 4 Dani Megert CLA 2007-02-02 04:56:34 EST
>I don't think it should apply to line comments.
Agree.
Comment 5 Olivier Thomann CLA 2007-02-02 10:06:38 EST
With the fix for bug 49412, we put the formatting of the code snippet inside the javadoc section.
Also you can now disable formatting for the block comment. So we can keep formatting of code snippets inside javadoc only using a <pre></pre> tag.
Does this sound reasonable?
Daniel, any thought?
Comment 6 Olivier Thomann CLA 2007-02-02 10:17:58 EST
This means that if formatting of block comments is disabled, the case in comment 0 would be left as is. The only possible change would be the indentation of the lines in the comment, but no more line wrapping.
Comment 7 Dani Megert CLA 2007-02-02 10:35:30 EST
Sounds good. The only thing what I always missed is
- that I cannot use <code></code>
- that the preference doesn't tell how to mark a Java code snippet (Benno fixes
  that one)
Comment 8 Olivier Thomann CLA 2007-02-02 10:42:47 EST
(In reply to comment #7)
> Sounds good. The only thing what I always missed is
> - that I cannot use <code></code>
What do you mean?
Using <code></code> to insert a code snippet?
or using <code></code> to insert a code snippet inside block comment ?
Comment 9 Dani Megert CLA 2007-02-02 11:16:17 EST
use the code tag like the pre tag (inside Javadoc)
Comment 10 Olivier Thomann CLA 2007-03-13 22:21:58 EDT
*** Bug 97202 has been marked as a duplicate of this bug. ***
Comment 11 Olivier Thomann CLA 2007-06-21 11:26:37 EDT
In 3.3, you can disable the block comment formatting.
This will preserve your existing comment layout.
Closing as WONTFIX.
No further action planned.