if (problems.length != 0) return;
for (int i= 0; i != problems.length; ++i) if (problems[i].getID() == IProblem.UnmatchedBracket) return;
	private void smartBraces(IDocument document, DocumentCommand command) throws BadLocationException {		if (! JavaPlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_CLOSE_BRACES))			return;		final int offset= command.offset;		final int length= command.length;		final IRegion replace= new Region(offset, length);		CompilationUnitInfo info= getCompilationUnitForMethod(document, offset);		if (info == null)			return;					char[] buffer= info.buffer;		int delta= info.delta; // offset of buffer inside document		final CompilationUnit compilationUnit= AST.parseCompilationUnit(buffer);		// continue only if no problems exist in this method		IProblem[] problems= compilationUnit.getProblems();		if (problems.length != 0)			return;		ASTNode node= NodeFinder.perform(compilationUnit, offset - delta, length);		if (node == null)			return;		// get truly enclosing node		while (node != null && length == 0 && (offset - delta == node.getStartPosition() || offset - delta == node.getStartPosition() + node.getLength()))			node= node.getParent();		switch (node.getNodeType()) {		case ASTNode.IF_STATEMENT:			{				IfStatement ifStatement= (IfStatement) node;				Expression expression= ifStatement.getExpression();				Statement thenStatement= ifStatement.getThenStatement();				Statement elseStatement= ifStatement.getElseStatement();				Statement nextStatement= getNextStatement(ifStatement);				IRegion expressionRegion= createRegion(expression, delta);				IRegion thenRegion= createRegion(thenStatement, delta);				IRegion elseRegion= createRegion(elseStatement, delta);				IRegion nextRegion= createRegion(nextStatement, delta);				IRegion elseToken= null;				if (elseStatement != null) {					int sourceOffset= thenRegion.getOffset() + thenRegion.getLength();					int sourceLength= elseRegion.getOffset() - sourceOffset;					elseToken= getToken(document, new Region(sourceOffset, sourceLength), ITerminalSymbols.TokenNameelse);				}				// between expression and then statement				if (offset >= expressionRegion.getOffset() + expressionRegion.getLength() &&					offset + length <= thenRegion.getOffset())				{					if (thenStatement == null || thenStatement.getNodeType() == ASTNode.BLOCK)						return;					if (elseToken != null)						nextRegion= elseToken;					// search for )					int sourceOffset= expressionRegion.getOffset() + expressionRegion.getLength();					int sourceLength= thenRegion.getOffset() - sourceOffset;					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;				// between then and else and				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);				// search for )				int sourceOffset= expressionRegion.getOffset() + expressionRegion.getLength();				int sourceLength= bodyRegion.getOffset() - sourceOffset;				IRegion rightParenthesisToken= getToken(document, new Region(sourceOffset, sourceLength), ITerminalSymbols.TokenNameRPAREN);				if (offset >= expressionRegion.getOffset() + expressionRegion.getLength() && offset + length <= bodyRegion.getOffset())					makeBlock(document, command, replace, bodyRegion, nextRegion, rightParenthesisToken, false);			}			break;		case ASTNode.DO_STATEMENT:			{				DoStatement doStatement= (DoStatement) node;				Statement body= doStatement.getBody();				Expression expression= doStatement.getExpression();				Statement nextStatement= getNextStatement((Statement) node);				if (expression == null || body == null || body.getNodeType() == ASTNode.BLOCK)					return;				IRegion doRegion= createRegion(doStatement, delta);				IRegion bodyRegion= createRegion(body, delta);				IRegion expressionRegion= createRegion(expression, delta);				IRegion nextRegion= createRegion(nextStatement, delta);				int sourceOffset= bodyRegion.getOffset() + bodyRegion.getLength();				int sourceLength= expressionRegion.getOffset() - sourceOffset;				IRegion whileToken= getToken(document, new Region(sourceOffset, sourceLength), ITerminalSymbols.TokenNamewhile);				IRegion prevRegion= getToken(document, doRegion, ITerminalSymbols.TokenNamedo);				if (offset >= doRegion.getOffset() && offset + length <= bodyRegion.getOffset())					makeBlock(document, command, replace, bodyRegion, whileToken, prevRegion, true);			}			break;		default:			break;		}	}