<commit_before>package pl.openrest.dto.mappers.generator.utils;

import javax.lang.model.element.Modifier;

import pl.openrest.dto.mapper.MapperDelegator;

import com.squareup.javapoet.CodeBlock;
import com.squareup.javapoet.FieldSpec;
import com.squareup.javapoet.MethodSpec;
import com.squareup.javapoet.ParameterizedTypeName;

public class CodeBlockUtils {

    private static final String DTO_PARAM_NAME = "dto";
    private static final String ENTITY_PARAM_NAME = "entity";
    private static final String MAPPER_DELEGATOR_FIELD_NAME = "mapperDelegator";

    public static String delegateCreateLiteral(String getterLiteral) {
        return String.format("%s.create(%s)", MAPPER_DELEGATOR_FIELD_NAME, getterLiteral);
    }

    public static CodeBlock setterCodeBlock(String setter, String getterLiteral) {
        return CodeBlock.builder().addStatement("$L.$L($L)", ENTITY_PARAM_NAME, setter, getterLiteral).build();
    }

    public static CodeBlock collectionSetterCodeBlock(String name, String setter, String getter, Class<?> collectionType, Class<?> rawType) {
        CodeBlock collectionVariable = collectionVariable(name, collectionType, rawType);
        CodeBlock addCodeBlock = addCodeBlock(name, "o");
        return CodeBlock.builder().add(collectionVariable).beginControlFlow("for($T o: $L)", rawType, getterLiteral(getter))
                .add(addCodeBlock).endControlFlow().add(setterCodeBlock(setter, name)).build();
    }

    public static CodeBlock dtoCollectionSetterCodeBlock(String name, String setter, String getter, Class<?> collectionType,
            Class<?> rawType, Class<?> rawDtoType) {
        CodeBlock collectionVariable = collectionVariable(name, collectionType, rawType);
        CodeBlock addCodeBlock = addCodeBlock(name, delegateCreateLiteral("o"));
        return CodeBlock.builder().add(collectionVariable).beginControlFlow("for($T o: $L)", rawDtoType, getterLiteral(getter))<commit_msg>Change DTO_PARAM_NAME and ENTITY_PARAM_NAME fields' modifiers to public<commit_after>package pl.openrest.dto.mappers.generator.utils;

import javax.lang.model.element.Modifier;

import pl.openrest.dto.mapper.MapperDelegator;

import com.squareup.javapoet.CodeBlock;
import com.squareup.javapoet.FieldSpec;
import com.squareup.javapoet.MethodSpec;
import com.squareup.javapoet.ParameterizedTypeName;

public class CodeBlockUtils {

    public static final String DTO_PARAM_NAME = "dto";
    public static final String ENTITY_PARAM_NAME = "entity";
    private static final String MAPPER_DELEGATOR_FIELD_NAME = "mapperDelegator";

    public static String delegateCreateLiteral(String getterLiteral) {
        return String.format("%s.create(%s)", MAPPER_DELEGATOR_FIELD_NAME, getterLiteral);
    }

    public static CodeBlock setterCodeBlock(String setter, String getterLiteral) {
        return CodeBlock.builder().addStatement("$L.$L($L)", ENTITY_PARAM_NAME, setter, getterLiteral).build();
    }

    public static CodeBlock collectionSetterCodeBlock(String name, String setter, String getter, Class<?> collectionType, Class<?> rawType) {
        CodeBlock collectionVariable = collectionVariable(name, collectionType, rawType);
        CodeBlock addCodeBlock = addCodeBlock(name, "o");
        return CodeBlock.builder().add(collectionVariable).beginControlFlow("for($T o: $L)", rawType, getterLiteral(getter))
                .add(addCodeBlock).endControlFlow().add(setterCodeBlock(setter, name)).build();
    }

    public static CodeBlock dtoCollectionSetterCodeBlock(String name, String setter, String getter, Class<?> collectionType,
            Class<?> rawType, Class<?> rawDtoType) {
        CodeBlock collectionVariable = collectionVariable(name, collectionType, rawType);
        CodeBlock addCodeBlock = addCodeBlock(name, delegateCreateLiteral("o"));
        return CodeBlock.builder().add(collectionVariable).beginControlFlow("for($T o: $L)", rawDtoType, getterLiteral(getter))
{'fraction_non_alphanumeric': 0.1050356052899288, 'fraction_numerical': 0.0, 'mean_word_length': 5.223101265822785, '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': '4269806', 'n_tokens_mistral': 1125, 'n_tokens_neox': 1112, 'n_words': 238}