Bug 12159 - Code Format is generating bogus output
Summary: Code Format is generating bogus output
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: 2.0 F2   Edit
Assignee: David Audel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 12187 16517 17626 (view as bug list)
Depends on:
Blocks:
 
Reported: 2002-03-22 15:18 EST by Eduardo Pereira CLA
Modified: 2002-06-03 12:36 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 Eduardo Pereira CLA 2002-03-22 15:18:23 EST
WorkbenchPlugin.log(
WorkbenchMessages.format("WorkspaceAction.logTitle", new Object[] {getClass
().getName(), e.getTargetException()}), 
			StatusUtil.newStatus(IStatus.ERROR, null, "foo", 
e.getTargetException())); //$NON-NLS-1$
		displayError(e.getTargetException().getMessage());
Comment 1 Eduardo Pereira CLA 2002-03-22 15:28:16 EST
Sorry Could not finish writing: Tab+Space in this bug system == Commit.

I selected the first two lines of a code that looks like:

System.out.println("Foo");
System.out.println("Foo"); //$NON-NLS-1$
System.out.println("Foo");

The comment "//$NON-NLS-1$" was added to a 3rd line. Ending up like that:

System.out.println("Foo");
System.out.println("Foo"); 
//$NON-NLS-1$ System.out.println("Foo");

PS: Change the number of columns in the format preferences so that 
System.out.println("Foo"); //$NON-NLS-1$ does not fit in a single line.
Comment 2 Olivier Thomann CLA 2002-03-22 19:09:29 EST
Which build are you using?
Comment 3 Eduardo Pereira CLA 2002-03-25 09:16:52 EST
Build 20020319
Comment 4 Olivier Thomann CLA 2002-03-25 17:19:28 EST
A workaround is to format the three lines together. The issue seems to be that the formatter is 
removing line ends at the end of the formatted string.
Comment 5 Philipe Mulet CLA 2002-03-26 17:51:48 EST
Could a bonus one be added at the end ? I have seen similar additions in UI 
code.
Comment 6 Philipe Mulet CLA 2002-04-02 02:56:08 EST
*** Bug 12187 has been marked as a duplicate of this bug. ***
Comment 7 Olivier Thomann CLA 2002-05-21 09:49:17 EDT
*** Bug 16517 has been marked as a duplicate of this bug. ***
Comment 8 Olivier Thomann CLA 2002-05-22 12:26:51 EDT
I can patch this by adding a line delimiter at the end of the output string. This doesn't fix the case 
where several line delimiters are at the end of the source that is formatted, but it solves 
problems like this one and the one in <A 
HREF="http://dev.eclipse.org/bugs/show_bug.cgi?id=16517>16517</A>.
Is this good 
enough for now? We want to revisit the whole code formatter after 2.0 anyway.
Comment 9 Olivier Thomann CLA 2002-05-22 13:09:24 EDT
Patch released. Please reopen if the new formatted source is still boggus.
Comment 10 Philipe Mulet CLA 2002-06-01 07:09:02 EDT
*** Bug 17626 has been marked as a duplicate of this bug. ***
Comment 11 David Audel CLA 2002-06-03 08:50:11 EDT
Verified.
Comment 12 Rick Goldstein CLA 2002-06-03 11:32:24 EDT
I checked in the F2 build, and there is still a small problem with this with 
respect to the end of file (see the duplicate bug 12187).  Now, the formatter 
removes all but one line termination character from the end of file, which is 
the correct behavior.  However, if there is *no* line termination character to 
start with, it will not add one.  It should, since all java lines must end with 
a line termination character, according to the language spec.  Not that the 
compilers seem to care, mind you, but, still... 
Comment 13 Philipe Mulet CLA 2002-06-03 12:19:50 EDT
Rick - the Java grammar does not mention any need for a trailing line delimitor 
at the end of a source file. What do you have in mind ?
Comment 14 Rick Goldstein CLA 2002-06-03 12:36:51 EDT
Sorry.  A cursory reading of the language spec gave me the impression that all 
lines needed to end with a line terminator.  We also have a developer here who 
was relying on that assumption and choked on code that did not have the 
terminal line terminator.  That particular issue has apparently gone away.

Reading grammars gives me a headache.

In the immortal words of Emily Litella, may she rest in peace: "Never mind."