<commit_before>package ru.vyarus.dropwizard.guice.debug.report.jersey.util;

import com.google.common.collect.ImmutableMap;
import org.glassfish.jersey.internal.inject.InjectionResolver;
import org.glassfish.jersey.jaxb.internal.AbstractCollectionJaxbProvider;
import org.glassfish.jersey.server.internal.inject.ParamInjectionResolver;
import org.glassfish.jersey.server.monitoring.ApplicationEventListener;
import org.glassfish.jersey.server.spi.internal.ValueParamProvider;
import org.glassfish.jersey.spi.ExtendedExceptionMapper;
import ru.vyarus.dropwizard.guice.debug.util.RenderUtils;
import ru.vyarus.dropwizard.guice.module.installer.util.FeatureUtils;
import ru.vyarus.java.generics.resolver.GenericsResolver;
import ru.vyarus.java.generics.resolver.context.GenericsContext;

import javax.ws.rs.Consumes;
import javax.ws.rs.NameBinding;
import javax.ws.rs.Produces;
import javax.ws.rs.container.ContainerRequestFilter;
import javax.ws.rs.container.ContainerResponseFilter;
import javax.ws.rs.container.DynamicFeature;
import javax.ws.rs.ext.*;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.function.Supplier;

/**
 * Jersey providers recognition and render utility.
 *
 * @author <NAME>
 * @since 26.10.2019
 */
@SuppressWarnings("PMD.CouplingBetweenObjects")
public final class ProviderRenderUtil {
    private static final String SIMPLE_FORMAT = "%s";
    private static final String SINGLE_GENERIC_FORMAT = "%-30s %s";
    private static final String DOUBLE_GENERICS_FORMAT = "%-15s -> %-15s %s";
    private static final String INJECTION_FORMAT = "@%-30s %s";

    private static final Map<Class, ExtDescriptor> DESCRIPTORS = ImmutableMap.<Class, ExtDescriptor>builder()
            .put(Supplier.class, new ExtDescriptor("Suppliers", SINGLE_GENERIC_FORMAT, 1))
            .put(Function.class, new ExtDescriptor("Functions", DOUBLE_GENERICS_FORMAT, 2))
            .put(ExceptionMapper.class, new ExtDescriptor("Exception mappers", SINGLE_GENERIC_FORMAT, 1))
            .put(ParamConverterProvider.class, new ExtDescriptor("Param converters", SIMPLE_FORMAT, 0))
            .put(ContextResolver.class, new ExtDescriptor("Context resolvers", SINGLE_GENERIC_FORMAT, 1))
            .put(MessageBodyReader.class, new ExtDescriptor("Message body readers", SINGLE_GENERIC_FORMAT, 1))
            .put(MessageBodyWriter.class, new ExtDescriptor("Message body writers", SINGLE_GENERIC_FORMAT, 1))
            .put(ReaderInterceptor.class, new ExtDescriptor("Reader interceptors", SIMPLE_FORMAT, 0))
            .put(WriterInterceptor.class, new ExtDescriptor("Writer interceptors", SIMPLE_FORMAT, 0))
            .put(ContainerRequestFilter.class, new ExtDescriptor("Container request filters", SIMPLE_FORMAT, 0))
            .put(ContainerResponseFilter.class, new ExtDescriptor("Container response filters", SIMPLE_FORMAT, 0))
            .put(DynamicFeature.class, new ExtDescriptor("Dynamic features", SIMPLE_FORMAT, 0))
            .put(InjectionResolver.class, new ExtDescriptor("Injection resolvers", INJECTION_FORMAT, 1))
            .put(ValueParamProvider.class, new ExtDescriptor("Value factory providers", SIMPLE_FORMAT, 0))
            .put(ApplicationEventListener.class, new ExtDescriptor("Application event listeners", SIMPLE_FORMAT, 0))
            .build();

    private ProviderRenderUtil() {
    }

    /**
     * Detects known provider types in provided class.
     *
     * @param provider provider class for detection
     * @return list of detected types or list with {@link Object} class to identify unknown type.
     */
    @SuppressWarnings("unchecked")
    public static List<Class> detectProviderTypes(final Class<?> provider) {
        final List<Class> res = new ArrayList<>();
        boolean recognized = false;
        for (Map.Entry<Class, ExtDescriptor> entry : DESCRIPTORS.entrySet()) {
            final Class ext = entry.getKey();<commit_msg>rename param value factory section in jersey report<commit_after>package ru.vyarus.dropwizard.guice.debug.report.jersey.util;

import com.google.common.collect.ImmutableMap;
import org.glassfish.jersey.internal.inject.InjectionResolver;
import org.glassfish.jersey.jaxb.internal.AbstractCollectionJaxbProvider;
import org.glassfish.jersey.server.internal.inject.ParamInjectionResolver;
import org.glassfish.jersey.server.monitoring.ApplicationEventListener;
import org.glassfish.jersey.server.spi.internal.ValueParamProvider;
import org.glassfish.jersey.spi.ExtendedExceptionMapper;
import ru.vyarus.dropwizard.guice.debug.util.RenderUtils;
import ru.vyarus.dropwizard.guice.module.installer.util.FeatureUtils;
import ru.vyarus.java.generics.resolver.GenericsResolver;
import ru.vyarus.java.generics.resolver.context.GenericsContext;

import javax.ws.rs.Consumes;
import javax.ws.rs.NameBinding;
import javax.ws.rs.Produces;
import javax.ws.rs.container.ContainerRequestFilter;
import javax.ws.rs.container.ContainerResponseFilter;
import javax.ws.rs.container.DynamicFeature;
import javax.ws.rs.ext.*;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.function.Supplier;

/**
 * Jersey providers recognition and render utility.
 *
 * @author <NAME>
 * @since 26.10.2019
 */
@SuppressWarnings("PMD.CouplingBetweenObjects")
public final class ProviderRenderUtil {
    private static final String SIMPLE_FORMAT = "%s";
    private static final String SINGLE_GENERIC_FORMAT = "%-30s %s";
    private static final String DOUBLE_GENERICS_FORMAT = "%-15s -> %-15s %s";
    private static final String INJECTION_FORMAT = "@%-30s %s";

    private static final Map<Class, ExtDescriptor> DESCRIPTORS = ImmutableMap.<Class, ExtDescriptor>builder()
            .put(Supplier.class, new ExtDescriptor("Suppliers", SINGLE_GENERIC_FORMAT, 1))
            .put(Function.class, new ExtDescriptor("Functions", DOUBLE_GENERICS_FORMAT, 2))
            .put(ExceptionMapper.class, new ExtDescriptor("Exception mappers", SINGLE_GENERIC_FORMAT, 1))
            .put(ParamConverterProvider.class, new ExtDescriptor("Param converters", SIMPLE_FORMAT, 0))
            .put(ContextResolver.class, new ExtDescriptor("Context resolvers", SINGLE_GENERIC_FORMAT, 1))
            .put(MessageBodyReader.class, new ExtDescriptor("Message body readers", SINGLE_GENERIC_FORMAT, 1))
            .put(MessageBodyWriter.class, new ExtDescriptor("Message body writers", SINGLE_GENERIC_FORMAT, 1))
            .put(ReaderInterceptor.class, new ExtDescriptor("Reader interceptors", SIMPLE_FORMAT, 0))
            .put(WriterInterceptor.class, new ExtDescriptor("Writer interceptors", SIMPLE_FORMAT, 0))
            .put(ContainerRequestFilter.class, new ExtDescriptor("Container request filters", SIMPLE_FORMAT, 0))
            .put(ContainerResponseFilter.class, new ExtDescriptor("Container response filters", SIMPLE_FORMAT, 0))
            .put(DynamicFeature.class, new ExtDescriptor("Dynamic features", SIMPLE_FORMAT, 0))
            .put(InjectionResolver.class, new ExtDescriptor("Injection resolvers", INJECTION_FORMAT, 1))
            .put(ValueParamProvider.class, new ExtDescriptor("Param value providers", SIMPLE_FORMAT, 0))
            .put(ApplicationEventListener.class, new ExtDescriptor("Application event listeners", SIMPLE_FORMAT, 0))
            .build();

    private ProviderRenderUtil() {
    }

    /**
     * Detects known provider types in provided class.
     *
     * @param provider provider class for detection
     * @return list of detected types or list with {@link Object} class to identify unknown type.
     */
    @SuppressWarnings("unchecked")
    public static List<Class> detectProviderTypes(final Class<?> provider) {
        final List<Class> res = new ArrayList<>();
        boolean recognized = false;
        for (Map.Entry<Class, ExtDescriptor> entry : DESCRIPTORS.entrySet()) {
            final Class ext = entry.getKey();
{'fraction_non_alphanumeric': 0.10624235006119952, 'fraction_numerical': 0.007588739290085679, 'mean_word_length': 4.45460614152203, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 21, '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': '1570413', 'n_tokens_mistral': 2357, 'n_tokens_neox': 2260, 'n_words': 514}