int (int line) { CharSequence docChars = myDocument.getCharsSequence(); for (int lineAfter = line + 1; lineAfter < myDocument.getLineCount(); lineAfter ++) { if (!containsWhitespacesOnly(docChars, myDocument.getLineStartOffset(lineAfter), myDocument.getLineEndOffset(lineAfter))) { return lineAfter; } } return -1; }