2 * This file is part of yosql. It is subject to the license terms in the LICENSE file found in the top-level
3 * directory of this distribution and at https://creativecommons.org/publicdomain/zero/1.0/. No part of yosql,
4 * including this file, may be copied, modified, propagated, or distributed except according to the terms contained
7 package wtf
.metio
.yosql
.models
.configuration
;
9 import com
.fasterxml
.jackson
.databind
.annotation
.JsonDeserialize
;
10 import com
.fasterxml
.jackson
.databind
.annotation
.JsonSerialize
;
11 import org
.immutables
.value
.Value
;
12 import wtf
.metio
.yosql
.internals
.jdk
.Buckets
;
14 import java
.util
.List
;
15 import java
.util
.stream
.Collectors
;
16 import java
.util
.stream
.Stream
;
19 * Configuration for an extra annotation that is to be placed on a constructor or method in generated code.
23 as
= ImmutableAnnotation
.class
26 as
= ImmutableAnnotation
.class
28 public interface Annotation
{
32 static ImmutableAnnotation
.TypeBuildStage
builder() {
33 return ImmutableAnnotation
.builder();
36 static ImmutableAnnotation
copyOf(final Annotation annotation
) {
37 return ImmutableAnnotation
.copyOf(annotation
);
44 static List
<Annotation
> mergeAnnotations(
45 final List
<Annotation
> first
,
46 final List
<Annotation
> second
) {
47 if (first
== null || first
.isEmpty()) {
50 return Stream
.concat(copyAttributes(first
, second
), copyAttributes(second
, first
))
51 .filter(Buckets
.distinctByKey(Annotation
::type
))
52 .collect(Collectors
.toList());
55 private static Stream
<ImmutableAnnotation
> copyAttributes(
56 final List
<Annotation
> first
,
57 final List
<Annotation
> second
) {
59 .map(annotation
-> second
.stream()
60 .filter(other
-> annotation
.type().equals(other
.type()))
62 .map(other
-> Annotation
.copyOf(annotation
)
63 .withMembers(mergeMembers(annotation
.members(), other
.members())))
64 .orElseGet(() -> Annotation
.copyOf(annotation
)));
67 private static List
<AnnotationMember
> mergeMembers(
68 final List
<AnnotationMember
> first
,
69 final List
<AnnotationMember
> second
) {
70 if (first
== null || first
.isEmpty()) {
73 return Stream
.concat(first
.stream(), second
.stream())
74 .filter(Buckets
.distinctByKey(AnnotationMember
::key
))
75 .collect(Collectors
.toList());
81 * @return The fully-qualified type name of this annotation.
86 * @return The members of this annotation.
88 List
<AnnotationMember
> members();