Search in sources :

Example 1 with SortedSetMultimap

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);
}
Also used : Arrays(java.util.Arrays) PipelineOptionDescriptor(org.apache.beam.model.jobmanagement.v1.JobApi.PipelineOptionDescriptor) Joiner(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Joiner) ImmutableMap(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableMap) TreeTraversingParser(com.fasterxml.jackson.databind.node.TreeTraversingParser) DefaultSerializerProvider(com.fasterxml.jackson.databind.ser.DefaultSerializerProvider) ImmutableSet(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableSet) Strings(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Strings) KeyFor(org.checkerframework.checker.nullness.qual.KeyFor) Map(java.util.Map) JsonSerializer(com.fasterxml.jackson.databind.JsonSerializer) JsonNode(com.fasterxml.jackson.databind.JsonNode) BigInteger(java.math.BigInteger) Predicates(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Predicates) Iterators(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.Iterators) BeanProperty(com.fasterxml.jackson.databind.BeanProperty) Set(java.util.Set) TreeMultimap(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.TreeMultimap) IntrospectionException(java.beans.IntrospectionException) Stream(java.util.stream.Stream) VisibleForTesting(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.annotations.VisibleForTesting) PropertyDescriptor(java.beans.PropertyDescriptor) RowSortedTable(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.RowSortedTable) TypeResolutionContext(com.fasterxml.jackson.databind.introspect.TypeResolutionContext) JsonDeserialize(com.fasterxml.jackson.databind.annotation.JsonDeserialize) Preconditions.checkNotNull(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Preconditions.checkNotNull) InjectableValues(com.fasterxml.jackson.databind.InjectableValues) Proxy(java.lang.reflect.Proxy) Experimental(org.apache.beam.sdk.annotations.Experimental) DefaultDeserializationContext(com.fasterxml.jackson.databind.deser.DefaultDeserializationContext) Optional(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Optional) TreeSet(java.util.TreeSet) ImmutableListMultimap(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableListMultimap) ArrayList(java.util.ArrayList) Introspector(java.beans.Introspector) SortedSetMultimap(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.SortedSetMultimap) PipelineRunner(org.apache.beam.sdk.PipelineRunner) BeanInfo(java.beans.BeanInfo) PipelineOptionType(org.apache.beam.model.jobmanagement.v1.JobApi.PipelineOptionType) Preconditions.checkArgument(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Preconditions.checkArgument) Maps(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.Maps) StreamSupport(java.util.stream.StreamSupport) StringUtils(org.apache.beam.sdk.util.StringUtils) JavaType(com.fasterxml.jackson.databind.JavaType) LinkedHashSet(java.util.LinkedHashSet) PipelineRunnerRegistrar(org.apache.beam.sdk.runners.PipelineRunnerRegistrar) IOException(java.io.IOException) TreeMap(java.util.TreeMap) BeanPropertyDefinition(com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition) TokenBuffer(com.fasterxml.jackson.databind.util.TokenBuffer) Ordering(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.Ordering) SortedSet(java.util.SortedSet) TypeDeserializer(com.fasterxml.jackson.databind.jsontype.TypeDeserializer) LoggerFactory(org.slf4j.LoggerFactory) TreeBasedTable(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.TreeBasedTable) Sets(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.Sets) Iterables(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.Iterables) AnnotatedMember(com.fasterxml.jackson.databind.introspect.AnnotatedMember) TypeWrappedDeserializer(com.fasterxml.jackson.databind.deser.impl.TypeWrappedDeserializer) JsonDeserializer(com.fasterxml.jackson.databind.JsonDeserializer) JsonParseException(com.fasterxml.jackson.core.JsonParseException) Method(java.lang.reflect.Method) MethodProperty(com.fasterxml.jackson.databind.deser.impl.MethodProperty) SimpleBeanPropertyDefinition(com.fasterxml.jackson.databind.util.SimpleBeanPropertyDefinition) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) List(java.util.List) Type(java.lang.reflect.Type) Modifier(java.lang.reflect.Modifier) ReflectHelpers(org.apache.beam.sdk.util.common.ReflectHelpers) Annotation(java.lang.annotation.Annotation) ListMultimap(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ListMultimap) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) SortedMap(java.util.SortedMap) Required(org.apache.beam.sdk.options.Validation.Required) CaseFormat(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.CaseFormat) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) ImmutableSortedSet(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableSortedSet) JsonSerialize(com.fasterxml.jackson.databind.annotation.JsonSerialize) TypeBindings(com.fasterxml.jackson.databind.type.TypeBindings) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore) AnnotationCollector(com.fasterxml.jackson.databind.introspect.AnnotationCollector) ROOT(java.util.Locale.ROOT) AnnotatedMethod(com.fasterxml.jackson.databind.introspect.AnnotatedMethod) NoSuchElementException(java.util.NoSuchElementException) Nonnull(javax.annotation.Nonnull) Predicate(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Predicate) Nullable(org.checkerframework.checker.nullness.qual.Nullable) PrintStream(java.io.PrintStream) DisplayData(org.apache.beam.sdk.transforms.display.DisplayData) Logger(org.slf4j.Logger) JsonParser(com.fasterxml.jackson.core.JsonParser) Iterator(java.util.Iterator) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Lists(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.Lists) Comparator(java.util.Comparator) Collections(java.util.Collections) Collection(java.util.Collection) Method(java.lang.reflect.Method) AnnotatedMethod(com.fasterxml.jackson.databind.introspect.AnnotatedMethod) ImmutableMap(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableMap) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap)

Example 2 with SortedSetMultimap

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);
}
Also used : Arrays(java.util.Arrays) PipelineOptionDescriptor(org.apache.beam.model.jobmanagement.v1.JobApi.PipelineOptionDescriptor) Joiner(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Joiner) ImmutableMap(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableMap) TreeTraversingParser(com.fasterxml.jackson.databind.node.TreeTraversingParser) DefaultSerializerProvider(com.fasterxml.jackson.databind.ser.DefaultSerializerProvider) ImmutableSet(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableSet) Strings(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Strings) KeyFor(org.checkerframework.checker.nullness.qual.KeyFor) Map(java.util.Map) JsonSerializer(com.fasterxml.jackson.databind.JsonSerializer) JsonNode(com.fasterxml.jackson.databind.JsonNode) BigInteger(java.math.BigInteger) Predicates(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Predicates) Iterators(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.Iterators) BeanProperty(com.fasterxml.jackson.databind.BeanProperty) Set(java.util.Set) TreeMultimap(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.TreeMultimap) IntrospectionException(java.beans.IntrospectionException) Stream(java.util.stream.Stream) VisibleForTesting(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.annotations.VisibleForTesting) PropertyDescriptor(java.beans.PropertyDescriptor) RowSortedTable(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.RowSortedTable) TypeResolutionContext(com.fasterxml.jackson.databind.introspect.TypeResolutionContext) JsonDeserialize(com.fasterxml.jackson.databind.annotation.JsonDeserialize) Preconditions.checkNotNull(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Preconditions.checkNotNull) InjectableValues(com.fasterxml.jackson.databind.InjectableValues) Proxy(java.lang.reflect.Proxy) Experimental(org.apache.beam.sdk.annotations.Experimental) DefaultDeserializationContext(com.fasterxml.jackson.databind.deser.DefaultDeserializationContext) Optional(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Optional) TreeSet(java.util.TreeSet) ImmutableListMultimap(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableListMultimap) ArrayList(java.util.ArrayList) Introspector(java.beans.Introspector) SortedSetMultimap(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.SortedSetMultimap) PipelineRunner(org.apache.beam.sdk.PipelineRunner) BeanInfo(java.beans.BeanInfo) PipelineOptionType(org.apache.beam.model.jobmanagement.v1.JobApi.PipelineOptionType) Preconditions.checkArgument(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Preconditions.checkArgument) Maps(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.Maps) StreamSupport(java.util.stream.StreamSupport) StringUtils(org.apache.beam.sdk.util.StringUtils) JavaType(com.fasterxml.jackson.databind.JavaType) LinkedHashSet(java.util.LinkedHashSet) PipelineRunnerRegistrar(org.apache.beam.sdk.runners.PipelineRunnerRegistrar) IOException(java.io.IOException) TreeMap(java.util.TreeMap) BeanPropertyDefinition(com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition) TokenBuffer(com.fasterxml.jackson.databind.util.TokenBuffer) Ordering(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.Ordering) SortedSet(java.util.SortedSet) TypeDeserializer(com.fasterxml.jackson.databind.jsontype.TypeDeserializer) LoggerFactory(org.slf4j.LoggerFactory) TreeBasedTable(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.TreeBasedTable) Sets(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.Sets) Iterables(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.Iterables) AnnotatedMember(com.fasterxml.jackson.databind.introspect.AnnotatedMember) TypeWrappedDeserializer(com.fasterxml.jackson.databind.deser.impl.TypeWrappedDeserializer) JsonDeserializer(com.fasterxml.jackson.databind.JsonDeserializer) JsonParseException(com.fasterxml.jackson.core.JsonParseException) Method(java.lang.reflect.Method) MethodProperty(com.fasterxml.jackson.databind.deser.impl.MethodProperty) SimpleBeanPropertyDefinition(com.fasterxml.jackson.databind.util.SimpleBeanPropertyDefinition) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) List(java.util.List) Type(java.lang.reflect.Type) Modifier(java.lang.reflect.Modifier) ReflectHelpers(org.apache.beam.sdk.util.common.ReflectHelpers) Annotation(java.lang.annotation.Annotation) ListMultimap(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ListMultimap) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) SortedMap(java.util.SortedMap) Required(org.apache.beam.sdk.options.Validation.Required) CaseFormat(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.CaseFormat) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) ImmutableSortedSet(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableSortedSet) JsonSerialize(com.fasterxml.jackson.databind.annotation.JsonSerialize) TypeBindings(com.fasterxml.jackson.databind.type.TypeBindings) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore) AnnotationCollector(com.fasterxml.jackson.databind.introspect.AnnotationCollector) ROOT(java.util.Locale.ROOT) AnnotatedMethod(com.fasterxml.jackson.databind.introspect.AnnotatedMethod) NoSuchElementException(java.util.NoSuchElementException) Nonnull(javax.annotation.Nonnull) Predicate(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Predicate) Nullable(org.checkerframework.checker.nullness.qual.Nullable) PrintStream(java.io.PrintStream) DisplayData(org.apache.beam.sdk.transforms.display.DisplayData) Logger(org.slf4j.Logger) JsonParser(com.fasterxml.jackson.core.JsonParser) Iterator(java.util.Iterator) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Lists(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.Lists) Comparator(java.util.Comparator) Collections(java.util.Collections) PropertyDescriptor(java.beans.PropertyDescriptor) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) AnnotatedMethod(com.fasterxml.jackson.databind.introspect.AnnotatedMethod) Annotation(java.lang.annotation.Annotation)

Aggregations

JsonIgnore (com.fasterxml.jackson.annotation.JsonIgnore)2 JsonParseException (com.fasterxml.jackson.core.JsonParseException)2 JsonParser (com.fasterxml.jackson.core.JsonParser)2 BeanProperty (com.fasterxml.jackson.databind.BeanProperty)2 InjectableValues (com.fasterxml.jackson.databind.InjectableValues)2 JavaType (com.fasterxml.jackson.databind.JavaType)2 JsonDeserializer (com.fasterxml.jackson.databind.JsonDeserializer)2 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 JsonSerializer (com.fasterxml.jackson.databind.JsonSerializer)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 JsonDeserialize (com.fasterxml.jackson.databind.annotation.JsonDeserialize)2 JsonSerialize (com.fasterxml.jackson.databind.annotation.JsonSerialize)2 DefaultDeserializationContext (com.fasterxml.jackson.databind.deser.DefaultDeserializationContext)2 MethodProperty (com.fasterxml.jackson.databind.deser.impl.MethodProperty)2 TypeWrappedDeserializer (com.fasterxml.jackson.databind.deser.impl.TypeWrappedDeserializer)2 AnnotatedMember (com.fasterxml.jackson.databind.introspect.AnnotatedMember)2 AnnotatedMethod (com.fasterxml.jackson.databind.introspect.AnnotatedMethod)2 AnnotationCollector (com.fasterxml.jackson.databind.introspect.AnnotationCollector)2 BeanPropertyDefinition (com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition)2