{ final String lineDelimiter= getLineDelimiter(document); final String lineIndentation= getLineIndentation(document, insertionLine, replace.getOffset());  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()); }
	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 String outerSpace= (prevStatement.getOffset() + prevStatement.getLength() == replace.getOffset()) ? "" : " "; //$NON-NLS-1$ //$NON-NLS-2$		final String innerSpace= (replace.getOffset() + replace.getLength() == statement.getOffset()) ? "" : " "; //$NON-NLS-1$ //$NON-NLS-2$		switch (statementLine - insertionLine) {			// same line			case 0:				{					int replaceOffset= statement.getOffset() + statement.getLength();					int replaceLength= document.getChar(replaceOffset) == ' ' ? 1 : 0; // eat existing space										addReplace(document, command, replaceOffset, replaceLength, innerSpace + "}" + outerSpace); //$NON-NLS-1$				}				break;			// more lines:			default:				// statement is too far away				break;			// next line			case 1:				final String lineDelimiter= getLineDelimiter(document);				final String lineIndentation= getLineIndentation(document, insertionLine, replace.getOffset());				final StringBuffer buffer= new StringBuffer();				if (nextStatement == null) {					buffer.append(lineDelimiter);					buffer.append(lineIndentation);					buffer.append("}"); //$NON-NLS-1$					// at end of line to skip a possible comment					IRegion region= document.getLineInformation(statementLine);					addReplace(document, command, region.getOffset() + region.getLength(), 0, buffer.toString());				} else {					final int nextStatementLine=document.getLineOfOffset(nextStatement.getOffset());					if (statementLine == nextStatementLine) {						int replaceOffset= statement.getOffset() + statement.getLength();						int replaceLength= document.getChar(replaceOffset) == ' ' ? 1 : 0; // eat existing space						addReplace(document, command, replaceOffset, replaceLength, innerSpace + "}" + outerSpace); //$NON-NLS-1$											} else {						if (followingControl && JavaCore.DO_NOT_INSERT.equals(JavaCore.getOption(JavaCore.FORMATTER_NEWLINE_CONTROL))) {							addReplace(document, command, nextStatement.getOffset(), 0, "}" + outerSpace); //$NON-NLS-1$						} else {							buffer.append(lineDelimiter);							buffer.append(lineIndentation);							buffer.append("}"); //$NON-NLS-1$							// at end of line to skip a possible comment							IRegion region= document.getLineInformation(statementLine);							addReplace(document, command, region.getOffset() + region.getLength(), 0, buffer.toString());						}					}				}				break;		}	}