32
32
import java .util .stream .Collectors ;
33
33
34
34
public abstract class BaseBuilder <B extends BaseBuilder <B , T >, T > implements Cloneable {
35
-
36
- private final B thisB ;
37
-
38
35
protected final List <RequestInterceptor > requestInterceptors = new ArrayList <>();
39
36
protected final List <ResponseInterceptor > responseInterceptors = new ArrayList <>();
40
37
protected Logger .Level logLevel = Logger .Level .NONE ;
@@ -56,37 +53,42 @@ public abstract class BaseBuilder<B extends BaseBuilder<B, T>, T> implements Clo
56
53
57
54
public BaseBuilder () {
58
55
super ();
59
- thisB = (B ) this ;
60
56
}
61
57
58
+ @ SuppressWarnings ("unchecked" )
62
59
public B logLevel (Logger .Level logLevel ) {
63
60
this .logLevel = logLevel ;
64
- return thisB ;
61
+ return ( B ) this ;
65
62
}
66
63
64
+ @ SuppressWarnings ("unchecked" )
67
65
public B contract (Contract contract ) {
68
66
this .contract = contract ;
69
- return thisB ;
67
+ return ( B ) this ;
70
68
}
71
69
70
+ @ SuppressWarnings ("unchecked" )
72
71
public B retryer (Retryer retryer ) {
73
72
this .retryer = retryer ;
74
- return thisB ;
73
+ return ( B ) this ;
75
74
}
76
75
76
+ @ SuppressWarnings ("unchecked" )
77
77
public B logger (Logger logger ) {
78
78
this .logger = logger ;
79
- return thisB ;
79
+ return ( B ) this ;
80
80
}
81
81
82
+ @ SuppressWarnings ("unchecked" )
82
83
public B encoder (Encoder encoder ) {
83
84
this .encoder = encoder ;
84
- return thisB ;
85
+ return ( B ) this ;
85
86
}
86
87
88
+ @ SuppressWarnings ("unchecked" )
87
89
public B decoder (Decoder decoder ) {
88
90
this .decoder = decoder ;
89
- return thisB ;
91
+ return ( B ) this ;
90
92
}
91
93
92
94
/**
@@ -99,25 +101,29 @@ public B decoder(Decoder decoder) {
99
101
*
100
102
* @since 9.6
101
103
*/
104
+ @ SuppressWarnings ("unchecked" )
102
105
public B doNotCloseAfterDecode () {
103
106
this .closeAfterDecode = false ;
104
- return thisB ;
107
+ return ( B ) this ;
105
108
}
106
109
110
+ @ SuppressWarnings ("unchecked" )
107
111
public B decodeVoid () {
108
112
this .decodeVoid = true ;
109
- return thisB ;
113
+ return ( B ) this ;
110
114
}
111
115
116
+ @ SuppressWarnings ("unchecked" )
112
117
public B queryMapEncoder (QueryMapEncoder queryMapEncoder ) {
113
118
this .queryMapEncoder = queryMapEncoder ;
114
- return thisB ;
119
+ return ( B ) this ;
115
120
}
116
121
117
122
/** Allows to map the response before passing it to the decoder. */
123
+ @ SuppressWarnings ("unchecked" )
118
124
public B mapAndDecode (ResponseMapper mapper , Decoder decoder ) {
119
125
this .decoder = new ResponseMappingDecoder (mapper , decoder );
120
- return thisB ;
126
+ return ( B ) this ;
121
127
}
122
128
123
129
/**
@@ -135,9 +141,10 @@ public B mapAndDecode(ResponseMapper mapper, Decoder decoder) {
135
141
*
136
142
* @since 11.9
137
143
*/
144
+ @ SuppressWarnings ("unchecked" )
138
145
public B dismiss404 () {
139
146
this .dismiss404 = true ;
140
- return thisB ;
147
+ return ( B ) this ;
141
148
}
142
149
143
150
/**
@@ -157,81 +164,91 @@ public B dismiss404() {
157
164
* @deprecated use {@link #dismiss404()} instead.
158
165
*/
159
166
@ Deprecated
167
+ @ SuppressWarnings ("unchecked" )
160
168
public B decode404 () {
161
169
this .dismiss404 = true ;
162
- return thisB ;
170
+ return ( B ) this ;
163
171
}
164
172
173
+ @ SuppressWarnings ("unchecked" )
165
174
public B errorDecoder (ErrorDecoder errorDecoder ) {
166
175
this .errorDecoder = errorDecoder ;
167
- return thisB ;
176
+ return ( B ) this ;
168
177
}
169
178
179
+ @ SuppressWarnings ("unchecked" )
170
180
public B options (Options options ) {
171
181
this .options = options ;
172
- return thisB ;
182
+ return ( B ) this ;
173
183
}
174
184
175
185
/** Adds a single request interceptor to the builder. */
186
+ @ SuppressWarnings ("unchecked" )
176
187
public B requestInterceptor (RequestInterceptor requestInterceptor ) {
177
188
this .requestInterceptors .add (requestInterceptor );
178
- return thisB ;
189
+ return ( B ) this ;
179
190
}
180
191
181
192
/**
182
193
* Sets the full set of request interceptors for the builder, overwriting any previous
183
194
* interceptors.
184
195
*/
196
+ @ SuppressWarnings ("unchecked" )
185
197
public B requestInterceptors (Iterable <RequestInterceptor > requestInterceptors ) {
186
198
this .requestInterceptors .clear ();
187
199
for (RequestInterceptor requestInterceptor : requestInterceptors ) {
188
200
this .requestInterceptors .add (requestInterceptor );
189
201
}
190
- return thisB ;
202
+ return ( B ) this ;
191
203
}
192
204
193
205
/**
194
206
* Sets the full set of request interceptors for the builder, overwriting any previous
195
207
* interceptors.
196
208
*/
209
+ @ SuppressWarnings ("unchecked" )
197
210
public B responseInterceptors (Iterable <ResponseInterceptor > responseInterceptors ) {
198
211
this .responseInterceptors .clear ();
199
212
for (ResponseInterceptor responseInterceptor : responseInterceptors ) {
200
213
this .responseInterceptors .add (responseInterceptor );
201
214
}
202
- return thisB ;
215
+ return ( B ) this ;
203
216
}
204
217
205
218
/** Adds a single response interceptor to the builder. */
219
+ @ SuppressWarnings ("unchecked" )
206
220
public B responseInterceptor (ResponseInterceptor responseInterceptor ) {
207
221
this .responseInterceptors .add (responseInterceptor );
208
- return thisB ;
222
+ return ( B ) this ;
209
223
}
210
224
211
225
/** Allows you to override how reflective dispatch works inside of Feign. */
226
+ @ SuppressWarnings ("unchecked" )
212
227
public B invocationHandlerFactory (InvocationHandlerFactory invocationHandlerFactory ) {
213
228
this .invocationHandlerFactory = invocationHandlerFactory ;
214
- return thisB ;
229
+ return ( B ) this ;
215
230
}
216
231
232
+ @ SuppressWarnings ("unchecked" )
217
233
public B exceptionPropagationPolicy (ExceptionPropagationPolicy propagationPolicy ) {
218
234
this .propagationPolicy = propagationPolicy ;
219
- return thisB ;
235
+ return ( B ) this ;
220
236
}
221
237
238
+ @ SuppressWarnings ("unchecked" )
222
239
public B addCapability (Capability capability ) {
223
240
this .capabilities .add (capability );
224
- return thisB ;
241
+ return ( B ) this ;
225
242
}
226
243
227
244
@ SuppressWarnings ("unchecked" )
228
245
B enrich () {
229
246
if (capabilities .isEmpty ()) {
230
- return thisB ;
247
+ return ( B ) this ;
231
248
}
232
249
233
250
try {
234
- B clone = (B ) thisB .clone ();
251
+ B clone = (B ) this .clone ();
235
252
236
253
getFieldsToEnrich ()
237
254
.forEach (
@@ -274,8 +291,6 @@ List<Field> getFieldsToEnrich() {
274
291
.filter (field -> !field .isSynthetic ())
275
292
// and capabilities itself
276
293
.filter (field -> !Objects .equals (field .getName (), "capabilities" ))
277
- // and thisB helper field
278
- .filter (field -> !Objects .equals (field .getName (), "thisB" ))
279
294
// skip primitive types
280
295
.filter (field -> !field .getType ().isPrimitive ())
281
296
// skip enumerations
0 commit comments