Package com.diffplug.spotless
Interface FormatterFunc.Closeable
- All Superinterfaces:
AutoCloseable,FormatterFunc
- Enclosing interface:
- FormatterFunc
Function<String, String> and BiFunction<String, File, String> whose implementation
requires a resource which should be released when the function is no longer needed.-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfacestatic interfaceNested classes/interfaces inherited from interface com.diffplug.spotless.FormatterFunc
FormatterFunc.Closeable, FormatterFunc.NeedsFile -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()static <T extends AutoCloseable>
FormatterFunc.Closeableof(T resource, FormatterFunc.Closeable.ResourceFunc<T> function) Creates aFormatterFunc.Closeablewhich uses the given resource to execute the format function.static <T extends AutoCloseable>
FormatterFunc.Closeableof(T resource, FormatterFunc.Closeable.ResourceFuncNeedsFile<T> function) Creates aFormatterFunc.Closeablewhich uses the given resource to execute the file-dependent format function.static FormatterFunc.CloseableofDangerous(AutoCloseable closeable, FormatterFunc function) Dangerous way to create aFormatterFunc.Closeablefrom an AutoCloseable and a function.Methods inherited from interface com.diffplug.spotless.FormatterFunc
apply, apply, lint
-
Method Details
-
close
void close()- Specified by:
closein interfaceAutoCloseable
-
ofDangerous
Dangerous way to create aFormatterFunc.Closeablefrom an AutoCloseable and a function.It's important for FormatterStep's to allocate their resources as lazily as possible. It's easy to create a resource inside the state, and not realize that it may not be released. It's far better to use one of the non-deprecated
of()methods below.The bug (and its fix) which is easy to write using this method: https://github.com/diffplug/spotless/commit/7f16ecca031810b5e6e6f647e1f10a6d2152d9f4 How the
of()methods below make the correct thing easier to write and safer: https://github.com/diffplug/spotless/commit/18c10f9c93d6f18f753233d0b5f028d5f0961916 -
of
static <T extends AutoCloseable> FormatterFunc.Closeable of(T resource, FormatterFunc.Closeable.ResourceFunc<T> function) Creates aFormatterFunc.Closeablewhich uses the given resource to execute the format function. -
of
static <T extends AutoCloseable> FormatterFunc.Closeable of(T resource, FormatterFunc.Closeable.ResourceFuncNeedsFile<T> function) Creates aFormatterFunc.Closeablewhich uses the given resource to execute the file-dependent format function.
-