use of com.google.gwt.uibinder.client.UiConstructor in project gwt-test-utils by gwt-test-utils.
the class UiBinderInstanciator method getObjectFromUiConstructor.
private static <U> U getObjectFromUiConstructor(Class<U> clazz, Map<String, Object> attributes) {
for (Constructor<?> cons : clazz.getDeclaredConstructors()) {
if (cons.getAnnotation(UiConstructor.class) == null) {
continue;
}
Constructor<U> uiConstructor = (Constructor<U>) cons;
String[] argNames = GwtParanamer.get().lookupParameterNames(uiConstructor);
if (allArgsAreDeclaredInUiFile(argNames, attributes)) {
List<Object> constructorArgs = extractArgs(argNames, attributes);
if (constructorArgs != null) {
Class<?>[] paramTypes = uiConstructor.getParameterTypes();
for (int i = 0; i < argNames.length; i++) {
String argName = argNames[i];
try {
Object convertedArg = convertArgs(paramTypes[i], constructorArgs.get(i));
constructorArgs.set(i, convertedArg);
// remove the attribute from the map to populate the widget with since it's
// used in the constructor
attributes.remove(argName);
} catch (Exception e) {
throw new GwtTestUiBinderException("Error while converting argument " + argNames[i] + " to " + paramTypes[i], e);
}
}
}
return instanciate(uiConstructor, constructorArgs);
}
}
return null;
}
Aggregations