Search in sources :

Example 1 with UiFactory

use of com.google.gwt.uibinder.client.UiFactory in project gwt-test-utils by gwt-test-utils.

the class UiBinderInstanciator method getObjectFromUiFactory.

private static <U> U getObjectFromUiFactory(Class<U> clazz, Object owner) {
    Map<Method, UiFactory> map = GwtReflectionUtils.getAnnotatedMethod(owner.getClass(), UiFactory.class);
    List<Method> compatibleFactories = new ArrayList<Method>();
    for (Method factoryMethod : map.keySet()) {
        if (clazz.isAssignableFrom(factoryMethod.getReturnType())) {
            compatibleFactories.add(factoryMethod);
        }
    }
    switch(compatibleFactories.size()) {
        case 0:
            return null;
        case 1:
            return (U) GwtReflectionUtils.callPrivateMethod(owner, compatibleFactories.get(0));
        default:
            throw new GwtTestUiBinderException("Duplicate factory in class '" + owner.getClass().getName() + " for type '" + clazz.getName() + "'");
    }
}
Also used : GwtTestUiBinderException(com.googlecode.gwt.test.exceptions.GwtTestUiBinderException) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) UiFactory(com.google.gwt.uibinder.client.UiFactory)

Aggregations

UiFactory (com.google.gwt.uibinder.client.UiFactory)1 GwtTestUiBinderException (com.googlecode.gwt.test.exceptions.GwtTestUiBinderException)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1