TextRange (@NotNull PsiElement comment, @NotNull String text) { Language language = comment.getLanguage(); Commenter commenter = LanguageCommenters.INSTANCE.forLanguage(language); if (commenter == null) { return null; } for (String prefix : commenter.getLineCommentPrefixes()) { if (StringUtil.startsWith(text, prefix)) { return new TextRange(prefix.length(), text.length()); } } String blockCommentPrefix = commenter.getBlockCommentPrefix(); if (blockCommentPrefix != null && StringUtil.startsWith(text, blockCommentPrefix)) { String suffix = commenter.getBlockCommentSuffix(); int endOffset = text.length() - (suffix != null && StringUtil.endsWith(text, blockCommentPrefix.length(), text.length(), suffix) ? suffix.length() : 0); return new TextRange(blockCommentPrefix.length(), endOffset); } return null; }