int[] (char[] text, int start, int end, IElementType token) { if (token == null) return null; Commenter commenter = LanguageCommenters.INSTANCE.forLanguage(token.getLanguage()); if (!(commenter instanceof CodeDocumentationAwareCommenter cdaCommenter)) return null; if (token.equals(cdaCommenter.getLineCommentTokenType())) { String prefix = cdaCommenter.getLineCommentPrefix(); if (prefix != null) prefix = prefix.stripTrailing(); // some commenters (e.g. for Python) include space in comment prefix if (isValidSuffixOrPrefix(prefix) && CharArrayUtil.regionMatches(text, start, end, prefix)) { return new int[]{Math.min(end, CharArrayUtil.shiftForward(text, start + prefix.length(), WHITESPACE_CHARS)), end}; } } else if (token.equals(cdaCommenter.getBlockCommentTokenType())) { String prefix = cdaCommenter.getBlockCommentPrefix(); String suffix = cdaCommenter.getBlockCommentSuffix(); if (!isValidSuffixOrPrefix(prefix) || !isValidSuffixOrPrefix(suffix)) return null; int[] result = new int[]{start, end}; boolean hasPrefixOrSuffix = false; if (CharArrayUtil.regionMatches(text, start, end, prefix)) { result[0] = start + prefix.length(); hasPrefixOrSuffix = true; } if (CharArrayUtil.regionMatches(text, end - suffix.length(), end, suffix)) { result[1] = end - suffix.length(); hasPrefixOrSuffix = true; } if (hasPrefixOrSuffix && result[0] < result[1]) { result[0] = Math.min(result[1], CharArrayUtil.shiftForward(text, result[0], WHITESPACE_CHARS)); result[1] = Math.max(result[0], CharArrayUtil.shiftBackward(text, result[1] - 1, WHITESPACE_CHARS) + 1); return result; } } return null; }