<commit_before>package com.matthewtamlin.spyglass.library.util;

import com.matthewtamlin.java_utilities.testing.Tested;
import com.matthewtamlin.spyglass.library.call_handler_adapters.CallHandlerAdapter;
import com.matthewtamlin.spyglass.library.default_adapters.DefaultAdapter;
import com.matthewtamlin.spyglass.library.meta_annotations.CallHandler;
import com.matthewtamlin.spyglass.library.meta_annotations.Default;
import com.matthewtamlin.spyglass.library.meta_annotations.Use;
import com.matthewtamlin.spyglass.library.meta_annotations.ValueHandler;
import com.matthewtamlin.spyglass.library.use_adapters.UseAdapter;
import com.matthewtamlin.spyglass.library.value_handler_adapters.ValueHandlerAdapter;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

import static com.matthewtamlin.java_utilities.checkers.NullChecker.checkNotNull;
import static com.matthewtamlin.spyglass.library.util.AnnotationUtil.getUseAnnotations;

@Tested(testMethod = "automated")
@SuppressWarnings("TryWithIdenticalCatches") // Can't actually collapse blocks until API 19
public class AdapterUtil {
	private static final String EXCEPTION_MESSAGE = "Could not instantiate class %1$s. " +
			"Does the class have a public no-arg constructor?";

	public static ValueHandlerAdapter<?, Annotation> getValueHandlerAdapter(final Field field) {
		checkNotNull(field, "Argument \'field\' cannot be null.");

		final Annotation handlerAnnotation = AnnotationUtil.getValueHandlerAnnotation(field);

		if (handlerAnnotation == null) {
			return null;
		}

		final Class<? extends ValueHandlerAdapter> adapterClass = handlerAnnotation
				.annotationType()
				.getAnnotation(ValueHandler.class)
				.adapterClass();

		try {
			return adapterClass.newInstance();
		} catch (final InstantiationException e) {
			throw new RuntimeException(String.format(EXCEPTION_MESSAGE, adapterClass), e);
		} catch (final IllegalAccessException e) {
			throw new RuntimeException(String.format(EXCEPTION_MESSAGE, adapterClass), e);
		}
	}

	public static ValueHandlerAdapter<?, Annotation> getValueHandlerAdapter(final Method method) {
		checkNotNull(method, "Argument \'method\' cannot be null.");

		final Annotation handlerAnnotation = AnnotationUtil.getValueHandlerAnnotation(method);

		if (handlerAnnotation == null) {
			return null;
		}

		final Class<? extends ValueHandlerAdapter> adapterClass = handlerAnnotation
				.annotationType()
				.getAnnotation(ValueHandler.class)
				.adapterClass();

		try {
			return adapterClass.newInstance();
		} catch (final InstantiationException e) {
			throw new RuntimeException(String.format(EXCEPTION_MESSAGE, adapterClass), e);
		} catch (final IllegalAccessException e) {
			throw new RuntimeException(String.format(EXCEPTION_MESSAGE, adapterClass), e);
		}
	}

	public static CallHandlerAdapter<Annotation> getCallHandlerAdapter(final Method method) {
		checkNotNull(method, "Argument \'method\' cannot be null.");

		final Annotation handlerAnnotation = AnnotationUtil.getCallHandlerAnnotation(method);

		if (handlerAnnotation == null) {
			return null;
		}

		final Class<? extends CallHandlerAdapter> adapterClass = handlerAnnotation
				.annotationType()
				.getAnnotation(CallHandler.class)
				.adapterClass();

		try {
			return adapterClass.newInstance();
		} catch (final InstantiationException e) {
			throw new RuntimeException(String.format(EXCEPTION_MESSAGE, adapterClass), e);
		} catch (final IllegalAccessException e) {
			throw new RuntimeException(String.format(EXCEPTION_MESSAGE, adapterClass), e);
		}
	}

	public static DefaultAdapter<?, Annotation> getDefaultAdapter(final Field field) {
		checkNotNull(field, "Argument \'field\' cannot be null.");

		final Annotation defaultAnnotation = AnnotationUtil.getDefaultAnnotation(field);

		if (defaultAnnotation == null) {
			return null;
		}

		final Class<? extends DefaultAdapter> adapterClass = defaultAnnotation
				.annotationType()
				.getAnnotation(Default.class)
				.adapterClass();

		try {
			return adapterClass.newInstance();
		} catch (final InstantiationException e) {
			throw new RuntimeException(String.format(EXCEPTION_MESSAGE, adapterClass), e);
		} catch (final IllegalAccessException e) {
			throw new RuntimeException(String.format(EXCEPTION_MESSAGE, adapterClass), e);
		}
	}<commit_msg>Deleted field specific methods<commit_after>package com.matthewtamlin.spyglass.library.util;

import com.matthewtamlin.java_utilities.testing.Tested;
import com.matthewtamlin.spyglass.library.call_handler_adapters.CallHandlerAdapter;
import com.matthewtamlin.spyglass.library.default_adapters.DefaultAdapter;
import com.matthewtamlin.spyglass.library.meta_annotations.CallHandler;
import com.matthewtamlin.spyglass.library.meta_annotations.Default;
import com.matthewtamlin.spyglass.library.meta_annotations.Use;
import com.matthewtamlin.spyglass.library.meta_annotations.ValueHandler;
import com.matthewtamlin.spyglass.library.use_adapters.UseAdapter;
import com.matthewtamlin.spyglass.library.value_handler_adapters.ValueHandlerAdapter;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

import static com.matthewtamlin.java_utilities.checkers.NullChecker.checkNotNull;
import static com.matthewtamlin.spyglass.library.util.AnnotationUtil.getUseAnnotations;

@Tested(testMethod = "automated")
@SuppressWarnings("TryWithIdenticalCatches") // Can't actually collapse blocks until API 19
public class AdapterUtil {
	private static final String EXCEPTION_MESSAGE = "Could not instantiate class %1$s. " +
			"Does the class have a public no-arg constructor?";

	public static ValueHandlerAdapter<?, Annotation> getValueHandlerAdapter(final Method method) {
		checkNotNull(method, "Argument \'method\' cannot be null.");

		final Annotation handlerAnnotation = AnnotationUtil.getValueHandlerAnnotation(method);

		if (handlerAnnotation == null) {
			return null;
		}

		final Class<? extends ValueHandlerAdapter> adapterClass = handlerAnnotation
				.annotationType()
				.getAnnotation(ValueHandler.class)
				.adapterClass();

		try {
			return adapterClass.newInstance();
		} catch (final InstantiationException e) {
			throw new RuntimeException(String.format(EXCEPTION_MESSAGE, adapterClass), e);
		} catch (final IllegalAccessException e) {
			throw new RuntimeException(String.format(EXCEPTION_MESSAGE, adapterClass), e);
		}
	}

	public static CallHandlerAdapter<Annotation> getCallHandlerAdapter(final Method method) {
		checkNotNull(method, "Argument \'method\' cannot be null.");

		final Annotation handlerAnnotation = AnnotationUtil.getCallHandlerAnnotation(method);

		if (handlerAnnotation == null) {
			return null;
		}

		final Class<? extends CallHandlerAdapter> adapterClass = handlerAnnotation
				.annotationType()
				.getAnnotation(CallHandler.class)
				.adapterClass();

		try {
			return adapterClass.newInstance();
		} catch (final InstantiationException e) {
			throw new RuntimeException(String.format(EXCEPTION_MESSAGE, adapterClass), e);
		} catch (final IllegalAccessException e) {
			throw new RuntimeException(String.format(EXCEPTION_MESSAGE, adapterClass), e);
		}
	}
{'fraction_non_alphanumeric': 0.09449465899753492, 'fraction_numerical': 0.0008216926869350862, 'mean_word_length': 5.863721804511278, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '7062387', 'n_tokens_mistral': 2271, 'n_tokens_neox': 2025, 'n_words': 453}