Class FilerProcessor
- java.lang.Object
-
- io.microsphere.annotation.processor.FilerProcessor
-
public class FilerProcessor extends java.lang.Object
A processor class that provides safe and exception-handled operations for interacting with theFiler
in an annotation processing environment. This class wraps calls to the underlyingFiler
instance obtained from the providedProcessingEnvironment
, ensuring robust resource handling and simplifying error management through functional interfaces.It supports executing operations on the
Filer
using a callback model, allowing custom logic to be applied while handling exceptions gracefully using provided handlers.Example Usage
// Creating an instance of FilerProcessor FilerProcessor filerProcessor = new FilerProcessor(processingEnv); // Using processInFiler to create a source file filerProcessor.processInFiler(filer -> { JavaFileObject file = filer.createSourceFile("com.example.GeneratedClass"); try (Writer writer = file.openWriter()) { writer.write("// Auto-generated class\npublic class GeneratedClass {}"); } return null; }); // Using processInFiler with a custom exception handler filerProcessor.processInFiler( filer -> { JavaFileObject file = filer.createSourceFile("com.example.AnotherGeneratedClass"); try (Writer writer = file.openWriter()) { writer.write("// Auto-generated class\npublic class AnotherGeneratedClass {}"); } return null; }, (filer, e) -> { System.err.println("Failed to generate file: " + e.getMessage()); return null; } );
- Since:
- 1.0.0
- Author:
- Mercy
- See Also:
processInFiler(ThrowableFunction)
,processInFiler(ThrowableFunction, BiFunction)
-
-
Constructor Summary
Constructors Constructor Description FilerProcessor(javax.annotation.processing.ProcessingEnvironment processingEnv)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description javax.tools.JavaFileManager
getJavaFileManager()
Get theJavaFileManager
<T> T
processInFiler(ThrowableFunction<javax.annotation.processing.Filer,T> filerCallback)
<T> T
processInFiler(ThrowableFunction<javax.annotation.processing.Filer,T> filerCallback, java.util.function.BiFunction<javax.annotation.processing.Filer,java.lang.Throwable,T> exceptionHandler)
-
-
-
Method Detail
-
processInFiler
public <T> T processInFiler(ThrowableFunction<javax.annotation.processing.Filer,T> filerCallback)
-
processInFiler
public <T> T processInFiler(ThrowableFunction<javax.annotation.processing.Filer,T> filerCallback, java.util.function.BiFunction<javax.annotation.processing.Filer,java.lang.Throwable,T> exceptionHandler)
-
getJavaFileManager
public javax.tools.JavaFileManager getJavaFileManager()
Get theJavaFileManager
- Returns:
- the
JavaFileManager
-
-