String (@NotNull String regexp, @NotNull Project project) { return ReadAction.compute(() -> { List<PsiElement> topLevelRegExpChars = getTopLevelRegExpChars("a", project); if (topLevelRegExpChars.size() != 1) return " "; // leave only top level regExpChars Class<?> regExpCharPsiClass = topLevelRegExpChars.get(0).getClass(); return getTopLevelRegExpChars(regexp, project) .stream() .map(psi -> { if (regExpCharPsiClass.isInstance(psi)) { String text = psi.getText(); if (!text.startsWith("\\")) return text; } return " "; }) .collect(Collectors.joining()); }); }