int position= computeCharacterPosition(line, pos, fCharacter);
int position= computeCharacterPosition(document, line, pos, fCharacter);
	public void customizeDocumentCommand(IDocument document, DocumentCommand command) {		// 0: early pruning		// also customize if <code>doit</code> is false (so it works in code completion situations)//		if (!command.doit)//			return;				if (command.text == null)			return;					if (command.text.equals(SEMICOLON))			fCharacter= SEMICHAR;		else if (command.text.equals(BRACE))			fCharacter= BRACECHAR;		else			return;						IPreferenceStore store= JavaPlugin.getDefault().getPreferenceStore();		if (fCharacter == SEMICHAR && !store.getBoolean(PreferenceConstants.EDITOR_SMART_SEMICOLON))			return;		if (fCharacter == BRACECHAR && !store.getBoolean(PreferenceConstants.EDITOR_SMART_OPENING_BRACE))			return;							IWorkbenchPage page= JavaPlugin.getActivePage();		if (page == null) return;		IEditorPart part= page.getActiveEditor(); 		if (!(part instanceof CompilationUnitEditor)) return;		CompilationUnitEditor editor= (CompilationUnitEditor)part;		if (editor.getInsertMode() != ITextEditorExtension3.SMART_INSERT || !editor.isEditable()) return;		ITextEditorExtension2 extension= (ITextEditorExtension2) editor.getAdapter(ITextEditorExtension2.class);		if (extension != null && !extension.validateEditorInputState()) return;				// 1: find concerned line / position in java code, location in statement		// TODO: use AST / Java project tree?		int pos= command.offset;		ITextSelection line;		try {			IRegion l= document.getLineInformationOfOffset(pos);			line = new TextSelection(document, l.getOffset(), l.getLength());		} catch (BadLocationException e) {			return;		}		// 2: choose action based on findings (is for-Statement?)		// TODO: adjust to use AST / Java project tree?		// for now: compute the best position to insert the new character		// but never position before the current position!		int position= computeCharacterPosition(line, pos, fCharacter);		if (position < pos)			return;				// 3: modify command		command.offset= position;		// if the character at the insert position is the same, we simply replace it		// the new caret position is right after the inserted / replaced character		int positionInLine= position - line.getOffset();		if (line.getLength() > positionInLine && line.getText().charAt(positionInLine) == fCharacter) {			command.length= 0;			command.text= ""; //$NON-NLS-1$			command.caretOffset= position + 1;		} else {			command.length= 0;			command.caretOffset= position;			if (fCharacter == BRACECHAR) {				// TODO check for formatting options				command.text= " " + BRACE;  //$NON-NLS-1$			}		}		command.doit= false;	}