use of org.talend.sdk.component.runtime.visitor.ModelListener in project component-runtime by Talend.
the class ComponentValidator method validateModel.
private void validateModel(final AnnotationFinder finder, final List<Class<?>> components, final Set<String> errors) {
errors.addAll(components.stream().filter(c -> componentMarkers().filter(c::isAnnotationPresent).count() > 1).map(i -> i + " has conflicting component annotations, ensure it has a single one").collect(toList()));
final ModelVisitor modelVisitor = new ModelVisitor();
final ModelListener noop = new ModelListener() {
};
errors.addAll(components.stream().map(c -> {
try {
modelVisitor.visit(c, noop, configuration.isValidateComponent());
return null;
} catch (final RuntimeException re) {
return re.getMessage();
}
}).filter(Objects::nonNull).collect(toList()));
// limited config types
errors.addAll(finder.findAnnotatedFields(Structure.class).stream().filter(f -> !ParameterizedType.class.isInstance(f.getGenericType()) || (!isListString(f) && !isMapString(f))).map(f -> f.getDeclaringClass() + "#" + f.getName() + " uses @Structure but is not a List<String> nor a Map<String, String>").collect(toList()));
}
use of org.talend.sdk.component.runtime.visitor.ModelListener in project component-runtime by Talend.
the class ModelVisitorTest method visit.
private List<String> visit(final Class<?> type) {
final ModelVisitor visitor = new ModelVisitor();
final List<String> tracker = new ArrayList<>();
Stream.of(type.getClasses()).sorted(Comparator.comparing(Class::getName)).forEach(nested -> visitor.visit(nested, new ModelListener() {
@Override
public void onPartitionMapper(final Class<?> type, final PartitionMapper partitionMapper) {
tracker.add("@PartitionMapper(" + type.getName() + ")");
}
@Override
public void onEmitter(final Class<?> type, final Emitter emitter) {
tracker.add("@Emitter(" + type.getName() + ")");
}
@Override
public void onProcessor(final Class<?> type, final Processor processor) {
tracker.add("@Processor(" + type.getName() + ")");
}
}, true));
return tracker;
}
Aggregations