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
IRegion rightParenthesisToken= getToken(document, new Region(sourceOffset, sourceLength), ITerminalSymbols.TokenNameRPAREN);
					makeBlock(document, command, replace, thenRegion, nextRegion, rightParenthesisToken, elseStatement != null);
					break;
				}
				if (elseStatement == null || elseStatement.getNodeType() == ASTNode.BLOCK)
					return;
				
				if (offset >= elseToken.getOffset() + elseToken.getLength() && offset + length <= elseRegion.getOffset())
					makeBlock(document, command, replace, createRegion(elseStatement, delta), nextRegion, elseToken, false);
			}
			break;
		case ASTNode.WHILE_STATEMENT:
		case ASTNode.FOR_STATEMENT:
			{
				Expression expression= node.getNodeType() == ASTNode.WHILE_STATEMENT
					? ((WhileStatement) node).getExpression()
					: ((ForStatement) node).getExpression();
				Statement body= node.getNodeType() == ASTNode.WHILE_STATEMENT
					? ((WhileStatement) node).getBody()
					: ((ForStatement) node).getBody();
				Statement nextStatement= getNextStatement((Statement) node);
				if (expression == null || body == null || body.getNodeType() == ASTNode.BLOCK)
					return;
				IRegion expressionRegion= createRegion(expression, delta);
				IRegion bodyRegion= createRegion(body, delta);
				IRegion nextRegion= createRegion(nextStatement, delta);
				
				int sourceOffset= expressionRegion.getOffset() + expressionRegion.getLength();
				int sourceLength= bodyRegion.getOffset() - sourceOffset;
				IRegion rightParenthesisToken= getToken(document, new Region(sourceOffset, sourceLength), ITerminalSymbols.TokenNameRPAREN);