Bug 322180 - [formatter] Won't reformat a Java file with extra blank lines
Summary: [formatter] Won't reformat a Java file with extra blank lines
Status: VERIFIED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.7   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.7 M2   Edit
Assignee: Frederic Fusier CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-09 15:37 EDT by Michael Murphree CLA
Modified: 2010-09-14 05:51 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Murphree CLA 2010-08-09 15:37:11 EDT
Build Identifier: 20100617-1415

If some Java code has been written to be doublespaced (a blank line between every line of text) the Java formatter will not reformat the code at all.

There is no error message, the code simply does not change.  Nothing is written to the .log file either.

Reproducible: Always

Steps to Reproduce:
1. Create a simply Java class like HelloWorld with extra blank lines:

package com.blah;

public class Main

{

	/**
	 * @param args
	 */
	public static void main(String[] args)

	{

		System.out.println("Format me!");

	}

}


2. Right-click in editor, choose Source > Format
3. Observe that the code is not reformatted to the Eclipse default format as expected.

This behavior can be reproduced if a single method is selected, if the entire text is selected or if there is no selection.
Comment 1 Michael Murphree CLA 2010-08-09 15:38:10 EDT
Once the extra blank lines are removed, the formatter will make the appropriate corrections.
Comment 2 Frederic Fusier CLA 2010-08-09 16:55:37 EDT
I'll investigate
Comment 3 Frederic Fusier CLA 2010-08-10 09:18:06 EDT
This is not a bug. This is due to the fact that the "Eclipse [built-in]" profile preserve 1 empty line by default. Hence, all blank lines you have in your sample a preserved by default and make the formatted code indentical than the original.

To avoid this, just change the value of 'Number of empty lines to preserve' from 1 to 0. You'll find it on the "Blank lines" tab when creating or modifying a formatter profile from the "Java" > "Code Style" > "Formatter" preference page.

As this is the expected behavior, close this bug as invalid.
Comment 4 Michael Murphree CLA 2010-08-10 10:42:38 EDT
Thanks for the correction.  That does what I was looking for.

Perhaps we could add an "Ignore blank lines for brace placement option" at some point.
Comment 5 Satyam Kandula CLA 2010-09-14 05:50:14 EDT
(In reply to comment #4)
> Thanks for the correction.  That does what I was looking for.
> 
> Perhaps we could add an "Ignore blank lines for brace placement option" at some
> point.
There are already many options -- don't want any more!
Comment 6 Satyam Kandula CLA 2010-09-14 05:51:13 EDT
Verified for 3.7M2