Skip to content

io microsphere annotation processor FilerProcessor

github-actions[bot] edited this page Mar 21, 2026 · 1 revision

FilerProcessor

Type: Class | Module: microsphere-annotation-processor | Package: io.microsphere.annotation.processor | Since: 1.0.0

Source: microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/FilerProcessor.java

Overview

A processor class that provides safe and exception-handled operations for interacting with the Filer in an annotation processing environment. This class wraps calls to the underlying Filer instance obtained from the provided ProcessingEnvironment, 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;
    }
);

Declaration

public class FilerProcessor

Author: Mercy

Version Information

  • Introduced in: 1.0.0
  • Current Project Version: 0.1.10-SNAPSHOT

Version Compatibility

This component is tested and compatible with the following Java versions:

Java Version Status
Java 8 ✅ Compatible
Java 11 ✅ Compatible
Java 17 ✅ Compatible
Java 21 ✅ Compatible
Java 25 ✅ Compatible

Examples

// 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;
    }
);

Usage

Maven Dependency

Add the following dependency to your pom.xml:

<dependency>
    <groupId>io.github.microsphere-projects</groupId>
    <artifactId>microsphere-annotation-processor</artifactId>
    <version>${microsphere-java.version}</version>
</dependency>

Tip: Use the BOM (microsphere-java-dependencies) for consistent version management. See the Getting Started guide.

Import

import io.microsphere.annotation.processor.FilerProcessor;

API Reference

Public Methods

Method Description
processInFiler
processInFiler
getJavaFileManager Get the JavaFileManager

See Also

  • #processInFiler(ThrowableFunction)
  • #processInFiler(ThrowableFunction, BiFunction)

This documentation was auto-generated from the source code of microsphere-java.

Home

java-annotations

java-core

jdk-tools

lang-model

annotation-processor

java-test

Clone this wiki locally