Community
Participate
Working Groups
N20101021-2000. Format regions does not format as expected. Test Case 1: 1. paste the following snippet into Package Explorer package test1; class A { int i; } 2. enable to format edited lines on save 3. delete the space before "A {" 4. delete the space before "i;" 5. save ==> "class A {" is not aligned at column 1 Test Case 2: public void testFormatFieldDeclWithExtraWhitespace() throws Exception { StringBuffer buf= new StringBuffer(); buf.append("package test1;\n"); buf.append(" class A {\n"); buf.append(" int i;\n"); buf.append("}\n"); String contents= buf.toString(); String formatString1= " class A {"; String formatString2= " int i;"; IRegion[] regions= new Region[] { new Region(contents.indexOf(formatString1), formatString1.length()), new Region(contents.indexOf(formatString2), formatString2.length()) }; TextEdit edit= ToolFactory.createCodeFormatter(null, ToolFactory.M_FORMAT_EXISTING).format((CodeFormatter.K_COMPILATION_UNIT | CodeFormatter.F_INCLUDE_COMMENTS), contents, regions, 0, "\n"); assertNotNull(edit); Document doc= new Document(contents); edit.apply(doc); String formatted= doc.get(); buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("class A {\n"); buf.append(" int i;\n"); buf.append("}\n"); String expected= buf.toString(); assertEqualString(formatted, expected); }
Created attachment 183937 [details] Proposed patch This was just a small glitch while adapting edits at region edges: when there's no spaces before the region and nothing to replace (i.e. all new lines before the region already matches those that the edit string contains), then the replacement string needed to be flushed...
Released for 3.7M4 in HEAD stream.
Verified in N20101128-2000 and HEAD.