public void apply(IDocument document, char trigger, int offset) { try {  int delta= offset - (getReplacementOffset() + getReplacementLength()); if (delta > 0) setReplacementLength(getReplacementLength() + delta);  boolean isSmartTrigger= isSmartTrigger(trigger);  String replacement; if (isSmartTrigger || trigger == (char) 0) { replacement= getReplacementString(); } else { StringBuffer buffer= new StringBuffer(getReplacementString());   if ((getCursorPosition() > 0 && getCursorPosition() <= buffer.length() && buffer.charAt(getCursorPosition() - 1) != trigger)) { buffer.insert(getCursorPosition(), trigger); setCursorPosition(getCursorPosition() + 1); }  replacement= buffer.toString(); setReplacementString(replacement); }   int referenceOffset= getReplacementOffset() + getReplacementLength(); final ReferenceTracker referenceTracker= new ReferenceTracker(); referenceTracker.preReplace(document, referenceOffset);  replace(document, getReplacementOffset(), getReplacementLength(), replacement);  referenceOffset= referenceTracker.postReplace(document); setReplacementOffset(referenceOffset - (replacement == null ? 0 : replacement.length()));   if (isSmartTrigger) handleSmartTrigger(document, trigger, referenceOffset);  } catch (BadLocationException x) {  }
public final void apply(IDocument document) {  apply(document, (char) 0, getReplacementOffset() + getReplacementLength());
	public void apply(IDocument document, char trigger, int offset) {		try {			// patch replacement length			int delta= offset - (getReplacementOffset() + getReplacementLength());			if (delta > 0)				setReplacementLength(getReplacementLength() + delta);				boolean isSmartTrigger= isSmartTrigger(trigger);				String replacement;			if (isSmartTrigger || trigger == (char) 0) {				replacement= getReplacementString();			} else {				StringBuffer buffer= new StringBuffer(getReplacementString());					// fix for PR #5533. Assumes that no eating takes place.				if ((getCursorPosition() > 0 && getCursorPosition() <= buffer.length() && buffer.charAt(getCursorPosition() - 1) != trigger)) {					buffer.insert(getCursorPosition(), trigger);					setCursorPosition(getCursorPosition() + 1);				}					replacement= buffer.toString();				setReplacementString(replacement);			}				// reference position just at the end of the document change.			int referenceOffset= getReplacementOffset() + getReplacementLength();			final ReferenceTracker referenceTracker= new ReferenceTracker();			referenceTracker.preReplace(document, referenceOffset);				replace(document, getReplacementOffset(), getReplacementLength(), replacement);				referenceOffset= referenceTracker.postReplace(document);			setReplacementOffset(referenceOffset - (replacement == null ? 0 : replacement.length()));				// PR 47097			if (isSmartTrigger)				handleSmartTrigger(document, trigger, referenceOffset);			} catch (BadLocationException x) {			// ignore		}	}