Skip to content

Commit 84c21d4

Browse files
committed
Types: rename a couple of methods, for clarity
The following methods were renamed: * type(Field, Class) -> fieldType(Field, Class) * returnType(Method, Class) -> methodReturnType(Method, Class) * paramTypes(Method, Class) -> methodParamTypes(Method, Class) These methods are all very similar: they all narrow the generic types using information from the given subclass w.r.t. where the field/method in question was originally defined.
1 parent 3f50b96 commit 84c21d4

File tree

6 files changed

+37
-33
lines changed

6 files changed

+37
-33
lines changed

src/main/java/org/scijava/command/CommandModuleItem.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,15 @@ public Parameter getParameter() {
7676

7777
@Override
7878
public Class<T> getType() {
79-
final Class<?> type = Types.raw(Types.type(field, getDelegateClass()));
79+
final Class<?> type = Types.raw(Types.fieldType(field, getDelegateClass()));
8080
@SuppressWarnings("unchecked")
8181
final Class<T> typedType = (Class<T>) type;
8282
return typedType;
8383
}
8484

8585
@Override
8686
public Type getGenericType() {
87-
return Types.type(field, getDelegateClass());
87+
return Types.fieldType(field, getDelegateClass());
8888
}
8989

9090
@Override

src/main/java/org/scijava/util/ClassUtils.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ public static void setValue(final Field field, final Object instance,
442442
}
443443
else {
444444
// the given value needs to be converted to a compatible type
445-
final Type fieldType = Types.type(field, instance.getClass());
445+
final Type fieldType = Types.fieldType(field, instance.getClass());
446446
@SuppressWarnings("deprecation")
447447
final Object convertedValue = ConversionUtils.convert(value, fieldType);
448448
compatibleValue = convertedValue;
@@ -696,19 +696,19 @@ public static <T> T getNullValue(final Class<T> type) {
696696
}
697697

698698
/**
699-
* @deprecated Use {@link Types#type(Field, Class)} and {@link Types#raws}
699+
* @deprecated Use {@link Types#fieldType(Field, Class)} and {@link Types#raws}
700700
* instead.
701701
*/
702702
@Deprecated
703703
public static List<Class<?>> getTypes(final Field field, final Class<?> type)
704704
{
705-
return Types.raws(Types.type(field, type));
705+
return Types.raws(Types.fieldType(field, type));
706706
}
707707

708-
/** @deprecated Use {@link Types#type(Field, Class)} instead. */
708+
/** @deprecated Use {@link Types#fieldType(Field, Class)} instead. */
709709
@Deprecated
710710
public static Type getGenericType(final Field field, final Class<?> type) {
711-
return Types.type(field, type);
711+
return Types.fieldType(field, type);
712712
}
713713

714714
/** @deprecated Use {@link Types#field} instead. */

src/main/java/org/scijava/util/GenericUtils.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,29 +74,29 @@ public static Class<?> getComponentClass(final Type type) {
7474
return Types.raw(Types.component(type));
7575
}
7676

77-
/** @deprecated Use {@link Types#type(Field, Class)} instead. */
77+
/** @deprecated Use {@link Types#fieldType(Field, Class)} instead. */
7878
@Deprecated
7979
public static Type getFieldType(final Field field, final Class<?> type) {
80-
return Types.type(field, type);
80+
return Types.fieldType(field, type);
8181
}
8282

8383
/**
84-
* @deprecated Use {@link Types#type(Field, Class)} and {@link Types#raws}
84+
* @deprecated Use {@link Types#fieldType(Field, Class)} and {@link Types#raws}
8585
* instead.
8686
*/
8787
@Deprecated
8888
public static List<Class<?>> getFieldClasses(final Field field,
8989
final Class<?> type)
9090
{
91-
return Types.raws(Types.type(field, type));
91+
return Types.raws(Types.fieldType(field, type));
9292
}
9393

9494
/** @deprecated Use {@link Types#returnType} instead. */
9595
@Deprecated
9696
public static Type getMethodReturnType(final Method method,
9797
final Class<?> type)
9898
{
99-
return Types.returnType(method, type);
99+
return Types.methodReturnType(method, type);
100100
}
101101

102102
/**
@@ -106,7 +106,7 @@ public static Type getMethodReturnType(final Method method,
106106
public static List<Class<?>> getMethodReturnClasses(final Method method,
107107
final Class<?> type)
108108
{
109-
return Types.raws(Types.returnType(method, type));
109+
return Types.raws(Types.methodReturnType(method, type));
110110
}
111111

112112
/** @deprecated Use {@link Types#param} instead. */

src/main/java/org/scijava/util/Types.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -540,30 +540,34 @@ public static Type component(final Type type) {
540540
* field.getType(); // Object
541541
* field.getGenericType(); // T
542542
*
543-
* Types.type(field, Thing.class); // T
544-
* Types.type(field, NumberThing.class); // N extends Number
545-
* Types.type(field, IntegerThing.class); // Integer
543+
* Types.fieldType(field, Thing.class); // T
544+
* Types.fieldType(field, NumberThing.class); // N extends Number
545+
* Types.fieldType(field, IntegerThing.class); // Integer
546546
* </pre>
547547
*/
548-
public static Type type(final Field field, final Class<?> type) {
548+
public static Type fieldType(final Field field, final Class<?> type) {
549549
final Type wildType = GenericTypeReflector.addWildcardParameters(type);
550550
return GenericTypeReflector.getExactFieldType(field, wildType);
551551
}
552552

553553
/**
554-
* As {@link #type(Field, Class)}, but with respect to the return type of the
555-
* given {@link Method} rather than a {@link Field}.
554+
* As {@link #fieldType(Field, Class)}, but with respect to the return type of
555+
* the given {@link Method} rather than a {@link Field}.
556556
*/
557-
public static Type returnType(final Method method, final Class<?> type) {
557+
public static Type methodReturnType(final Method method,
558+
final Class<?> type)
559+
{
558560
final Type wildType = GenericTypeReflector.addWildcardParameters(type);
559561
return GenericTypeReflector.getExactReturnType(method, wildType);
560562
}
561563

562564
/**
563-
* As {@link #type(Field, Class)}, but with respect to the parameter types of
564-
* the given {@link Method} rather than a {@link Field}.
565+
* As {@link #fieldType(Field, Class)}, but with respect to the parameter
566+
* types of the given {@link Method} rather than a {@link Field}.
565567
*/
566-
public static Type[] paramTypes(final Method method, final Class<?> type) {
568+
public static Type[] methodParamTypes(final Method method,
569+
final Class<?> type)
570+
{
567571
final Type wildType = GenericTypeReflector.addWildcardParameters(type);
568572
return GenericTypeReflector.getExactParameterTypes(method, wildType);
569573
}

src/test/java/org/scijava/convert/ConverterTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public void testCanConvertToGenericCollection() {
9696
final CastingConverter cc = new CastingConverter();
9797

9898
final Field destField = Types.field(getClass(), "collection");
99-
final Type destType = Types.type(destField, getClass());
99+
final Type destType = Types.fieldType(destField, getClass());
100100
assertTrue(cc.canConvert(ArrayList.class, destType));
101101
}
102102

src/test/java/org/scijava/util/TypesTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -176,18 +176,18 @@ public void testRaws() {
176176
final Field field = Types.field(Thing.class, "thing");
177177

178178
// Object
179-
assertAllTheSame(Types.raws(Types.type(field, Thing.class)), Object.class);
179+
assertAllTheSame(Types.raws(Types.fieldType(field, Thing.class)), Object.class);
180180

181181
// N extends Number
182-
assertAllTheSame(Types.raws(Types.type(field, NumberThing.class)),
182+
assertAllTheSame(Types.raws(Types.fieldType(field, NumberThing.class)),
183183
Number.class);
184184

185185
// Integer
186-
assertAllTheSame(Types.raws(Types.type(field, IntegerThing.class)),
186+
assertAllTheSame(Types.raws(Types.fieldType(field, IntegerThing.class)),
187187
Integer.class);
188188

189189
// Serializable & Cloneable
190-
assertAllTheSame(Types.raws(Types.type(field, ComplexThing.class)),
190+
assertAllTheSame(Types.raws(Types.fieldType(field, ComplexThing.class)),
191191
Serializable.class, Cloneable.class);
192192
}
193193

@@ -357,21 +357,21 @@ class Struct {
357357
assertSame(null, componentType(Struct.class, "map"));
358358
}
359359

360-
/** Tests {@link Types#type(Field, Class)}. */
360+
/** Tests {@link Types#fieldType(Field, Class)}. */
361361
@Test
362-
public void testTypeField() {
362+
public void testFieldType() {
363363
final Field field = Types.field(Thing.class, "thing");
364364

365365
// T
366-
final Type tType = Types.type(field, Thing.class);
366+
final Type tType = Types.fieldType(field, Thing.class);
367367
assertEquals("capture of ?", tType.toString());
368368

369369
// N extends Number
370-
final Type nType = Types.type(field, NumberThing.class);
370+
final Type nType = Types.fieldType(field, NumberThing.class);
371371
assertEquals("capture of ?", nType.toString());
372372

373373
// Integer
374-
final Type iType = Types.type(field, IntegerThing.class);
374+
final Type iType = Types.fieldType(field, IntegerThing.class);
375375
assertSame(Integer.class, iType);
376376
}
377377

0 commit comments

Comments
 (0)