MarkdownTableSeparatorRow (@NotNull Project project, @NotNull String text) { final var columnsCount = StringUtil.countChars(text, '|') - 1; if (columnsCount < 1) { throw new IllegalArgumentException("Passed separator text should be valid and contain at least one column.\n Text passed: [" + text + "]"); } final var builder = new StringBuilder(); builder.append("|"); for (var column = 0; column < columnsCount; column += 1) { builder.append(" |"); } builder.append('\n'); builder.append(text); final var file = createFile(project, builder.toString()); final var table = PsiTreeUtil.getParentOfType(file.findElementAt(0), MarkdownTable.class); if (table == null) { final var psi = DebugUtil.psiToString(file, true, true); throw new IllegalStateException("Failed to find table. PSI:\n" + psi); } final var separatorRowElement = PsiTreeUtil.getChildOfType(table, MarkdownTableSeparatorRow.class); if (separatorRowElement == null) { final var psi = DebugUtil.psiToString(file, true, true); throw new IllegalStateException("Failed to find separator row. PSI:\n" + psi); } return separatorRowElement; }