// Path: egtest-annotations/src/main/java/com/vocalabs/egtest/annotation/EgLanguage.java
// public enum EgLanguage {
//     /** Use the default language specified at a higher level, typically JAVA. */
//     INHERIT,
//     /** Java, copied verbatim into test code. */
//     JAVA,
// 
//     /**
//      * Produce Groovy embedded in Java. May produce simple Java rather than embedding a Groovy interpreter for simple
//      * cases such as primitives.
//      */
//     GROOVY,
// 
//     /** Produce Kotlin source code within Kotlin source files. Can't be mixed with JAVA or GROOVY within a file. */
//     KOTLIN
// }
// 
// Path: egtest-processor/src/main/java/com/vocalabs/egtest/processor/data/DefaultLanguageReader.java
// public class DefaultLanguageReader implements AnnotationReader<EgItem<EgDefaultLanguage>> {
// 
//     public static final DefaultLanguageReader INSTANCE = new DefaultLanguageReader();
// 
//     @Override
//     public Set<Class<? extends Annotation>> supportedAnnotationClasses() {
//         return Collections.singleton(EgDefaultLanguage.class);
//     }
// 
//     @Override
//     public List<EgItem<EgDefaultLanguage>> examples(Annotation annotation, Element element, MessageHandler messageHandler) {
//         return Collections.singletonList(new Item(element, (EgDefaultLanguage) annotation));
//     }
// 
//     public static class Item implements EgItem<EgDefaultLanguage> {
//         private final Element element;
//         private final EgDefaultLanguage language;
// 
//         public Item(Element element, EgDefaultLanguage language) {
//             this.language = language;
//             this.element = element;
//         }
// 
//         @Override
//         public EgDefaultLanguage getAnnotation() {
//             return language;
//         }
// 
//         @Override
//         public Element getElement() {
//             return element;
//         }
//     }
// }
// 
// Path: egtest-processor/src/main/java/com/vocalabs/egtest/processor/data/EgItem.java
// public interface EgItem<T extends Annotation> {
//     T getAnnotation();
//     Element getElement();
// }


import com.vocalabs.egtest.annotation.EgLanguage;
import com.vocalabs.egtest.processor.data.DefaultLanguageReader;
import com.vocalabs.egtest.processor.data.EgItem;
import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.NestingKind;
import javax.lang.model.element.TypeElement;
import javax.lang.model.type.DeclaredType;
import java.util.*;
        Element classEl = data.getElement();
        if (classEl.getKind().equals(ElementKind.CLASS)) {
            EgLanguage language = ((DefaultLanguageReader.Item)data).getAnnotation().value();
            languageForClassName.put(className(classEl), language);
        }
        else {
            messageHandler.error("Can't set default language except on Class: "+classEl);
        }
    }

    public static String className(Element classEl) {
        DeclaredType dt = (DeclaredType) classEl.asType();
        TypeElement te = (TypeElement) dt.asElement();

        if ( ! allowedNesting(te.getNestingKind())) {
            throw new IllegalArgumentException("EgTest doesn't support local and anonymous classes: "+classEl);
        }
        return te.getQualifiedName().toString();
    }

    private static boolean allowedNesting(NestingKind nk) {
        switch (nk) {
            case TOP_LEVEL: return true;
            case MEMBER:    return true;
            case LOCAL:     return false;
            case ANONYMOUS: return false;
            default:        return false;
        }
    }

// Path: egtest-annotations/src/main/java/com/vocalabs/egtest/annotation/EgLanguage.java
// public enum EgLanguage {
//     /** Use the default language specified at a higher level, typically JAVA. */
//     INHERIT,
//     /** Java, copied verbatim into test code. */
//     JAVA,
// 
//     /**
//      * Produce Groovy embedded in Java. May produce simple Java rather than embedding a Groovy interpreter for simple
//      * cases such as primitives.
//      */
//     GROOVY,
// 
//     /** Produce Kotlin source code within Kotlin source files. Can't be mixed with JAVA or GROOVY within a file. */
//     KOTLIN
// }
// 
// Path: egtest-processor/src/main/java/com/vocalabs/egtest/processor/data/DefaultLanguageReader.java
// public class DefaultLanguageReader implements AnnotationReader<EgItem<EgDefaultLanguage>> {
// 
//     public static final DefaultLanguageReader INSTANCE = new DefaultLanguageReader();
// 
//     @Override
//     public Set<Class<? extends Annotation>> supportedAnnotationClasses() {
//         return Collections.singleton(EgDefaultLanguage.class);
//     }
// 
//     @Override
//     public List<EgItem<EgDefaultLanguage>> examples(Annotation annotation, Element element, MessageHandler messageHandler) {
//         return Collections.singletonList(new Item(element, (EgDefaultLanguage) annotation));
//     }
// 
//     public static class Item implements EgItem<EgDefaultLanguage> {
//         private final Element element;
//         private final EgDefaultLanguage language;
// 
//         public Item(Element element, EgDefaultLanguage language) {
//             this.language = language;
//             this.element = element;
//         }
// 
//         @Override
//         public EgDefaultLanguage getAnnotation() {
//             return language;
//         }
// 
//         @Override
//         public Element getElement() {
//             return element;
//         }
//     }
// }
// 
// Path: egtest-processor/src/main/java/com/vocalabs/egtest/processor/data/EgItem.java
// public interface EgItem<T extends Annotation> {
//     T getAnnotation();
//     Element getElement();
// }


// Path: egtest-processor/src/main/java/com/vocalabs/egtest/processor/AnnotationCollector.java
import com.vocalabs.egtest.annotation.EgLanguage;
import com.vocalabs.egtest.processor.data.DefaultLanguageReader;
import com.vocalabs.egtest.processor.data.EgItem;
import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.NestingKind;
import javax.lang.model.element.TypeElement;
import javax.lang.model.type.DeclaredType;
import java.util.*;

        Element classEl = data.getElement();
        if (classEl.getKind().equals(ElementKind.CLASS)) {
            EgLanguage language = ((DefaultLanguageReader.Item)data).getAnnotation().value();
            languageForClassName.put(className(classEl), language);
        }
        else {
            messageHandler.error("Can't set default language except on Class: "+classEl);
        }
    }

    public static String className(Element classEl) {
        DeclaredType dt = (DeclaredType) classEl.asType();
        TypeElement te = (TypeElement) dt.asElement();

        if ( ! allowedNesting(te.getNestingKind())) {
            throw new IllegalArgumentException("EgTest doesn't support local and anonymous classes: "+classEl);
        }
        return te.getQualifiedName().toString();
    }

    private static boolean allowedNesting(NestingKind nk) {
        switch (nk) {
            case TOP_LEVEL: return true;
            case MEMBER:    return true;
            case LOCAL:     return false;
            case ANONYMOUS: return false;
            default:        return false;
        }
    }

    public EgLanguage languageForClassName(String className, EgLanguage defaultLanguage) {