Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 460008

Summary: [formatter] Inserts wrong line breaks on ASTRewrite (Extract Constant, Extract Local Variable)
Product: [Eclipse Project] JDT Reporter: Markus Keller <markus.kell.r>
Component: CoreAssignee: Markus Keller <markus.kell.r>
Status: VERIFIED FIXED QA Contact:
Severity: major    
Priority: P3 CC: manoj.palat, markus.kell.r, mateusz.matela
Version: 4.5   
Target Milestone: 4.5 M6   
Hardware: All   
OS: All   
Whiteboard:
Bug Depends on: 303519    
Bug Blocks:    
Attachments:
Description Flags
FormatterTest project none

Description Markus Keller CLA 2015-02-16 06:58:48 EST
Created attachment 250823 [details]
FormatterTest project

With the formatter settings in the attached project, apply Extract Constant or Extract Local Variable to the integer literals '1' here:

public class MyTest {
	int i= 1;
	
	{
		if (hashCode() == 1) {
			
		}
	}
}

Result has too many line breaks:

public class MyTest {
	private static final int _1= 1;

	int i= _1
;
	
	{
		int j= 1;

		if (hashCode() == j
) {
			
		}
	}
}
Comment 1 Markus Keller CLA 2015-02-16 11:58:27 EST
The problem is that the the formatter now appends a line break when formatting CodeFormatter.K_EXPRESSION, K_STATEMENTS, and K_CLASS_BODY_DECLARATIONS kinds when "insert_new_line_at_end_of_file_if_missing" is set to "insert".

This bug makes refactorings unusable when that option is enabled. I'll fix it for tomorrow's I-build.
Comment 3 Markus Keller CLA 2015-02-23 07:56:41 EST
Verified in I20150217-0800.