Creates a mock object and populates its fields.

@param type Type of mock object
@param <T>  Type of mock object
@return Mock Object of type T
163933
@SuppressWarnings("unchecked") // types must agree
  public static <T> T createMockObject(Type type) {
    Class<T> rawType;

    if (type instanceof ParameterizedType) {
      rawType = (Class<T>) ((ParameterizedType) type).getRawType();
    } else if (type instanceof Class) {
      rawType = (Class<T>) type;
    } else {
      throw new UnsupportedOperationException("Unsupported type: "
          + type.getClass().getSimpleName());
    }
    T instance = instantiateObject(rawType);

    return populateObject(instance);
  }
955063
public static <T> T get(Class<T> type) {
        FactoryBuilder factoryBuilder = REPOSITORY.get(type);
        return (T) factoryBuilder.get();
    }
382426
@SuppressWarnings("rawtypes")
	public static Object instantiate(Class<?> type) throws Exception {
		if (type.isAssignableFrom(ArrayList.class))
			return new ArrayList();
		if (type.isAssignableFrom(LinkedList.class))
			return new LinkedList();
		if (type.isAssignableFrom(HashSet.class))
			return new HashSet();
		if (type.isAssignableFrom(HashMap.class))
			return new HashMap();
		return type.newInstance();
	}
318444
public ParamConfigBuilder newParamConfig(Class<?> type, Type genericType){
        return paramConfigBuilderFactory.newInstance(type, genericType);
    }
513231
@SuppressWarnings("unchecked")
    public <T> PathBuilder<T> create(Class<T> type) {
        PathBuilder<T> rv = (PathBuilder<T>) paths.get(type);
        if (rv == null) {
            rv = new PathBuilder<T>(type, variableName(type));
            paths.put(type, rv);
        }
        return rv;
    }
1177456
@SuppressWarnings("WeakerAccess")
  public CreateInstanceRequest setType(@Nonnull Instance.Type type) {
    Preconditions.checkNotNull(type);
    Preconditions.checkArgument(type != Instance.Type.UNRECOGNIZED, "Type is unrecognized");
    builder.getInstanceBuilder().setType(type.toProto());
    return this;
  }
554968
@Override
    public <T> T createMockComponent(final Class<T> type) {
        if (isFinalOrPrimitive(type)) {
            LOG.warn("Skipping creation of a mock : {} as it is final or primitive type.", type.getSimpleName());
            return null;
        }

        return Mockito.mock(type);
    }
647043
public RuntimeTypeAdapterFactory<T> registerSubtype(Class<? extends T> type) {
    return registerSubtype(type, type.getSimpleName());
  }
437768
private void init(Class<?> type) {

    ParameterizedType parameterizedType =
      stream(nullSafeArray(type.getGenericInterfaces(), Type.class))
        .filter(this::isParameterizedFunctionType)
        .findFirst()
        .map(it -> (ParameterizedType) it)
        .orElseGet(() -> {

          Type genericSuperclass = type.getGenericSuperclass();

          return isParameterizedFunctionType(genericSuperclass) ? (ParameterizedType) genericSuperclass : null;

        });

    this.sourceType = parameterizedType != null
      ? ClassUtils.toRawType(parameterizedType.getActualTypeArguments()[0])
      : Object.class;

    this.targetType = parameterizedType != null
      ? ClassUtils.toRawType(parameterizedType.getActualTypeArguments()[1])
      : Object.class;
  }
975771
public static <T> List<Field> getDeclaredFields(T type) {
        return new ArrayList<>(asList(type.getClass().getDeclaredFields()));
    }
156158
@Override
  public <T> T instance(Class<T> type)
  {
    Key<T> key = Key.of(type);

    return instance(key);
  }
674327
public static <T> T instantiate(Class<T> type) {
        try {
            return BeanIntrospector.SHARED.findIntrospection(type).map(BeanIntrospection::instantiate).orElseGet(() -> {
                try {
                    Logger log = ClassUtils.REFLECTION_LOGGER;
                    if (log.isDebugEnabled()) {
                        log.debug("Reflectively instantiating type: " + type);
                    }
                    return type.newInstance();
                } catch (Throwable e) {
                    throw new InstantiationException("Could not instantiate type [" + type.getName() + "]: " + e.getMessage(), e);
                }
            });
        } catch (Throwable e) {
            throw new InstantiationException("Could not instantiate type [" + type.getName() + "]: " + e.getMessage(), e);
        }
    }
744585
@SuppressWarnings("unchecked")
    public <T> List<T> getContextualInstances(final Class<T> type) {
        List<T> result = new ArrayList<T>();
        for (Bean<?> bean : manager.getBeans(type)) {
            CreationalContext<T> context = (CreationalContext<T>) manager.createCreationalContext(bean);
            if (context != null) {
                result.add((T) manager.getReference(bean, type, context));
            }
        }
        return result;
    }
1154818
public static <T> TypeReference<T> get(Class<T> type) {
		return new SimpleTypeReference<T>(type);
	}
1302709
@SuppressWarnings({"unchecked"})
  public static <T extends MessageBundle> T create(final Class<T> type) {
    checkNotNull(type);
    return (T) Proxy.newProxyInstance(type.getClassLoader(), new Class[]{type}, new Handler(type));
  }
613941
private static List<Field> getAllFields(Class type) {
		final List<Field> fields = new ArrayList<>();
		for (Class<?> c = type; c != null; c = c.getSuperclass()) {
			fields.addAll(Arrays.asList(c.getDeclaredFields()));
		}
		return fields;
	}
715508
public static <T> ParameterBuilder<T> create(String name, Class<T> type) {
    return new ParameterBuilder<T>()
        .name(name)
        .type(type);
  }