use of org.talend.sdk.component.api.configuration.ui.layout.GridLayout in project component-runtime by Talend.
the class UiParameterEnricher method toConfig.
private Map<String, String> toConfig(final Annotation annotation, final String prefix) {
// fine
if (GridLayout.class == annotation.annotationType()) {
final GridLayout layout = GridLayout.class.cast(annotation);
return Stream.of(layout.names()).flatMap(name -> Stream.of(annotation.annotationType().getMethods()).filter(m -> m.getDeclaringClass() == annotation.annotationType() && !"names".equals(m.getName())).collect(toMap(m -> prefix + name + "::" + m.getName(), m -> toString(annotation, m, invoke -> {
if (invoke.getClass().isArray()) {
final Class<?> component = invoke.getClass().getComponentType();
if (!Annotation.class.isAssignableFrom(component)) {
return null;
}
final int length = Array.getLength(invoke);
if (length == 0) {
return "";
}
final Collection<Method> mtds = Stream.of(component.getMethods()).filter(mtd -> mtd.getDeclaringClass() == component && "value".equals(mtd.getName())).collect(toList());
final StringBuilder builder = new StringBuilder("");
for (int i = 0; i < length; i++) {
final Object annot = Array.get(invoke, i);
mtds.forEach(p -> builder.append(toString(Annotation.class.cast(annot), p, o -> null)));
if (i + 1 < length) {
builder.append('|');
}
}
return builder.toString();
}
return null;
}))).entrySet().stream()).collect(toMap(Map.Entry::getKey, Map.Entry::getValue));
}
final Map<String, String> config = Stream.of(annotation.annotationType().getMethods()).filter(m -> m.getDeclaringClass() == annotation.annotationType()).collect(toMap(m -> prefix + m.getName(), m -> toString(annotation, m, invoke -> null)));
return config.isEmpty() ? singletonMap(prefix.substring(0, prefix.length() - "::".length()), "true") : config;
}
Aggregations