// Path: jackdaw-apt/src/main/java/com/github/vbauer/jackdaw/code/context/CodeGeneratorContext.java
// public final class CodeGeneratorContext {
// 
//     private final TypeElement typeElement;
//     private final String packageName;
// 
// 
//     private CodeGeneratorContext(final TypeElement typeElement, final String packageName) {
//         this.typeElement = typeElement;
//         this.packageName = packageName;
//     }
// 
// 
//     public static CodeGeneratorContext create(final TypeElement typeElement) {
//         Validate.notNull(typeElement, "Type element must be defined");
// 
//         final String packageName = ProcessorUtils.packageName(typeElement);
//         return new CodeGeneratorContext(typeElement, packageName);
//     }
// 
// 
//     public TypeElement getTypeElement() {
//         return typeElement;
//     }
// 
//     public String getPackageName() {
//         return packageName;
//     }
// 
//     public String getClassName(final Function<String, String> nameModifier) {
//         return nameModifier.apply(TypeUtils.getName(getTypeElement()));
//     }
// 
// }


import com.github.vbauer.jackdaw.code.base.CodeGenerator;
import com.github.vbauer.jackdaw.code.context.CodeGeneratorContext;
import com.github.vbauer.jackdaw.util.MessageUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import javax.lang.model.element.TypeElement;
import java.util.Collection;
package com.github.vbauer.jackdaw.code;



/**
 * @author Vladislav Bauer
 */

public final class SourceCodeGenerator {

    private SourceCodeGenerator() {
        throw new UnsupportedOperationException();
    }


    public static boolean generate(
        final String annotationClassName, final Collection<TypeElement> elements
    ) {
        try {
            final CodeGenerator generator = SourceCodeGeneratorRegistry.find(annotationClassName);
            generator.onStart();

            for (final TypeElement element : elements) {
                generate(generator, element);
            }
            generator.onFinish();
            return true;
        } catch (final Exception ex) {
            MessageUtils.error(ExceptionUtils.getMessage(ex));
            return false;
        }
    }


    private static void generate(
        final CodeGenerator generator, final TypeElement element
    ) throws Exception {
        final Class<? extends CodeGenerator> generatorClass = generator.getClass();
        final String generatorName = generatorClass.getSimpleName();

        MessageUtils.note(String.format("Detected %s on %s", generatorName, element));
// Path: jackdaw-apt/src/main/java/com/github/vbauer/jackdaw/code/context/CodeGeneratorContext.java
// public final class CodeGeneratorContext {
// 
//     private final TypeElement typeElement;
//     private final String packageName;
// 
// 
//     private CodeGeneratorContext(final TypeElement typeElement, final String packageName) {
//         this.typeElement = typeElement;
//         this.packageName = packageName;
//     }
// 
// 
//     public static CodeGeneratorContext create(final TypeElement typeElement) {
//         Validate.notNull(typeElement, "Type element must be defined");
// 
//         final String packageName = ProcessorUtils.packageName(typeElement);
//         return new CodeGeneratorContext(typeElement, packageName);
//     }
// 
// 
//     public TypeElement getTypeElement() {
//         return typeElement;
//     }
// 
//     public String getPackageName() {
//         return packageName;
//     }
// 
//     public String getClassName(final Function<String, String> nameModifier) {
//         return nameModifier.apply(TypeUtils.getName(getTypeElement()));
//     }
// 
// }


// Path: jackdaw-apt/src/main/java/com/github/vbauer/jackdaw/code/SourceCodeGenerator.java
import com.github.vbauer.jackdaw.code.base.CodeGenerator;
import com.github.vbauer.jackdaw.code.context.CodeGeneratorContext;
import com.github.vbauer.jackdaw.util.MessageUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import javax.lang.model.element.TypeElement;
import java.util.Collection;

package com.github.vbauer.jackdaw.code;



/**
 * @author Vladislav Bauer
 */

public final class SourceCodeGenerator {

    private SourceCodeGenerator() {
        throw new UnsupportedOperationException();
    }


    public static boolean generate(
        final String annotationClassName, final Collection<TypeElement> elements
    ) {
        try {
            final CodeGenerator generator = SourceCodeGeneratorRegistry.find(annotationClassName);
            generator.onStart();

            for (final TypeElement element : elements) {
                generate(generator, element);
            }
            generator.onFinish();
            return true;
        } catch (final Exception ex) {
            MessageUtils.error(ExceptionUtils.getMessage(ex));
            return false;
        }
    }


    private static void generate(
        final CodeGenerator generator, final TypeElement element
    ) throws Exception {
        final Class<? extends CodeGenerator> generatorClass = generator.getClass();
        final String generatorName = generatorClass.getSimpleName();

        MessageUtils.note(String.format("Detected %s on %s", generatorName, element));
        generator.generate(CodeGeneratorContext.create(element));