Bug 32082 Creation of { } block captures first line
When creating an 'if' or 'for' block, the first line is always captured in the block. I believe this to be a fairly major bug, since it is very possible that when you are writing code you want to insert an if/for/while test into existing code, and definately /not/ end up accidentally capturing a statement. It may have been added in as an idea of productivity recently (don't recall seeing this in 2.1M3 or 4) but it really does not work. 2.1M5 Mac OS X 10.2.4 System.out.println("Before if"); System.out.println("After if"); -> System.out.println("Before if"); if (test) System.out.println("After if"); -> System.out.println("Before if"); if (test) { System.out.println("After if"); } I am reporting this as a major bug; I can't quite feel that it should be a critical bug. However, I do think it should be fixed in 2.1 rather than leaving it, because otherwise people are going to introduce a /lot/ of unneccessary coding errors without realising what is going on.
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/SmartBracesAutoEditStrategy.java
final String lineDelimiter= getLineDelimiter(document);
		final String lineIndentation= getLineIndentation(document, insertionLine, offset);
	
		final StringBuffer buffer= new StringBuffer();
		buffer.append(lineIndentation);
		buffer.append("}"); 
		buffer.append(lineDelimiter);
	
		
		int replaceOffset= document.getLineOffset(insertionLine) + document.getLineLength(insertionLine);
		addReplace(document, command, replaceOffset, 0, buffer.toString());
	}
	/**
	 * Surrounds a statement with a block.
	 */
	private void makeBlock(IDocument document, DocumentCommand command, IRegion replace, IRegion statement, IRegion nextStatement, IRegion prevStatement, boolean followingControl) throws BadLocationException {
		final int insertionLine= document.getLineOfOffset(replace.getOffset());
		final int statementLine= document.getLineOfOffset(statement.getOffset() + statement.getLength());
		final int statementLineBegin= document.getLineOfOffset(statement.getOffset());
		final String outerSpace= (prevStatement.getOffset() + prevStatement.getLength() == replace.getOffset()) ? "" : " "; 
		final String innerSpace= (replace.getOffset() + replace.getLength() == statement.getOffset()) ? "" : " "; 
		switch (statementLine - insertionLine) {
			
			case 0:
				{
					int replaceOffset= statement.getOffset() + statement.getLength();
					int replaceLength= document.getChar(replaceOffset) == ' ' ? 1 : 0; 					
					addReplace(document, command, replaceOffset, replaceLength, innerSpace + "}" + outerSpace); 
				}