接口 FormatterService


public interface FormatterService
A stable facade for palantir-java-format. The implementation must be ServiceLoaded, to ensure its classpath remains isolated.
  • 方法详细资料

    • getFormatReplacements

      com.google.common.collect.ImmutableList<Replacement> getFormatReplacements(String input, Collection<com.google.common.collect.Range<Integer>> ranges) throws FormatterException
      Emit a list of Replacements to convert from input to formatted output.
      参数:
      input - the input compilation unit
      ranges - the character ranges to reformat
      返回:
      a list of Replacements, sorted from low index to high index, without overlaps
      抛出:
      FormatterException - if the input string cannot be parsed
    • formatSourceReflowStringsAndFixImports

      String formatSourceReflowStringsAndFixImports(String input) throws FormatterException
      Formats an input string (a Java compilation unit), reflows strings and fixes imports.

      Fixing imports includes ordering, spacing, and removal of unused import statements.

      参数:
      input - the input string
      返回:
      the output string
      抛出:
      FormatterException - if the input string cannot be parsed
    • formatSourceReflowStringsAndFixImports

      default String formatSourceReflowStringsAndFixImports(String input, FormatContext context) throws FormatterException
      Formats an input string using additional per-file context when available.

      The default implementation preserves the existing formatter behaviour. Implementations must not apply type-sensitive formatting rules unless the supplied context contains enough information to resolve the current source path to a source-set context and perform type attribution.

      参数:
      input - the input string
      context - per-file formatting context
      返回:
      the output string
      抛出:
      FormatterException - if the input string cannot be parsed
    • fixImports

      String fixImports(String input) throws FormatterException
      Fixes imports (eg. ordering, spacing, and removal of unused import statements).
      参数:
      input - the input string
      返回:
      the output string
      抛出:
      FormatterException - if the input string cannot be parsed