1313 */
1414package feign ;
1515
16+ import static feign .Util .checkState ;
17+ import static feign .Util .emptyToNull ;
1618import java .lang .annotation .Annotation ;
1719import java .lang .reflect .*;
1820import java .net .URI ;
1921import java .util .*;
20- import java .util .function .BiConsumer ;
21- import java .util .function .BiFunction ;
2222import java .util .regex .Matcher ;
2323import java .util .regex .Pattern ;
24- import java .util .stream .Collectors ;
25- import feign .Contract .DeclarativeContract .ClassAnnotationProcessor ;
2624import feign .Request .HttpMethod ;
27- import static feign .Util .checkState ;
28- import static feign .Util .emptyToNull ;
2925
3026/**
3127 * Defines what annotations and values are valid on interfaces.
@@ -106,9 +102,15 @@ protected MethodMetadata parseAndValidateMetadata(Class<?> targetType, Method me
106102 if (parameterAnnotations [i ] != null ) {
107103 isHttpAnnotation = processAnnotationsOnParameter (data , parameterAnnotations [i ], i );
108104 }
105+
106+ if (isHttpAnnotation ) {
107+ data .ignoreParamater (i );
108+ }
109+
109110 if (parameterTypes [i ] == URI .class ) {
110111 data .urlIndex (i );
111- } else if (!isHttpAnnotation && parameterTypes [i ] != Request .Options .class ) {
112+ } else if (!isHttpAnnotation && parameterTypes [i ] != Request .Options .class
113+ && !data .isAlreadyProcessed (i )) {
112114 checkState (data .formParams ().isEmpty (),
113115 "Body parameters cannot be used with form parameters." );
114116 checkState (data .bodyIndex () == null , "Method has too many Body parameters: %s" , method );
@@ -220,6 +222,7 @@ public abstract class DeclarativeContract extends BaseContract {
220222 Map <Class <Annotation >, ParameterAnnotationProcessor <Annotation >> parameterAnnotationProcessors =
221223 new HashMap <>();
222224
225+ @ Override
223226 public final List <MethodMetadata > parseAndValidatateMetadata (Class <?> targetType ) {
224227 // any implementations must register processors
225228 return super .parseAndValidatateMetadata (targetType );
@@ -263,17 +266,17 @@ protected void processAnnotationOnMethod(MethodMetadata data,
263266 * @return true if you called {@link #nameParam(MethodMetadata, String, int)} after finding an
264267 * http-relevant annotation.
265268 */
269+ @ Override
266270 protected final boolean processAnnotationsOnParameter (MethodMetadata data ,
267271 Annotation [] annotations ,
268272 int paramIndex ) {
269- return Arrays .stream (annotations )
273+ Arrays .stream (annotations )
270274 .filter (
271275 annotation -> parameterAnnotationProcessors .containsKey (annotation .annotationType ()))
272- .map (annotation -> parameterAnnotationProcessors
276+ .forEach (annotation -> parameterAnnotationProcessors
273277 .getOrDefault (annotation .annotationType (), ParameterAnnotationProcessor .DO_NOTHING )
274- .process (annotation , data , paramIndex ))
275- .collect (Collectors .reducing (Boolean ::logicalOr ))
276- .orElse (false );
278+ .process (annotation , data , paramIndex ));
279+ return false ;
277280 }
278281
279282 @ FunctionalInterface
@@ -332,7 +335,8 @@ protected <E extends Annotation> void registerMethodAnnotation(Class<E> annotati
332335 @ FunctionalInterface
333336 public interface ParameterAnnotationProcessor <E extends Annotation > {
334337
335- ParameterAnnotationProcessor <Annotation > DO_NOTHING = (ann , data , i ) -> false ;
338+ ParameterAnnotationProcessor <Annotation > DO_NOTHING = (ann , data , i ) -> {
339+ };
336340
337341 /**
338342 * @param annotation present on the current parameter annotation.
@@ -342,7 +346,7 @@ public interface ParameterAnnotationProcessor<E extends Annotation> {
342346 * @return true if you called {@link #nameParam(MethodMetadata, String, int)} after finding an
343347 * http-relevant annotation.
344348 */
345- boolean process (E annotation , MethodMetadata metadata , int paramIndex );
349+ void process (E annotation , MethodMetadata metadata , int paramIndex );
346350 }
347351
348352 /**
@@ -424,20 +428,17 @@ public Default() {
424428 if (!data .template ().hasRequestVariable (name )) {
425429 data .formParams ().add (name );
426430 }
427- return true ;
428431 });
429432 super .registerParameterAnnotation (QueryMap .class , (queryMap , data , paramIndex ) -> {
430433 checkState (data .queryMapIndex () == null ,
431434 "QueryMap annotation was present on multiple parameters." );
432435 data .queryMapIndex (paramIndex );
433436 data .queryMapEncoded (queryMap .encoded ());
434- return true ;
435437 });
436438 super .registerParameterAnnotation (HeaderMap .class , (queryMap , data , paramIndex ) -> {
437439 checkState (data .headerMapIndex () == null ,
438440 "HeaderMap annotation was present on multiple parameters." );
439441 data .headerMapIndex (paramIndex );
440- return true ;
441442 });
442443 }
443444
0 commit comments