int (int line) { CharSequence docChars = myDocument.getCharsSequence(); for (int lineBefore = line - 1; lineBefore >= 0; lineBefore --) { if (!containsWhitespacesOnly(docChars, myDocument.getLineStartOffset(lineBefore), myDocument.getLineEndOffset(lineBefore))) { return lineBefore; } } return -1; }