<commit_before>package flextrade.buildtool.builder;

import static com.google.inject.internal.util.Sets.newHashSet;
import static com.sun.codemodel.JExpr._new;
import static com.sun.codemodel.JExpr.ref;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Set;
import java.util.function.Consumer;


import com.dyuproject.protostuff.Message;
import com.sun.codemodel.JBlock;
import com.sun.codemodel.JClass;
import com.sun.codemodel.JClassAlreadyExistsException;
import com.sun.codemodel.JCodeModel;
import com.sun.codemodel.JDefinedClass;
import com.sun.codemodel.JExpr;
import com.sun.codemodel.JFieldVar;
import com.sun.codemodel.JMethod;
import com.sun.codemodel.JMod;
import com.sun.codemodel.JVar;

import flextrade.buildtool.PojoBuilderMojo;

public class PojoBuilderBuilder<T extends Message> {


    private final JCodeModel codeModel = new JCodeModel();
    private final Class<T> clazz;
    private final JDefinedClass definedClass;

    private final Set<Property> properties = newHashSet();

    public PojoBuilderBuilder(Class<T> clazz) throws JClassAlreadyExistsException {

        this.clazz = clazz;
        definedClass = codeModel._class(clazz.getName() + "Builder");
    }


    public void build() throws IOException {

        final String fieldName = "Property";

        Arrays.asList(clazz.getMethods()).stream().forEach(new CreateField());


        createBuildMethod();

        File file = new File(PojoBuilderMojo.TARGET_BUILDERS_SOURCES);
        file.mkdirs();
        codeModel.build(file);

    }

    private void createBuildMethod() {
        JClass pojoClass = codeModel.ref(clazz);
        JMethod builderMethod = definedClass.method(JMod.PUBLIC, pojoClass, "build");
        JBlock methodBody = builderMethod.body();

        JVar message = methodBody.decl(pojoClass, "result", _new(pojoClass));
        for(Property property : properties) {
            methodBody.invoke(message, property.getSetter().getName()).arg(property.getFieldVar());
        }

        methodBody._return(message);
    }

    private String convertFirstCharToLowercase(String string) {
        return string.isEmpty() ? string : string.substring(0, 1).toLowerCase() + string.substring(1);
    }

    private class CreateField implements Consumer<Method> {
        @Override<commit_msg>Cleaned up a bit<commit_after>package flextrade.buildtool.builder;

import static com.google.inject.internal.util.Sets.newHashSet;
import static com.sun.codemodel.JExpr._new;
import static com.sun.codemodel.JExpr.ref;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Set;
import java.util.function.Consumer;


import com.dyuproject.protostuff.Message;
import com.sun.codemodel.JBlock;
import com.sun.codemodel.JClass;
import com.sun.codemodel.JClassAlreadyExistsException;
import com.sun.codemodel.JCodeModel;
import com.sun.codemodel.JDefinedClass;
import com.sun.codemodel.JExpr;
import com.sun.codemodel.JFieldVar;
import com.sun.codemodel.JMethod;
import com.sun.codemodel.JMod;
import com.sun.codemodel.JVar;

import flextrade.buildtool.PojoBuilderMojo;

public class PojoBuilderBuilder<T extends Message> {


    private final JCodeModel codeModel = new JCodeModel();
    private final Class<T> clazz;
    private final JDefinedClass definedClass;

    private final Set<Property> properties = newHashSet();

    public PojoBuilderBuilder(Class<T> clazz) throws JClassAlreadyExistsException {

        this.clazz = clazz;
        definedClass = codeModel._class(clazz.getName() + "Builder");
    }


    public void build() throws IOException {
        Arrays.asList(clazz.getMethods()).stream().forEach(new CreateField());

        createBuildMethod();

        File file = new File(PojoBuilderMojo.TARGET_BUILDERS_SOURCES);
        file.mkdirs();
        codeModel.build(file);
    }

    private void createBuildMethod() {
        JClass pojoClass = codeModel.ref(clazz);
        JMethod builderMethod = definedClass.method(JMod.PUBLIC, pojoClass, "build");
        JBlock methodBody = builderMethod.body();

        JVar message = methodBody.decl(pojoClass, "result", _new(pojoClass));
        for(Property property : properties) {
            methodBody.invoke(message, property.getSetter().getName()).arg(property.getFieldVar());
        }

        methodBody._return(message);
    }

    private String convertFirstCharToLowercase(String string) {
        return string.isEmpty() ? string : string.substring(0, 1).toLowerCase() + string.substring(1);
    }

    private class CreateField implements Consumer<Method> {
        @Override
{'fraction_non_alphanumeric': 0.10651896037494674, 'fraction_numerical': 0.0012782275244993609, 'mean_word_length': 3.957761351636748, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '6205898', 'n_tokens_mistral': 1463, 'n_tokens_neox': 1392, 'n_words': 278}