// Path: lifecyclebinder-processor/src/main/java/it/codingjam/lifecyclebinder/LifeCycleBinderProcessor.java
// @SupportedAnnotationTypes({
//         "it.codingjam.lifecyclebinder.BindLifeCycle",
//         "it.codingjam.lifecyclebinder.RetainedObjectProvider",
//         "it.codingjam.lifecyclebinder.BindEvent"
// })
// public class LifeCycleBinderProcessor extends AbstractProcessor {
// 
//     private Types types;
//     private Elements elements;
//     private Filer filer;
//     private Messager messager;
// 
//     private ElementsCollector elementsCollector;
// 
//     private BinderGenerator binderGenerator;
// 
//     @Override
//     public synchronized void init(ProcessingEnvironment processingEnv) {
//         super.init(processingEnv);
//         types = processingEnv.getTypeUtils();
//         elements = processingEnv.getElementUtils();
//         filer = processingEnv.getFiler();
//         messager = processingEnv.getMessager();
//         elementsCollector = new ElementsCollector(messager, types, elements);
//         binderGenerator = new BinderGenerator(processingEnv, types, messager, elements);
//     }
// 
//     @Override
//     public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
//         List<LifeCycleAwareInfo> elementsByClass = elementsCollector.createLifeCycleAwareElements(
//                 roundEnv.getElementsAnnotatedWith(BindLifeCycle.class),
//                 roundEnv.getElementsAnnotatedWith(RetainedObjectProvider.class),
//                 roundEnv.getElementsAnnotatedWith(BindEvent.class)
//         );
// 
//         if (elementsByClass == null) {
//             return true;
//         }
// 
//         elementsCollector.calculateNestedElements(elementsByClass);
// 
//         for (LifeCycleAwareInfo entry : elementsByClass) {
//             binderGenerator.generateBinder(entry);
//         }
//         return false;
//     }
// 
//     @Override public SourceVersion getSupportedSourceVersion() {
//         return SourceVersion.latestSupported();
//     }
// }
// 
// Path: lifecyclebinder-processor/src/test/java/it/codingjam/lifecyclebinder/test/FileLoader.java
// public static void check(String name) {
//     check(name, name);
// }


import com.google.testing.compile.JavaSourceSubjectFactory;
import org.junit.Test;
import org.truth0.Truth;
import javax.tools.JavaFileObject;
import it.codingjam.lifecyclebinder.LifeCycleBinderProcessor;
import static it.codingjam.lifecyclebinder.test.FileLoader.check;

    @Test public void testActivityWithBaseClass() throws Exception {
        check("com.test.activityWithBaseClass.MyActivityWithBaseClass");
    }

    @Test public void testObjectWithBaseClass() throws Exception {
        check("com.test.objectWithBaseClass.MyObjectWithBaseClass");
    }

    @Test public void testObjectWithGenericBaseClass() throws Exception {
        check("com.test.objectWithGenericBaseClass.MyObjectWithGenericBaseClass");
    }

    @Test public void testObjectWithNestedGenericBaseClass() throws Exception {
        check("com.test.objectWithNestedGenericBaseClass.MyObjectWithGenericBaseClass");
    }

    //@Test public void testActivityObjectNotExtendsLifeCycleAware() throws Exception {
    //    JavaFileObject target = FileLoader.loadClass("com.test.errors.ActivityObjectNotExtendsLifeCycleAware");
    //    Truth.ASSERT.about(JavaSourceSubjectFactory.javaSource())
    //            .that(target)
    //            .processedWith(new LifeCycleBinderProcessor())
    //            .failsToCompile()
    //            .withErrorContaining("must implement " + LifeCycleAware.class.getSimpleName());
    //}

    @Test public void testWrongFieldName() throws Exception {
        JavaFileObject target = FileLoader.loadClass("com.test.errors.WrongFieldName");
        Truth.ASSERT.about(JavaSourceSubjectFactory.javaSource())
                .that(target)
// Path: lifecyclebinder-processor/src/main/java/it/codingjam/lifecyclebinder/LifeCycleBinderProcessor.java
// @SupportedAnnotationTypes({
//         "it.codingjam.lifecyclebinder.BindLifeCycle",
//         "it.codingjam.lifecyclebinder.RetainedObjectProvider",
//         "it.codingjam.lifecyclebinder.BindEvent"
// })
// public class LifeCycleBinderProcessor extends AbstractProcessor {
// 
//     private Types types;
//     private Elements elements;
//     private Filer filer;
//     private Messager messager;
// 
//     private ElementsCollector elementsCollector;
// 
//     private BinderGenerator binderGenerator;
// 
//     @Override
//     public synchronized void init(ProcessingEnvironment processingEnv) {
//         super.init(processingEnv);
//         types = processingEnv.getTypeUtils();
//         elements = processingEnv.getElementUtils();
//         filer = processingEnv.getFiler();
//         messager = processingEnv.getMessager();
//         elementsCollector = new ElementsCollector(messager, types, elements);
//         binderGenerator = new BinderGenerator(processingEnv, types, messager, elements);
//     }
// 
//     @Override
//     public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
//         List<LifeCycleAwareInfo> elementsByClass = elementsCollector.createLifeCycleAwareElements(
//                 roundEnv.getElementsAnnotatedWith(BindLifeCycle.class),
//                 roundEnv.getElementsAnnotatedWith(RetainedObjectProvider.class),
//                 roundEnv.getElementsAnnotatedWith(BindEvent.class)
//         );
// 
//         if (elementsByClass == null) {
//             return true;
//         }
// 
//         elementsCollector.calculateNestedElements(elementsByClass);
// 
//         for (LifeCycleAwareInfo entry : elementsByClass) {
//             binderGenerator.generateBinder(entry);
//         }
//         return false;
//     }
// 
//     @Override public SourceVersion getSupportedSourceVersion() {
//         return SourceVersion.latestSupported();
//     }
// }
// 
// Path: lifecyclebinder-processor/src/test/java/it/codingjam/lifecyclebinder/test/FileLoader.java
// public static void check(String name) {
//     check(name, name);
// }


// Path: lifecyclebinder-processor/src/test/java/it/codingjam/lifecyclebinder/test/ProcessorTest.java
import com.google.testing.compile.JavaSourceSubjectFactory;
import org.junit.Test;
import org.truth0.Truth;
import javax.tools.JavaFileObject;
import it.codingjam.lifecyclebinder.LifeCycleBinderProcessor;
import static it.codingjam.lifecyclebinder.test.FileLoader.check;


    @Test public void testActivityWithBaseClass() throws Exception {
        check("com.test.activityWithBaseClass.MyActivityWithBaseClass");
    }

    @Test public void testObjectWithBaseClass() throws Exception {
        check("com.test.objectWithBaseClass.MyObjectWithBaseClass");
    }

    @Test public void testObjectWithGenericBaseClass() throws Exception {
        check("com.test.objectWithGenericBaseClass.MyObjectWithGenericBaseClass");
    }

    @Test public void testObjectWithNestedGenericBaseClass() throws Exception {
        check("com.test.objectWithNestedGenericBaseClass.MyObjectWithGenericBaseClass");
    }

    //@Test public void testActivityObjectNotExtendsLifeCycleAware() throws Exception {
    //    JavaFileObject target = FileLoader.loadClass("com.test.errors.ActivityObjectNotExtendsLifeCycleAware");
    //    Truth.ASSERT.about(JavaSourceSubjectFactory.javaSource())
    //            .that(target)
    //            .processedWith(new LifeCycleBinderProcessor())
    //            .failsToCompile()
    //            .withErrorContaining("must implement " + LifeCycleAware.class.getSimpleName());
    //}

    @Test public void testWrongFieldName() throws Exception {
        JavaFileObject target = FileLoader.loadClass("com.test.errors.WrongFieldName");
        Truth.ASSERT.about(JavaSourceSubjectFactory.javaSource())
                .that(target)
                .processedWith(new LifeCycleBinderProcessor())