<commit_before>package com.carrotcreative.recyclercore.compiler;

import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.JavaFile;
import com.squareup.javapoet.MethodSpec;
import com.squareup.javapoet.ParameterSpec;
import com.squareup.javapoet.ParameterizedTypeName;
import com.squareup.javapoet.TypeSpec;
import com.squareup.javapoet.WildcardTypeName;

import java.util.List;
import java.util.Map;

import javax.lang.model.element.Modifier;

/**
 * Created by kaushik on 9/30/16.
 */

class AdapterGenHelper
{
    private static final String PACKAGE = "com.carrotcreative.recyclercore";
    private static final String CLASSNAME = "RecyclerCoreAdapter";
    private static final ClassName VIEW = ClassName.get("android.view", "View");
    private static final ClassName VIEW_GROUP = ClassName.get("android.view", "ViewGroup");
    private static final ClassName LAYOUT_INFLATER = ClassName.get("android.view", "LayoutInflater");
    private static final ClassName RCAdapter = ClassName.get("com.carrotcreative.recyclercore.adapter", "RecyclerCoreBaseAdapter");
    private static final ClassName RCController = ClassName.get("com.carrotcreative.recyclercore.adapter", "RecyclerCoreController");

    static JavaFile brewAdapter(Map<ModelDetails, ControllerDetails> map)
    {
        ParameterSpec param = ParameterSpec.builder(List.class, "list").build();
        MethodSpec constructor = MethodSpec.constructorBuilder()
                .addModifiers(Modifier.PUBLIC)
                .addParameter(param)
                .addStatement("super(list)")
                .addStatement("initModelToViewType()")
                .build();

        // Create a factory method for controller, that takes the parent view, controller class and returns a new object.
        ParameterizedTypeName controllerParam = ParameterizedTypeName.get(ClassName.get(Class.class), WildcardTypeName.subtypeOf(Object.class));
        ParameterSpec viewGroupParam = ParameterSpec.builder(VIEW_GROUP, "parent").build();
        MethodSpec.Builder newInstanceControllerMethod = MethodSpec.methodBuilder("newInstanceController")
                .addModifiers(Modifier.PROTECTED)
                .addAnnotation(Override.class)
                .returns(RCController)
                .addParameter(controllerParam, "clazz")
                .addParameter(viewGroupParam)
                .addStatement("$T view = null", VIEW);
        {
            String statement = "view = $T.from(parent.getContext()).inflate($L, parent, false)";
            newInstanceControllerMethod.beginControlFlow("switch(clazz.getCanonicalName()t)");
            for(ControllerDetails controller : map.values())
            {
                ClassName returnCls = ClassName.get(controller.getPackageName(), controller.getClassName());
                String canonicalName = controller.getPackageName() + "." + controller.getClassName();
                newInstanceControllerMethod
                        .addCode("case $S:\n", canonicalName )
                        .addStatement(statement, LAYOUT_INFLATER, controller.getLayoutId())
                        .addStatement("return new $T(view)", returnCls);<commit_msg>Fix typo, remove t<commit_after>package com.carrotcreative.recyclercore.compiler;

import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.JavaFile;
import com.squareup.javapoet.MethodSpec;
import com.squareup.javapoet.ParameterSpec;
import com.squareup.javapoet.ParameterizedTypeName;
import com.squareup.javapoet.TypeSpec;
import com.squareup.javapoet.WildcardTypeName;

import java.util.List;
import java.util.Map;

import javax.lang.model.element.Modifier;

/**
 * Created by kaushik on 9/30/16.
 */

class AdapterGenHelper
{
    private static final String PACKAGE = "com.carrotcreative.recyclercore";
    private static final String CLASSNAME = "RecyclerCoreAdapter";
    private static final ClassName VIEW = ClassName.get("android.view", "View");
    private static final ClassName VIEW_GROUP = ClassName.get("android.view", "ViewGroup");
    private static final ClassName LAYOUT_INFLATER = ClassName.get("android.view", "LayoutInflater");
    private static final ClassName RCAdapter = ClassName.get("com.carrotcreative.recyclercore.adapter", "RecyclerCoreBaseAdapter");
    private static final ClassName RCController = ClassName.get("com.carrotcreative.recyclercore.adapter", "RecyclerCoreController");

    static JavaFile brewAdapter(Map<ModelDetails, ControllerDetails> map)
    {
        ParameterSpec param = ParameterSpec.builder(List.class, "list").build();
        MethodSpec constructor = MethodSpec.constructorBuilder()
                .addModifiers(Modifier.PUBLIC)
                .addParameter(param)
                .addStatement("super(list)")
                .addStatement("initModelToViewType()")
                .build();

        // Create a factory method for controller, that takes the parent view, controller class and returns a new object.
        ParameterizedTypeName controllerParam = ParameterizedTypeName.get(ClassName.get(Class.class), WildcardTypeName.subtypeOf(Object.class));
        ParameterSpec viewGroupParam = ParameterSpec.builder(VIEW_GROUP, "parent").build();
        MethodSpec.Builder newInstanceControllerMethod = MethodSpec.methodBuilder("newInstanceController")
                .addModifiers(Modifier.PROTECTED)
                .addAnnotation(Override.class)
                .returns(RCController)
                .addParameter(controllerParam, "clazz")
                .addParameter(viewGroupParam)
                .addStatement("$T view = null", VIEW);
        {
            String statement = "view = $T.from(parent.getContext()).inflate($L, parent, false)";
            newInstanceControllerMethod.beginControlFlow("switch(clazz.getCanonicalName())");
            for(ControllerDetails controller : map.values())
            {
                ClassName returnCls = ClassName.get(controller.getPackageName(), controller.getClassName());
                String canonicalName = controller.getPackageName() + "." + controller.getClassName();
                newInstanceControllerMethod
                        .addCode("case $S:\n", canonicalName )
                        .addStatement(statement, LAYOUT_INFLATER, controller.getLayoutId())
                        .addStatement("return new $T(view)", returnCls);
{'fraction_non_alphanumeric': 0.10295504558314995, 'fraction_numerical': 0.0015718327569946558, 'mean_word_length': 3.3168249660786975, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3442051', 'n_tokens_mistral': 1715, 'n_tokens_neox': 1645, 'n_words': 324}