String (String text) { int caretIndex = text.indexOf(CARET_TOKEN); if (caretIndex < 0) { return text; } if (text.indexOf(CARET_TOKEN, caretIndex + 1) >= 0) { fail(String.format("Invalid indentation test 'before' text - it contains more than one caret meta-token (%s). Text: %n%s", CARET_TOKEN, text)); } myTextRange = new TextRange(caretIndex, caretIndex); return text.substring(0, caretIndex) + text.substring(caretIndex + CARET_TOKEN.length()); }