// Path: stag-library-compiler/src/main/java/com/vimeo/stag/processor/utils/logging/DebugLog.java
// public final class DebugLog {
// 
//     private static final String TAG = "Stag";
//     @Nullable
//     private static Logger sLogger;
// 
//     private DebugLog() {
//         throw new UnsupportedOperationException("This class is not instantiable");
//     }
// 
//     /**
//      * Initialize the log utils with the logging instance.
//      *
//      * @param logger the logging instance, if null is provided, logging will result in a crash.
//      */
//     public static void initialize(@Nullable Logger logger) {
//         sLogger = logger;
//     }
// 
//     @NotNull
//     private static Logger safeLogger() {
//         if (sLogger == null) {
//             throw new IllegalStateException("initialize must be called first");
//         }
//         return sLogger;
//     }
// 
//     /**
//      * Log the provided message with the default log tag "Stag"
//      *
//      * @param message the message to log.
//      */
//     public static void log(@Nullable CharSequence message) {
//         safeLogger().log(TAG + ": " + message);
//     }
// 
//     /**
//      * Log the provided message with an additional log tag.
//      *
//      * @param tag     the tag to add to the log.
//      * @param message the message to log.
//      */
//     public static void log(@NotNull CharSequence tag, @Nullable CharSequence message) {
//         safeLogger().log(TAG + ":" + tag + ": " + message);
//     }
// 
// }


import java.io.Closeable;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.Writer;
import java.util.List;
import javax.annotation.processing.Filer;
import javax.lang.model.element.Element;
import javax.tools.FileObject;
import javax.tools.JavaFileObject;
import javax.tools.StandardLocation;
import com.squareup.javapoet.CodeBlock;
import com.squareup.javapoet.JavaFile;
import com.vimeo.stag.processor.utils.logging.DebugLog;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
    public static void writeToFile(@NotNull JavaFile file, @NotNull Filer filer) throws IOException {
        String fileName =
                file.packageName.isEmpty() ? file.typeSpec.name : file.packageName + '.' + file.typeSpec.name;
        List<Element> originatingElements = file.typeSpec.originatingElements;
        JavaFileObject filerSourceFile = filer.createSourceFile(fileName, originatingElements.toArray(
                new Element[originatingElements.size()]));
        filerSourceFile.delete();
        Writer writer = null;
        try {
            writer = filerSourceFile.openWriter();
            file.writeTo(writer);
        } catch (Exception e) {
            try {
                filerSourceFile.delete();
            } catch (Exception ignored) {
            }
            throw e;
        } finally {
            close(writer);
        }
    }

    @Nullable
    static CharSequence readResource(@NotNull Filer filer, @NotNull String generatedPackageName,
                                     @NotNull String resourceName) throws IOException {
        try {
            FileObject file =
                    filer.getResource(StandardLocation.CLASS_OUTPUT, generatedPackageName, resourceName);
            return file.getCharContent(false);
        } catch (FileNotFoundException e) {
// Path: stag-library-compiler/src/main/java/com/vimeo/stag/processor/utils/logging/DebugLog.java
// public final class DebugLog {
// 
//     private static final String TAG = "Stag";
//     @Nullable
//     private static Logger sLogger;
// 
//     private DebugLog() {
//         throw new UnsupportedOperationException("This class is not instantiable");
//     }
// 
//     /**
//      * Initialize the log utils with the logging instance.
//      *
//      * @param logger the logging instance, if null is provided, logging will result in a crash.
//      */
//     public static void initialize(@Nullable Logger logger) {
//         sLogger = logger;
//     }
// 
//     @NotNull
//     private static Logger safeLogger() {
//         if (sLogger == null) {
//             throw new IllegalStateException("initialize must be called first");
//         }
//         return sLogger;
//     }
// 
//     /**
//      * Log the provided message with the default log tag "Stag"
//      *
//      * @param message the message to log.
//      */
//     public static void log(@Nullable CharSequence message) {
//         safeLogger().log(TAG + ": " + message);
//     }
// 
//     /**
//      * Log the provided message with an additional log tag.
//      *
//      * @param tag     the tag to add to the log.
//      * @param message the message to log.
//      */
//     public static void log(@NotNull CharSequence tag, @Nullable CharSequence message) {
//         safeLogger().log(TAG + ":" + tag + ": " + message);
//     }
// 
// }


// Path: stag-library-compiler/src/main/java/com/vimeo/stag/processor/utils/FileGenUtils.java
import java.io.Closeable;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.Writer;
import java.util.List;
import javax.annotation.processing.Filer;
import javax.lang.model.element.Element;
import javax.tools.FileObject;
import javax.tools.JavaFileObject;
import javax.tools.StandardLocation;
import com.squareup.javapoet.CodeBlock;
import com.squareup.javapoet.JavaFile;
import com.vimeo.stag.processor.utils.logging.DebugLog;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

    public static void writeToFile(@NotNull JavaFile file, @NotNull Filer filer) throws IOException {
        String fileName =
                file.packageName.isEmpty() ? file.typeSpec.name : file.packageName + '.' + file.typeSpec.name;
        List<Element> originatingElements = file.typeSpec.originatingElements;
        JavaFileObject filerSourceFile = filer.createSourceFile(fileName, originatingElements.toArray(
                new Element[originatingElements.size()]));
        filerSourceFile.delete();
        Writer writer = null;
        try {
            writer = filerSourceFile.openWriter();
            file.writeTo(writer);
        } catch (Exception e) {
            try {
                filerSourceFile.delete();
            } catch (Exception ignored) {
            }
            throw e;
        } finally {
            close(writer);
        }
    }

    @Nullable
    static CharSequence readResource(@NotNull Filer filer, @NotNull String generatedPackageName,
                                     @NotNull String resourceName) throws IOException {
        try {
            FileObject file =
                    filer.getResource(StandardLocation.CLASS_OUTPUT, generatedPackageName, resourceName);
            return file.getCharContent(false);
        } catch (FileNotFoundException e) {
            DebugLog.log("Resource not found: " + resourceName);