use of org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.SortedSetMultimap in project beam by apache.
the class PipelineOptionsFactory method validateReturnType.
/**
* Validates that any method with the same name must have the same return type for all derived
* interfaces of {@link PipelineOptions}.
*
* @param iface The interface to validate.
*/
private static void validateReturnType(Class<? extends PipelineOptions> iface) {
Iterable<Method> interfaceMethods = StreamSupport.stream(ReflectHelpers.getClosureOfMethodsOnInterface(iface).spliterator(), false).filter(input -> !input.isSynthetic()).collect(ImmutableSortedSet.toImmutableSortedSet(MethodComparator.INSTANCE));
SortedSetMultimap<Method, Method> methodNameToMethodMap = TreeMultimap.create(MethodNameComparator.INSTANCE, MethodComparator.INSTANCE);
for (Method method : interfaceMethods) {
methodNameToMethodMap.put(method, method);
}
List<MultipleDefinitions> multipleDefinitions = Lists.newArrayList();
for (Map.Entry<Method, Collection<Method>> entry : methodNameToMethodMap.asMap().entrySet()) {
Set<Class<?>> returnTypes = entry.getValue().stream().map(ReturnTypeFetchingFunction.INSTANCE).collect(Collectors.toSet());
SortedSet<Method> collidingMethods = StreamSupport.stream(entry.getValue().spliterator(), false).collect(ImmutableSortedSet.toImmutableSortedSet(MethodComparator.INSTANCE));
if (returnTypes.size() > 1) {
MultipleDefinitions defs = new MultipleDefinitions();
defs.method = entry.getKey();
defs.collidingMethods = collidingMethods;
multipleDefinitions.add(defs);
}
}
throwForMultipleDefinitions(iface, multipleDefinitions);
}
use of org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.SortedSetMultimap in project beam by apache.
the class PipelineOptionsFactory method validateGettersHaveConsistentAnnotation.
/**
* Validates that getters don't have mixed annotation.
*/
private static void validateGettersHaveConsistentAnnotation(SortedSetMultimap<Method, Method> methodNameToAllMethodMap, List<PropertyDescriptor> descriptors, final AnnotationPredicates annotationPredicates) {
List<InconsistentlyAnnotatedGetters> inconsistentlyAnnotatedGetters = new ArrayList<>();
for (final PropertyDescriptor descriptor : descriptors) {
if (descriptor.getReadMethod() == null || IGNORED_METHODS.contains(descriptor.getReadMethod())) {
continue;
}
SortedSet<Method> getters = methodNameToAllMethodMap.get(descriptor.getReadMethod());
SortedSet<Method> gettersWithTheAnnotation = Sets.filter(getters, annotationPredicates.forMethod);
Set<Annotation> distinctAnnotations = gettersWithTheAnnotation.stream().flatMap(method -> Arrays.stream(method.getAnnotations())).filter(annotationPredicates.forAnnotation).collect(Collectors.toSet());
if (distinctAnnotations.size() > 1) {
throw new IllegalArgumentException(String.format("Property [%s] is marked with contradictory annotations. Found [%s].", descriptor.getName(), gettersWithTheAnnotation.stream().flatMap(method -> Arrays.stream(method.getAnnotations()).filter(annotationPredicates.forAnnotation).map(annotation -> String.format("[%s on %s]", ReflectHelpers.formatAnnotation(annotation), ReflectHelpers.formatMethodWithClass(method)))).collect(Collectors.joining(", "))));
}
Iterable<String> getterClassNames = getters.stream().map(MethodToDeclaringClassFunction.INSTANCE).map(Class::getName).collect(Collectors.toList());
Iterable<String> gettersWithTheAnnotationClassNames = gettersWithTheAnnotation.stream().map(MethodToDeclaringClassFunction.INSTANCE).map(Class::getName).collect(Collectors.toList());
if (!(gettersWithTheAnnotation.isEmpty() || getters.size() == gettersWithTheAnnotation.size())) {
InconsistentlyAnnotatedGetters err = new InconsistentlyAnnotatedGetters();
err.descriptor = descriptor;
err.getterClassNames = getterClassNames;
err.gettersWithTheAnnotationClassNames = gettersWithTheAnnotationClassNames;
inconsistentlyAnnotatedGetters.add(err);
}
}
throwForGettersWithInconsistentAnnotation(inconsistentlyAnnotatedGetters, annotationPredicates.annotationClass);
}
Aggregations