Skip to content

Commit a7d8b92

Browse files
committed
Refactoring: Move resolveLastTypeParameter from Util to Types
1 parent 34a7272 commit a7d8b92

File tree

2 files changed

+35
-24
lines changed

2 files changed

+35
-24
lines changed

core/src/main/java/feign/Types.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import java.util.Arrays;
2424
import java.util.NoSuchElementException;
2525

26+
import static feign.Util.checkState;
27+
2628
/**
2729
* Static methods for working with types.
2830
*
@@ -325,6 +327,36 @@ public static Type resolveReturnType(Type baseType, Type overridingType) {
325327
return baseType;
326328
}
327329

330+
/**
331+
* Resolves the last type parameter of the parameterized {@code supertype}, based on the {@code
332+
* genericContext}, into its upper bounds.
333+
* <p/>
334+
* Implementation copied from {@code
335+
* retrofit.RestMethodInfo}.
336+
*
337+
* @param genericContext Ex. {@link java.lang.reflect.Field#getGenericType()}
338+
* @param supertype Ex. {@code Decoder.class}
339+
* @return in the example above, the type parameter of {@code Decoder}.
340+
* @throws IllegalStateException if {@code supertype} cannot be resolved into a parameterized type
341+
* using {@code context}.
342+
*/
343+
public static Type resolveLastTypeParameter(Type genericContext, Class<?> supertype)
344+
throws IllegalStateException {
345+
Type resolvedSuperType =
346+
Types.getSupertype(genericContext, Types.getRawType(genericContext), supertype);
347+
checkState(resolvedSuperType instanceof ParameterizedType,
348+
"could not resolve %s into a parameterized type %s",
349+
genericContext, supertype);
350+
Type[] types = ParameterizedType.class.cast(resolvedSuperType).getActualTypeArguments();
351+
for (int i = 0; i < types.length; i++) {
352+
Type type = types[i];
353+
if (type instanceof WildcardType) {
354+
types[i] = ((WildcardType) type).getUpperBounds()[0];
355+
}
356+
}
357+
return types[types.length - 1];
358+
}
359+
328360
static final class ParameterizedTypeImpl implements ParameterizedType {
329361

330362
private final Type ownerType;

core/src/main/java/feign/Util.java

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -215,33 +215,12 @@ public static void ensureClosed(Closeable closeable) {
215215
}
216216

217217
/**
218-
* Resolves the last type parameter of the parameterized {@code supertype}, based on the {@code
219-
* genericContext}, into its upper bounds.
220-
* <p/>
221-
* Implementation copied from {@code
222-
* retrofit.RestMethodInfo}.
223-
*
224-
* @param genericContext Ex. {@link java.lang.reflect.Field#getGenericType()}
225-
* @param supertype Ex. {@code Decoder.class}
226-
* @return in the example above, the type parameter of {@code Decoder}.
227-
* @throws IllegalStateException if {@code supertype} cannot be resolved into a parameterized type
228-
* using {@code context}.
218+
* Moved to {@code feign.Types.resolveLastTypeParameter}
229219
*/
220+
@Deprecated
230221
public static Type resolveLastTypeParameter(Type genericContext, Class<?> supertype)
231222
throws IllegalStateException {
232-
Type resolvedSuperType =
233-
Types.getSupertype(genericContext, Types.getRawType(genericContext), supertype);
234-
checkState(resolvedSuperType instanceof ParameterizedType,
235-
"could not resolve %s into a parameterized type %s",
236-
genericContext, supertype);
237-
Type[] types = ParameterizedType.class.cast(resolvedSuperType).getActualTypeArguments();
238-
for (int i = 0; i < types.length; i++) {
239-
Type type = types[i];
240-
if (type instanceof WildcardType) {
241-
types[i] = ((WildcardType) type).getUpperBounds()[0];
242-
}
243-
}
244-
return types[types.length - 1];
223+
return Types.resolveLastTypeParameter(genericContext, supertype);
245224
}
246225

247226
/**

0 commit comments

Comments
 (0)