Bug 12321 - Code formatter and comments
Summary: Code formatter and comments
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 3.0 M4   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-03-26 16:48 EST by Pascal Rapicault CLA
Modified: 2003-10-13 09:18 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Pascal Rapicault CLA 2002-03-26 16:48:16 EST
The following code formats correctly. 
However if you add a comment at the end of the 6th line and then format the
code, the result is very strange.

public class ttt {

	public static void main() {
		if (true)
			if (false)
				System.out.println("meuh");
			else
				System.out.println("coucou");
		else {
			System.out.println("bar");
		}
	}
}

    PaScaL
Comment 1 Pascal Rapicault CLA 2002-03-27 07:22:38 EST
The comment needs to be added at the end of the line : 
   System.out.println("meuh");
Comment 2 Philipe Mulet CLA 2002-04-02 02:57:15 EST
Will consider post 2.0
Comment 3 Philipe Mulet CLA 2002-07-25 06:59:45 EDT
Reopening
Comment 4 Philipe Mulet CLA 2002-07-25 07:01:03 EDT
Clearing resolution
Comment 5 jean-louis willems CLA 2002-09-01 11:37:12 EDT
The cause of the problem is that 'clearNonBlockIndents' is reset during the use 
of the comment token in the format method from CodeFormatter.

A solution is to exclude comment tokens from the condition that protect the 
removing of all indentations made by statements not followed by a block
except if the current token is ELSE, CATCH or if we are in a switch/case

The proposal is to update the line 365 in the version from eclipse 2.0.1
from
    if (clearNonBlockIndents && (token != Scanner.TokenNameWHITESPACE)) {
to
    if (clearNonBlockIndents && (token != Scanner.TokenNameWHITESPACE) 
	&& (token != TokenNameCOMMENT_BLOCK)
    	&& (token != TokenNameCOMMENT_JAVADOC)
        && (token != TokenNameCOMMENT_LINE	)) {
Comment 6 Olivier Thomann CLA 2003-01-15 13:23:15 EST
We need to clear 2.1 bug reports that won't be addressed before 2.1. The new 
implementation is still in the works. Therefore we cannot include it for 2.1. 
Not enough testing and we need to polish the preferences. This will be address 
for 2.2 as stated in the JDT/Core plan.
Comment 7 Philipe Mulet CLA 2003-06-12 06:36:09 EDT
Resurrecting for 3.0
Comment 8 Olivier Thomann CLA 2003-06-12 15:58:58 EDT
Reopen for 3.0 consideration.
Comment 9 Olivier Thomann CLA 2003-10-03 09:49:33 EDT
This is addressed in the new formatter.
Fixed and released in HEAD.
Regression test added.
Comment 10 David Audel CLA 2003-10-13 09:18:48 EDT
Verified.