CompletionData (final Editor editor, final CharSequence charsSequence) { final int offset = editor.getCaretModel().getOffset(); final CompletionData data = new CompletionData(); processWords(editor, Math.max(offset - 1, 0), new TokenProcessor() { @Override public boolean processToken(int start, int end) { if (start > offset) { return false; } if (end >= offset) { data.myPrefix = charsSequence.subSequence(start, offset).toString(); data.startOffset = start; return false; } return true; } }); if (data.myPrefix == null) { data.myPrefix = ""; data.startOffset = offset; } return data; }