<commit_before>package fitnesse.slim.fixtureInteraction;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import fitnesse.slim.ConverterSupport;
import fitnesse.slim.SlimError;
import fitnesse.slim.SlimServer;

public class DefaultInteraction implements FixtureInteraction {

  @Override
  public Object createInstance(List<String> paths, String className, Object[] args)
          throws IllegalArgumentException, InstantiationException,
          IllegalAccessException, InvocationTargetException {
    Class<?> k = searchPathsForClass(paths, className);
    Constructor<?> constructor = getConstructor(k.getConstructors(), args);
    if (constructor == null) {
      throw new SlimError(String.format("message:<<%s %s>>",
              SlimServer.NO_CONSTRUCTOR, className));
    }

    return newInstance(args, constructor);
  }

  private Object newInstance(Object[] args, Constructor<?> constructor)
          throws IllegalAccessException, InstantiationException,
          InvocationTargetException {
    Object[] initargs = ConverterSupport.convertArgs(args,
            constructor.getParameterTypes());

    return newInstance(constructor, initargs);
  }

  private Class<?> searchPathsForClass(List<String> paths, String className) {
    Class<?> k = getClass(className);
    if (k != null) {
      return k;
    }
    List<String> reversedPaths = new ArrayList<String>(paths);
    Collections.reverse(reversedPaths);
    for (String path : reversedPaths) {
      k = getClass(path + "." + className);
      if (k != null) {
        return k;
      }
    }
    throw new SlimError(String.format("message:<<%s %s>>", SlimServer.NO_CLASS, className));
  }

  private Class<?> getClass(String className) {
    try {
      return Class.forName(className);
    } catch (ClassNotFoundException e) {<commit_msg>Expose finding of class to subclasses<commit_after>package fitnesse.slim.fixtureInteraction;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import fitnesse.slim.ConverterSupport;
import fitnesse.slim.SlimError;
import fitnesse.slim.SlimServer;

public class DefaultInteraction implements FixtureInteraction {

  @Override
  public Object createInstance(List<String> paths, String className, Object[] args)
          throws IllegalArgumentException, InstantiationException,
          IllegalAccessException, InvocationTargetException {
    Class<?> k = searchPathsForClass(paths, className);
    Constructor<?> constructor = getConstructor(k.getConstructors(), args);
    if (constructor == null) {
      throw new SlimError(String.format("message:<<%s %s>>",
              SlimServer.NO_CONSTRUCTOR, className));
    }

    return newInstance(args, constructor);
  }

  private Object newInstance(Object[] args, Constructor<?> constructor)
          throws IllegalAccessException, InstantiationException,
          InvocationTargetException {
    Object[] initargs = ConverterSupport.convertArgs(args,
            constructor.getParameterTypes());

    return newInstance(constructor, initargs);
  }

  protected Class<?> searchPathsForClass(List<String> paths, String className) {
    Class<?> k = getClass(className);
    if (k != null) {
      return k;
    }
    List<String> reversedPaths = new ArrayList<String>(paths);
    Collections.reverse(reversedPaths);
    for (String path : reversedPaths) {
      k = getClass(path + "." + className);
      if (k != null) {
        return k;
      }
    }
    throw new SlimError(String.format("message:<<%s %s>>", SlimServer.NO_CLASS, className));
  }

  private Class<?> getClass(String className) {
    try {
      return Class.forName(className);
    } catch (ClassNotFoundException e) {
{'fraction_non_alphanumeric': 0.10825780463242698, 'fraction_numerical': 0.0, 'mean_word_length': 4.05470737913486, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, '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': '7057796', 'n_tokens_mistral': 1092, 'n_tokens_neox': 1079, 'n_words': 251}