All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.robolectric.shadows.ClassNameResolver Maven / Gradle / Ivy

package org.robolectric.shadows;

public class ClassNameResolver {

  public static  Class resolve(String packageName, String className) throws ClassNotFoundException {
    Class aClass;
    if (looksFullyQualified(className)) {
      aClass = safeClassForName(className);
    } else {
      if (className.startsWith(".")) {
        aClass = safeClassForName(packageName + className);
      } else {
        aClass = safeClassForName(packageName + "." + className);
      }
    }

    if (aClass == null) {
      throw new ClassNotFoundException("Could not find a class for package: "
          + packageName + " and class name: " + className);
    }
    return aClass;
  }

  private static boolean looksFullyQualified(String className) {
    return className.contains(".") && !className.startsWith(".");
  }

  private static  Class safeClassForName(String classNamePath) {
    try {
      return (Class) Class.forName(classNamePath);
    } catch (ClassNotFoundException e) {
      return null;
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy