@Override public T build() { return (T) transformation.createInstantiator().newInstance(); } }
@Override public T build() { return (T) transformation.createInstantiator().newInstance(); } }
/** * Creates an entirely new class, extending from the provided base class. * * @param baseClass * class to extend from, which must be a class, not an interface * @param callback * used to configure the new class * @return the instantiator, which allows instances of the new class to be created */ public <T> ClassInstantiator<T> createClass(Class<T> baseClass, PlasticClassTransformer callback) { assert baseClass != null; assert callback != null; if (baseClass.isInterface()) throw new IllegalArgumentException(String.format("Class %s defines an interface, not a base class.", baseClass.getName())); String name = String.format("$%s_%s", baseClass.getSimpleName(), PlasticUtils.nextUID()); PlasticClassTransformation<T> transformation = pool.createTransformation(baseClass.getName(), name); callback.transform(transformation.getPlasticClass()); return transformation.createInstantiator(); }
/** * Creates an entirely new class, extending from the provided base class. * * @param baseClass * class to extend from, which must be a class, not an interface * @param callback * used to configure the new class * @return the instantiator, which allows instances of the new class to be created */ public <T> ClassInstantiator<T> createClass(Class<T> baseClass, PlasticClassTransformer callback) { assert baseClass != null; assert callback != null; if (baseClass.isInterface()) throw new IllegalArgumentException(String.format("Class %s defines an interface, not a base class.", baseClass.getName())); String name = String.format("$%s_%s", baseClass.getSimpleName(), PlasticUtils.nextUID()); PlasticClassTransformation<T> transformation = pool.createTransformation(baseClass.getName(), name); callback.transform(transformation.getPlasticClass()); return transformation.createInstantiator(); }
/** * Creates an entirely new class. The class extends from Object and implements the provided interface. * * @param interfaceType * class to extend from, which must be a class, not an interface * @param implementationType * class that implements interfaceType. It can be null. * @param callback * used to configure the new class * @return the instantiator, which allows instances of the new class to be created * @see #createProxyTransformation(Class, Class) * @since 5.4 */ public <T> ClassInstantiator<T> createProxy(Class<T> interfaceType, Class<? extends T> implementationType, PlasticClassTransformer callback) { assert callback != null; PlasticClassTransformation<T> transformation = createProxyTransformation(interfaceType, implementationType); callback.transform(transformation.getPlasticClass()); return transformation.createInstantiator(); }
/** * Creates an entirely new class. The class extends from Object and implements the provided interface. * * @param interfaceType * class to extend from, which must be a class, not an interface * @param implementationType * class that implements interfaceType. It can be null. * @param callback * used to configure the new class * @return the instantiator, which allows instances of the new class to be created * @see #createProxyTransformation(Class, Class) * @since 5.4 */ public <T> ClassInstantiator<T> createProxy(Class<T> interfaceType, Class<? extends T> implementationType, PlasticClassTransformer callback) { assert callback != null; PlasticClassTransformation<T> transformation = createProxyTransformation(interfaceType, implementationType); callback.transform(transformation.getPlasticClass()); return transformation.createInstantiator(); }