private static void setFieldContainerInstance(InspectionData data, Injector injector)
      throws Throwable {
    // no container instance for static data.
    if (!data.isStatic) {
      if (data.lookupClass == null) {
        // if the container had an enclosing class and it's not static, make sure the lookup
        // points to the enclosing class.
        if (data.actualClass.getEnclosingClass() != null
            && !Modifier.isStatic(data.actualClass.getModifiers())) {
          data.lookupClass = data.actualClass.getEnclosingClass();
        }
      }

      // check if this is an enclosed class
      if (data.lookupClass == null) {
        Binding<?> binding = injector.getBinding(data.actualClass);
        validateBindingIsSingleton(injector, binding);
        data.fieldContainerInstance = binding.getProvider().get();
      } else {
        // inner classes must be annotated properly
        Binding<?> binding = injector.getBinding(data.lookupClass);
        validateBindingIsSingleton(injector, binding);
        Object lookupObj = binding.getProvider().get();

        // If this was an enclosed class, validate that it has InspectableContainer.
        if (data.actualClass.getEnclosingClass() != null
            && !Modifier.isStatic(data.actualClass.getModifiers())) {
          if (data.actualClass.getAnnotation(InspectableContainer.class) == null) {
            throw new InspectionException("container must be annotated with InspectableContainer");
          }
          Constructor[] constructors = data.actualClass.getDeclaredConstructors();
          if (constructors.length != 1) {
            throw new InspectionException("wrong constructors length: " + constructors.length);
          }
          Class[] parameters = constructors[0].getParameterTypes();
          if (parameters.length != 1 || !data.lookupClass.isAssignableFrom(parameters[0])) {
            throw new InspectionException("wrong parameter count or type for constructor");
          }
          constructors[0].setAccessible(true);
          data.fieldContainerInstance = constructors[0].newInstance(lookupObj);
        } else {
          data.fieldContainerInstance = lookupObj;
        }
      }
    }
  }