接口 FormatterService
public interface FormatterService
A stable facade for palantir-java-format. The implementation must be ServiceLoaded, to ensure its classpath remains
isolated.
-
方法概要
修饰符和类型方法说明fixImports(String input) Fixes imports (eg. ordering, spacing, and removal of unused import statements).Formats an input string (a Java compilation unit), reflows strings and fixes imports.default StringformatSourceReflowStringsAndFixImports(String input, FormatContext context) Formats an input string using additional per-file context when available.com.google.common.collect.ImmutableList<Replacement> getFormatReplacements(String input, Collection<com.google.common.collect.Range<Integer>> ranges) Emit a list ofReplacements to convert from input to formatted output.
-
方法详细资料
-
getFormatReplacements
com.google.common.collect.ImmutableList<Replacement> getFormatReplacements(String input, Collection<com.google.common.collect.Range<Integer>> ranges) throws FormatterException Emit a list ofReplacements to convert from input to formatted output.- 参数:
input- the input compilation unitranges- 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
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 stringcontext- per-file formatting context- 返回:
- the output string
- 抛出:
FormatterException- if the input string cannot be parsed
-
fixImports
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
-