DialogBuilder dialogBuilder = new DialogBuilder(project);
dialogBuilder.setTitle("Formatting Block structure");
final String text = editor != null ? editor.getDocument().getText() : "";
final CodeStyleSettings settings = CodeStyleSettingsManager.getInstance(project).getCurrentSettings();
MathematicaFormattingModelBuilder modelBuilder = new MathematicaFormattingModelBuilder();
final PsiFile file = PsiFileFactory.getInstance(project).createFileFromText("a.m", MathematicaLanguage.INSTANCE, text);
final FormattingModel model = modelBuilder.createModel(file.getNode().getPsi(), settings);
final Block rootBlock = model.getRootBlock();
final String blockText = printBlock((AbstractBlock) rootBlock, text);