14
14
import java .util .Map ;
15
15
16
16
import org .hibernate .validator .internal .util .CollectionHelper ;
17
- import org .hibernate .validator .internal .util .StringHelper ;
18
17
import org .hibernate .validator .internal .util .annotation .AnnotationDescriptor ;
19
18
import org .hibernate .validator .internal .util .logging .Log ;
20
19
import org .hibernate .validator .internal .util .logging .LoggerFactory ;
32
31
* @author Hardy Ferentschik
33
32
* @author Gunnar Morling
34
33
* @author Marko Bekhta
34
+ * @author Guillaume Smet
35
35
*/
36
36
public abstract class AnnotationDef <C extends AnnotationDef <C , A >, A extends Annotation > {
37
37
@@ -42,16 +42,9 @@ public abstract class AnnotationDef<C extends AnnotationDef<C, A>, A extends Ann
42
42
// public getters as they would pollute the fluent definition API.
43
43
44
44
/**
45
- * The constraint annotation type of this definition .
45
+ * The annotation descriptor builder .
46
46
*/
47
- protected final Class <A > annotationType ;
48
-
49
- /**
50
- * A map with the annotation parameters of this definition. Contains only parameters
51
- * of non annotation types. Keys are property names of this definition's annotation
52
- * type, values are annotation parameter values of the appropriate types.
53
- */
54
- protected final Map <String , Object > parameters ;
47
+ protected final AnnotationDescriptor .Builder <A > annotationDescriptorBuilder ;
55
48
56
49
/**
57
50
* A map with annotation parameters of this definition which are annotations
@@ -71,15 +64,13 @@ public abstract class AnnotationDef<C extends AnnotationDef<C, A>, A extends Ann
71
64
private final Map <String , Class <?>> annotationsAsParametersTypes ;
72
65
73
66
protected AnnotationDef (Class <A > annotationType ) {
74
- this .annotationType = annotationType ;
75
- this .parameters = new HashMap <>();
67
+ this .annotationDescriptorBuilder = new AnnotationDescriptor .Builder <>( annotationType );
76
68
this .annotationsAsParameters = new HashMap <>();
77
69
this .annotationsAsParametersTypes = new HashMap <>();
78
70
}
79
71
80
72
protected AnnotationDef (AnnotationDef <?, A > original ) {
81
- this .annotationType = original .annotationType ;
82
- this .parameters = original .parameters ;
73
+ this .annotationDescriptorBuilder = original .annotationDescriptorBuilder ;
83
74
this .annotationsAsParameters = original .annotationsAsParameters ;
84
75
this .annotationsAsParametersTypes = original .annotationsAsParametersTypes ;
85
76
}
@@ -90,7 +81,7 @@ private C getThis() {
90
81
}
91
82
92
83
protected C addParameter (String key , Object value ) {
93
- parameters . put ( key , value );
84
+ annotationDescriptorBuilder . setAttribute ( key , value );
94
85
return getThis ();
95
86
}
96
87
@@ -105,16 +96,11 @@ protected C addAnnotationAsParameter(String key, AnnotationDef<?, ?> value) {
105
96
return resultingList ;
106
97
}
107
98
} );
108
- annotationsAsParametersTypes .putIfAbsent ( key , value .annotationType );
99
+ annotationsAsParametersTypes .putIfAbsent ( key , value .annotationDescriptorBuilder . getType () );
109
100
return getThis ();
110
101
}
111
102
112
103
protected AnnotationDescriptor <A > createAnnotationDescriptor () {
113
- AnnotationDescriptor .Builder <A > annotationDescriptorBuilder = new AnnotationDescriptor .Builder <>( annotationType );
114
- for ( Map .Entry <String , Object > parameter : parameters .entrySet () ) {
115
- annotationDescriptorBuilder .setAttribute ( parameter .getKey (), parameter .getValue () );
116
- }
117
-
118
104
for ( Map .Entry <String , List <AnnotationDef <?, ?>>> annotationAsParameter : annotationsAsParameters .entrySet () ) {
119
105
annotationDescriptorBuilder .setAttribute (
120
106
annotationAsParameter .getKey (),
@@ -149,8 +135,7 @@ public String toString() {
149
135
final StringBuilder sb = new StringBuilder ();
150
136
sb .append ( this .getClass ().getSimpleName () );
151
137
sb .append ( '{' );
152
- sb .append ( "annotationType=" ).append ( StringHelper .toShortString ( annotationType ) );
153
- sb .append ( ", parameters=" ).append ( parameters );
138
+ sb .append ( annotationDescriptorBuilder );
154
139
sb .append ( '}' );
155
140
return sb .toString ();
156
141
}
0 commit comments