@Test public void formatShouldReformatText() throws Exception { getApplication().invokeAndWait(() -> { final Formatter underTest = new Formatter(fileFactory, JsonFileType.INSTANCE); final String actual = underTest.format("{\"key\":\"value\",\"array\":[\"foo\",\"bar\"]}"); assertThat(actual) .isEqualTo("{\n \"key\": \"value\",\n \"array\": [\n \"foo\",\n \"bar\"\n ]\n}"); }); }
@NotNull @CheckReturnValue public String format(@Nonnull String text) { final String name = Extensions.append(NAME, fileType); final PsiFile file = fileFactory.createFileFromText(name, fileType, text); final CodeStyleManager styleManager = CodeStyleManager.getInstance(file.getProject()); styleManager.reformat(file); return file.getText(); }
Formatter { @NotNull @CheckReturnValue public String format(@Nonnull String text) { final String name = Extensions.append(NAME, fileType); final PsiFile file = fileFactory.createFileFromText(name, fileType, text); final CodeStyleManager styleManager = CodeStyleManager.getInstance(file.getProject()); styleManager.reformat(file); return file.getText(); } }
Formatter { @NotNull @CheckReturnValue public String format(@Nonnull String text) { final String name = Extensions.append(NAME, fileType); final PsiFile file = fileFactory.createFileFromText(name, fileType, text); final CodeStyleManager styleManager = CodeStyleManager.getInstance(file.getProject()); styleManager.reformat(file); return file.getText(); } Formatter(@Nonnull PsiFileFactory fileFactory, @Nonnull FileType fileType); }
Formatter { @NotNull @CheckReturnValue public String format(@Nonnull String text) { final String name = Extensions.append(NAME, fileType); final PsiFile file = fileFactory.createFileFromText(name, fileType, text); final CodeStyleManager styleManager = CodeStyleManager.getInstance(file.getProject()); styleManager.reformat(file); return file.getText(); } Formatter(@Nonnull PsiFileFactory fileFactory, @Nonnull FileType fileType); @NotNull @CheckReturnValue String format(@Nonnull String text); }
Formatter { @NotNull @CheckReturnValue public String format(@Nonnull String text) { final String name = Extensions.append(NAME, fileType); final PsiFile file = fileFactory.createFileFromText(name, fileType, text); final CodeStyleManager styleManager = CodeStyleManager.getInstance(file.getProject()); styleManager.reformat(file); return file.getText(); } Formatter(@Nonnull PsiFileFactory fileFactory, @Nonnull FileType fileType); @NotNull @CheckReturnValue String format(@Nonnull String text);  }