From eb43facd4d83aa289d2ccfeff0a3929be30e683b Mon Sep 17 00:00:00 2001 From: Liam Miller-Cushon Date: Mon, 1 Dec 2025 00:57:00 -0800 Subject: [PATCH] Create a FormattingFiler factory that disables formatting during header compilation PiperOrigin-RevId: 838646724 --- .../java/filer/FormattingFiler.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/core/src/main/java/com/google/googlejavaformat/java/filer/FormattingFiler.java b/core/src/main/java/com/google/googlejavaformat/java/filer/FormattingFiler.java index 2f2e33cbe..f5cc7fd09 100644 --- a/core/src/main/java/com/google/googlejavaformat/java/filer/FormattingFiler.java +++ b/core/src/main/java/com/google/googlejavaformat/java/filer/FormattingFiler.java @@ -20,6 +20,7 @@ import java.io.IOException; import javax.annotation.processing.Filer; import javax.annotation.processing.Messager; +import javax.annotation.processing.ProcessingEnvironment; import javax.lang.model.element.Element; import javax.tools.FileObject; import javax.tools.JavaFileManager; @@ -38,8 +39,25 @@ public final class FormattingFiler implements Filer { private final Messager messager; /** + * Create a new {@link FormattingFiler}. + * + * @param processingEnv the processing environment + */ + public static Filer create(ProcessingEnvironment processingEnv) { + Filer delegate = processingEnv.getFiler(); + if (processingEnv.getOptions().containsKey("experimental_turbine_hjar")) { + return delegate; + } + return new FormattingFiler(delegate, processingEnv.getMessager()); + } + + /** + * Create a new {@link FormattingFiler}. + * * @param delegate filer to decorate + * @deprecated prefer {@link #create(ProcessingEnvironment)} */ + @Deprecated public FormattingFiler(Filer delegate) { this(delegate, null); } @@ -50,7 +68,9 @@ public FormattingFiler(Filer delegate) { * * @param delegate filer to decorate * @param messager to log warnings to + * @deprecated prefer {@link #create(ProcessingEnvironment)} */ + @Deprecated public FormattingFiler(Filer delegate, @Nullable Messager messager) { this.delegate = checkNotNull(delegate); this.messager = messager;