<commit_before>package global.tranquillity.neuron.di.core;

import net.sf.cglib.proxy.Callback;
import net.sf.cglib.proxy.CallbackHelper;
import net.sf.cglib.proxy.Enhancer;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.function.Function;

public class Incubator {

    private Incubator() { }

    /**
     * Returns a new instance of the given runtime class which will resolve its
     * dependencies lazily by recursively calling this method.
     */
    public static <T> T breed(Class<T> runtimeClass) {
        return breed(runtimeClass, synapse -> breed(synapse.getReturnType()));
    }

    /**
     * Returns a new instance of the given runtime class which will resolve its
     * dependencies lazily by calling the given function.
     *
     *
     * @param dependency a function which maps a synapse method to its resolved
     *                   dependency.
     */
    public static <T> T breed(final Class<T> runtimeClass,
                              final Function<Method, ?> dependency) {

        class ClassVisitor implements Visitor {

            private T instance;

            @Override
            public void visitNeuron(final NeuronElement element) {
                assert runtimeClass == element.runtimeClass();
                instance = new CglibFunction<>((superclass, interfaces) -> {

                    class MethodVisitor
                            extends CallbackHelper
                            implements Visitor {

                        private Callback callback;

                        private MethodVisitor() {
                            super(superclass, interfaces);
                        }

                        @Override
                        protected Callback getCallback(Method method) {<commit_msg>Improves Javadoc.<commit_after>package global.tranquillity.neuron.di.core;

import net.sf.cglib.proxy.Callback;
import net.sf.cglib.proxy.CallbackHelper;
import net.sf.cglib.proxy.Enhancer;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.function.Function;

public class Incubator {

    private Incubator() { }

    /**
     * Returns a new instance of the given runtime class which will resolve its
     * dependencies lazily by recursively calling this method.
     */
    public static <T> T breed(Class<T> runtimeClass) {
        return breed(runtimeClass, synapse -> breed(synapse.getReturnType()));
    }

    /**
     * Returns a new instance of the given runtime class which will resolve its
     * dependencies lazily by calling the given function.
     * This method is usually called from plugins for DI frameworks in order to
     * integrate Neuron DI into the framework.
     * The {@code dependency} function then calls back into the DI framework in
     * order to look up a binding for the method injection point and eventually
     * recursively call this method again.
     *
     * @param dependency a function which maps a synapse method to its resolved
     *                   dependency.
     */
    public static <T> T breed(final Class<T> runtimeClass,
                              final Function<Method, ?> dependency) {

        class ClassVisitor implements Visitor {

            private T instance;

            @Override
            public void visitNeuron(final NeuronElement element) {
                assert runtimeClass == element.runtimeClass();
                instance = new CglibFunction<>((superclass, interfaces) -> {

                    class MethodVisitor
                            extends CallbackHelper
                            implements Visitor {

                        private Callback callback;

                        private MethodVisitor() {
                            super(superclass, interfaces);
                        }

                        @Override
                        protected Callback getCallback(Method method) {
{'fraction_non_alphanumeric': 0.06809770540340489, 'fraction_numerical': 0.0, 'mean_word_length': 1.9721407624633431, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 19, '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': '4826655', 'n_tokens_mistral': 974, 'n_tokens_neox': 930, 'n_words': 314}