// Path: core/src/main/java/pocketbus/SubscriptionRegistration.java
// public interface SubscriptionRegistration {
//     /**
//      * @return a list of subscriptions
//      */
//     List<Subscription<?>> getSubscriptions();
// }
// 
// Path: core/src/main/java/pocketbus/internal/PocketBusConst.java
// public class PocketBusConst {
//     public static final String ANDROID_PREFIX = "android.";
//     public static final String JAVA_PREFIX = "java.";
// 
//     public static final String REGISTRATION_SUFFIX = "SubscriptionRegistration";
//     public static final String REGISTRY_NAME = "BusRegistry";
// 
//     public static final String METHOD_HANDLE = "handle";
//     public static final String METHOD_GET_SUBSCRIPTIONS = "getSubscriptions";
//     public static final String METHOD_GET_EVENT_CLASS = "getEventClass";
//     public static final String METHOD_GET_THREAD_MODE = "getThreadMode";
//     public static final String METHOD_GET_TARGET = "getTarget";
//     public static final String METHOD_EQUALS = "equals";
//     public static final String METHOD_GET_REGISTRAR = "getRegistration";
// 
//     public static final String VAR_TARGET_REF = "targetRef";
//     public static final String VAR_TARGET = "target";
//     public static final String VAR_EVENT = "event";
//     public static final String VAR_SUBSCRIPTION = "subscription";
//     public static final String VAR_SUBSCRIPTIONS = "subscriptions";
//     public static final String VAR_O = "o";
// }
// 
// Path: core/src/main/java/pocketbus/internal/Registry.java
// public interface Registry {
//     /**
//      * @param target the target that has subscribe annotations
//      * @return the SubscriptionRegistration for the given target
//      */
//     <T> SubscriptionRegistration getRegistration(T target);
// }


import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.JavaFile;
import com.squareup.javapoet.MethodSpec;
import com.squareup.javapoet.TypeSpec;
import com.squareup.javapoet.TypeVariableName;
import java.util.List;
import javax.lang.model.element.Modifier;
import javax.lang.model.element.TypeElement;
import javax.lang.model.type.TypeMirror;
import pocketbus.SubscriptionRegistration;
import pocketbus.internal.PocketBusConst;
import pocketbus.internal.Registry;

    private void generateMethod(TypeSpec.Builder classBuilder) {
        TypeVariableName t = TypeVariableName.get("T");
        MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder(PocketBusConst.METHOD_GET_REGISTRAR)
                .addModifiers(Modifier.PUBLIC)
                .addAnnotation(Override.class)
                .addTypeVariable(t)
                .addParameter(t, PocketBusConst.VAR_TARGET)
                .returns(SubscriptionRegistration.class);

        boolean first = true;
        for (SubscriptionNode node : subscriptionTrees) {
            first = writeRegistrars(methodBuilder, node, first);
        }
        if (!first) {
            methodBuilder.endControlFlow();
        }
        methodBuilder.addStatement("return null");

        classBuilder.addMethod(methodBuilder.build());
    }

    /**
     *
     *
     * @param methodBuilder
     * @param node
     * @param first first element in this tree
     * @return whether first was consumed
     */
// Path: core/src/main/java/pocketbus/SubscriptionRegistration.java
// public interface SubscriptionRegistration {
//     /**
//      * @return a list of subscriptions
//      */
//     List<Subscription<?>> getSubscriptions();
// }
// 
// Path: core/src/main/java/pocketbus/internal/PocketBusConst.java
// public class PocketBusConst {
//     public static final String ANDROID_PREFIX = "android.";
//     public static final String JAVA_PREFIX = "java.";
// 
//     public static final String REGISTRATION_SUFFIX = "SubscriptionRegistration";
//     public static final String REGISTRY_NAME = "BusRegistry";
// 
//     public static final String METHOD_HANDLE = "handle";
//     public static final String METHOD_GET_SUBSCRIPTIONS = "getSubscriptions";
//     public static final String METHOD_GET_EVENT_CLASS = "getEventClass";
//     public static final String METHOD_GET_THREAD_MODE = "getThreadMode";
//     public static final String METHOD_GET_TARGET = "getTarget";
//     public static final String METHOD_EQUALS = "equals";
//     public static final String METHOD_GET_REGISTRAR = "getRegistration";
// 
//     public static final String VAR_TARGET_REF = "targetRef";
//     public static final String VAR_TARGET = "target";
//     public static final String VAR_EVENT = "event";
//     public static final String VAR_SUBSCRIPTION = "subscription";
//     public static final String VAR_SUBSCRIPTIONS = "subscriptions";
//     public static final String VAR_O = "o";
// }
// 
// Path: core/src/main/java/pocketbus/internal/Registry.java
// public interface Registry {
//     /**
//      * @param target the target that has subscribe annotations
//      * @return the SubscriptionRegistration for the given target
//      */
//     <T> SubscriptionRegistration getRegistration(T target);
// }


// Path: compiler/src/main/java/pocketbus/internal/codegen/RegistryGenerator.java
import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.JavaFile;
import com.squareup.javapoet.MethodSpec;
import com.squareup.javapoet.TypeSpec;
import com.squareup.javapoet.TypeVariableName;
import java.util.List;
import javax.lang.model.element.Modifier;
import javax.lang.model.element.TypeElement;
import javax.lang.model.type.TypeMirror;
import pocketbus.SubscriptionRegistration;
import pocketbus.internal.PocketBusConst;
import pocketbus.internal.Registry;


    private void generateMethod(TypeSpec.Builder classBuilder) {
        TypeVariableName t = TypeVariableName.get("T");
        MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder(PocketBusConst.METHOD_GET_REGISTRAR)
                .addModifiers(Modifier.PUBLIC)
                .addAnnotation(Override.class)
                .addTypeVariable(t)
                .addParameter(t, PocketBusConst.VAR_TARGET)
                .returns(SubscriptionRegistration.class);

        boolean first = true;
        for (SubscriptionNode node : subscriptionTrees) {
            first = writeRegistrars(methodBuilder, node, first);
        }
        if (!first) {
            methodBuilder.endControlFlow();
        }
        methodBuilder.addStatement("return null");

        classBuilder.addMethod(methodBuilder.build());
    }

    /**
     *
     *
     * @param methodBuilder
     * @param node
     * @param first first element in this tree
     * @return whether first was consumed
     */
    private boolean writeRegistrars(MethodSpec.Builder methodBuilder, SubscriptionNode node, boolean first) {