document.replace(fStart, fEnd - fStart, finalString); } catch (BadLocationException x) {}
document.replace(start, length, finalString); } catch (BadLocationException x) {}
	public void apply(IDocument document) {		int indentationLevel= guessIndentationLevel(document, fStart);				String pattern= fTemplate.getPattern();		// interpolate		pattern= fInterpolator.interpolate(pattern, fArgumentEvaluator);				pattern= fInterpolator.interpolate(pattern, fLocalVariableEvaluator);		fCursorSelectionEvaluator.reset();		pattern= fInterpolator.interpolate(pattern, fCursorSelectionEvaluator);		// side effect: stores selection		int start= fCursorSelectionEvaluator.getStart();		if (start == -1) {			fSelectionStart= pattern.length();			fSelectionEnd= fSelectionStart;		} else {					fSelectionStart= start;			fSelectionEnd= fCursorSelectionEvaluator.getEnd();					}		boolean format= TemplatePreferencePage.useCodeFormatter();		if (format) {			CodeFormatter formatter= new CodeFormatter(JavaCore.getOptions());			formatter.setPositionsToMap(new int[] {fSelectionStart, fSelectionEnd});			formatter.setInitialIndentationLevel(indentationLevel);			pattern= formatter.formatSourceString(pattern);						int[] positions= formatter.getMappedPositions();			fSelectionStart= positions[0];			fSelectionEnd= positions[1];		} else {			CodeIndentator indentator= new CodeIndentator();			indentator.setPositionsToMap(new int[] {fSelectionStart, fSelectionEnd});			indentator.setIndentationLevel(indentationLevel);						pattern= indentator.indentate(pattern);			int[] positions= indentator.getMappedPositions();			fSelectionStart= positions[0];			fSelectionEnd= positions[1];			}		// strip indentation on first line		String finalString= trimBegin(pattern);		int charactersRemoved= pattern.length() - finalString.length();		fSelectionStart -= charactersRemoved;		fSelectionEnd -= charactersRemoved;				try {			document.replace(fStart, fEnd - fStart, finalString);		} catch (BadLocationException x) {} // ignore	}