if (isSmartTrigger) { DocumentCommand cmd= new DocumentCommand() { };  cmd.offset= referenceOffset; cmd.length= 0; cmd.text= Character.toString(trigger); cmd.doit= true; cmd.shiftsCaret= true; cmd.caretOffset= fReplacementOffset + fCursorPosition;  SmartSemicolonAutoEditStrategy strategy= new SmartSemicolonAutoEditStrategy(IJavaPartitions.JAVA_PARTITIONING); strategy.customizeDocumentCommand(document, cmd);  replace(document, cmd.offset, cmd.length, cmd.text); setCursorPosition(cmd.caretOffset - fReplacementOffset + cmd.text.length()); }
	public void apply(IDocument document, char trigger, int offset) {		try {			// patch replacement length			int delta= offset - (fReplacementOffset + fReplacementLength);			if (delta > 0)				fReplacementLength += delta;						String string;			if (trigger == (char) 0) {				string= fReplacementString;			} else {				StringBuffer buffer= new StringBuffer(fReplacementString);				// fix for PR #5533. Assumes that no eating takes place.				if ((fCursorPosition > 0 && fCursorPosition <= buffer.length() && buffer.charAt(fCursorPosition - 1) != trigger)) {					buffer.insert(fCursorPosition, trigger);					++fCursorPosition;				}								string= buffer.toString();			}			// reference position just at the end of the document change.			int referenceOffset= fReplacementOffset + fReplacementLength;			final ReferenceTracker referenceTracker= new ReferenceTracker();			referenceTracker.preReplace(document, referenceOffset);			replace(document, fReplacementOffset, fReplacementLength, string);			referenceOffset= referenceTracker.postReplace(document);						fReplacementOffset= referenceOffset - (string == null ? 0 : string.length());			if (fTextViewer != null && string != null) {				int index= string.indexOf("()"); //$NON-NLS-1$				if (index != -1 && index + 1 == fCursorPosition) {					IPreferenceStore preferenceStore= JavaPlugin.getDefault().getPreferenceStore();					if (preferenceStore.getBoolean(PreferenceConstants.EDITOR_CLOSE_BRACKETS)) {						int newOffset= fReplacementOffset + fCursorPosition;												LinkedPositionGroup group= new LinkedPositionGroup();						group.addPosition(new LinkedPosition(document, newOffset, 0, LinkedPositionGroup.NO_STOP));												LinkedModeModel model= new LinkedModeModel();						model.addGroup(group);						model.forceInstall();												LinkedModeUI ui= new EditorLinkedModeUI(model, fTextViewer);						ui.setSimpleMode(true);						ui.setExitPolicy(new ExitPolicy(')'));						ui.setExitPosition(fTextViewer, newOffset + 1, 0, Integer.MAX_VALUE);						ui.setCyclingMode(LinkedModeUI.CYCLE_NEVER);						ui.enter();					}				}			}		} catch (BadLocationException x) {			// ignore		}			}