List<TextRange> (@NotNull PsiElement rootElement, @NotNull TokenSet keywordsElementTypes) { final IElementType type = PsiUtilCore.getElementType(rootElement); if (keywordsElementTypes.contains(type)) { return Collections.singletonList(rootElement.getTextRange()); } TokenSet directChildrenTypes = getDirectChildrenElementTypes(type); List<TextRange> result = new ArrayList<>(); PsiElement currentElement = rootElement.getFirstChild(); while (currentElement != null) { IElementType currentElementType = PsiUtilCore.getElementType(currentElement); if (directChildrenTypes.contains(currentElementType)) { result.addAll(computeMarkersRanges(currentElement, keywordsElementTypes)); } currentElement = currentElement.getNextSibling(); } return result; }