Skip to content

Commit 9066d1d

Browse files
committed
Eliminate uses of deprecated GenericUtils methods
We now use the consolidated Types utility class.
1 parent 74092f6 commit 9066d1d

File tree

8 files changed

+39
-35
lines changed

8 files changed

+39
-35
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
import org.scijava.plugin.Attr;
4747
import org.scijava.plugin.Parameter;
4848
import org.scijava.util.ConversionUtils;
49-
import org.scijava.util.GenericUtils;
49+
import org.scijava.util.Types;
5050

5151
/**
5252
* {@link ModuleItem} implementation describing an input or output of a command.
@@ -76,16 +76,15 @@ public Parameter getParameter() {
7676

7777
@Override
7878
public Class<T> getType() {
79-
final Class<?> type =
80-
GenericUtils.getFieldClasses(field, getDelegateClass()).get(0);
79+
final Class<?> type = Types.raw(Types.type(field, getDelegateClass()));
8180
@SuppressWarnings("unchecked")
8281
final Class<T> typedType = (Class<T>) type;
8382
return typedType;
8483
}
8584

8685
@Override
8786
public Type getGenericType() {
88-
return GenericUtils.getFieldType(field, getDelegateClass());
87+
return Types.type(field, getDelegateClass());
8988
}
9089

9190
@Override

src/main/java/org/scijava/convert/AbstractConverter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
import org.scijava.plugin.AbstractHandlerPlugin;
4040
import org.scijava.plugin.Parameter;
4141
import org.scijava.util.ConversionUtils;
42-
import org.scijava.util.GenericUtils;
42+
import org.scijava.util.Types;
4343

4444
/**
4545
* Abstract superclass for {@link Converter} plugins. Performs appropriate
@@ -117,7 +117,7 @@ public boolean canConvert(final Class<?> src, final Class<?> dest) {
117117

118118
@Override
119119
public Object convert(final Object src, final Type dest) {
120-
final Class<?> destClass = GenericUtils.getClass(dest);
120+
final Class<?> destClass = Types.raw(dest);
121121
return convert(src, destClass);
122122
}
123123

@@ -155,7 +155,7 @@ public Class<ConversionRequest> getType() {
155155
@Override
156156
@Deprecated
157157
public boolean canConvert(final Class<?> src, final Type dest) {
158-
final Class<?> destClass = GenericUtils.getClass(dest);
158+
final Class<?> destClass = Types.raw(dest);
159159
return canConvert(src, destClass);
160160
}
161161
}

src/main/java/org/scijava/convert/CastingConverter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import org.scijava.plugin.Plugin;
3636
import org.scijava.util.ClassUtils;
3737
import org.scijava.util.ConversionUtils;
38-
import org.scijava.util.GenericUtils;
38+
import org.scijava.util.Types;
3939

4040
/**
4141
* Minimal {@link Converter} implementation to do direct casting.
@@ -72,7 +72,7 @@ public <T> T convert(final Object src, final Class<T> dest) {
7272
// rather than only Classes. However, the logic could become complex
7373
// very quickly in various subclassing cases, generic parameters
7474
// resolved vs. propagated, etc.
75-
final Class<?> c = GenericUtils.getClass(dest);
75+
final Class<?> c = Types.raw(dest);
7676
return (T) ConversionUtils.cast(src, c);
7777
}
7878

src/main/java/org/scijava/convert/ConversionRequest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import java.lang.reflect.Type;
3636

3737
import org.scijava.plugin.HandlerService;
38-
import org.scijava.util.GenericUtils;
38+
import org.scijava.util.Types;
3939

4040
/**
4141
* Currency for use in {@link Converter} and {@link ConvertService} methods.
@@ -100,7 +100,7 @@ public Type sourceType() {
100100
* @return Source class for conversion or lookup.
101101
*/
102102
public Class<?> sourceClass() {
103-
return GenericUtils.getClass(srcType);
103+
return Types.raw(srcType);
104104
}
105105

106106
/**
@@ -121,7 +121,7 @@ public Type destType() {
121121
* @return Destination class for conversion.
122122
*/
123123
public Class<?> destClass() {
124-
return GenericUtils.getClass(destType);
124+
return Types.raw(destType);
125125
}
126126

127127
// -- Setters --

src/main/java/org/scijava/convert/DefaultConverter.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
import org.scijava.util.ArrayUtils;
4949
import org.scijava.util.ClassUtils;
5050
import org.scijava.util.ConversionUtils;
51-
import org.scijava.util.GenericUtils;
51+
import org.scijava.util.Types;
5252

5353
/**
5454
* Default {@link Converter} implementation. Provides useful conversion
@@ -79,8 +79,10 @@ public class DefaultConverter extends AbstractConverter<Object, Object> {
7979
public Object convert(final Object src, final Type dest) {
8080

8181
// Handle array types, including generic array types.
82-
if (isArray(dest)) {
83-
return convertToArray(src, GenericUtils.getComponentClass(dest));
82+
final Type componentType = Types.component(dest);
83+
if (componentType != null) {
84+
// NB: Destination is an array type.
85+
return convertToArray(src, Types.raw(componentType));
8486
}
8587

8688
// Handle parameterized collection types.
@@ -89,7 +91,7 @@ public Object convert(final Object src, final Type dest) {
8991
}
9092

9193
// This wasn't a collection or array, so convert it as a single element.
92-
return convert(src, GenericUtils.getClass(dest));
94+
return convert(src, Types.raw(dest));
9395
}
9496

9597
@Override
@@ -100,7 +102,7 @@ public <T> T convert(final Object src, final Class<T> dest) {
100102
// Handle array types
101103
if (isArray(dest)) {
102104
@SuppressWarnings("unchecked")
103-
T array = (T) convertToArray(src, GenericUtils.getComponentClass(dest));
105+
T array = (T) convertToArray(src, Types.raw(Types.component(dest)));
104106
return array;
105107
}
106108

@@ -216,12 +218,11 @@ private Constructor<?> getConstructor(final Class<?> type,
216218
}
217219

218220
private boolean isArray(final Type type) {
219-
return GenericUtils.getComponentClass(type) != null;
221+
return Types.component(type) != null;
220222
}
221223

222224
private boolean isCollection(final Type type) {
223-
return ConversionUtils.canCast(GenericUtils.getClass(type),
224-
Collection.class);
225+
return ConversionUtils.canCast(Types.raw(type), Collection.class);
225226
}
226227

227228
private Object
@@ -247,8 +248,7 @@ private boolean isCollection(final Type type) {
247248
private Object convertToCollection(final Object value,
248249
final ParameterizedType pType)
249250
{
250-
final Collection<Object> collection =
251-
createCollection(GenericUtils.getClass(pType));
251+
final Collection<Object> collection = createCollection(Types.raw(pType));
252252
if (collection == null) return null;
253253

254254
// Populate the collection.
@@ -298,7 +298,7 @@ public boolean canConvert(final Class<?> src, final Type dest) {
298298

299299
// Handle parameterized collection types.
300300
if (dest instanceof ParameterizedType && isCollection(dest) &&
301-
createCollection(GenericUtils.getClass(dest)) != null)
301+
createCollection(Types.raw(dest)) != null)
302302
{
303303
return true;
304304
}

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
import java.util.Map;
5050
import java.util.Set;
5151

52+
import org.scijava.util.Types;
53+
5254
/**
5355
* Useful methods for working with {@link Class} objects and primitive types.
5456
*
@@ -623,8 +625,7 @@ public static void setValue(final Field field, final Object instance,
623625
}
624626
else {
625627
// the given value needs to be converted to a compatible type
626-
final Type fieldType =
627-
GenericUtils.getFieldType(field, instance.getClass());
628+
final Type fieldType = Types.type(field, instance.getClass());
628629
@SuppressWarnings("deprecation")
629630
final Object convertedValue = ConversionUtils.convert(value, fieldType);
630631
compatibleValue = convertedValue;
@@ -804,17 +805,20 @@ public static <T> T getNullValue(final Class<T> type) {
804805
return ConversionUtils.getNullValue(type);
805806
}
806807

807-
/** @deprecated use {@link GenericUtils#getFieldClasses(Field, Class)} */
808+
/**
809+
* @deprecated Use {@link Types#type(Field, Class)} and {@link Types#raws}
810+
* instead.
811+
*/
808812
@Deprecated
809813
public static List<Class<?>> getTypes(final Field field, final Class<?> type)
810814
{
811-
return GenericUtils.getFieldClasses(field, type);
815+
return Types.raws(Types.type(field, type));
812816
}
813817

814-
/** @deprecated use {@link GenericUtils#getFieldType(Field, Class)} */
818+
/** @deprecated Use {@link Types#type(Field, Class)} instead. */
815819
@Deprecated
816820
public static Type getGenericType(final Field field, final Class<?> type) {
817-
return GenericUtils.getFieldType(field, type);
821+
return Types.type(field, type);
818822
}
819823

820824
// -- Helper classes --

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.scijava.convert.ConvertService;
3939
import org.scijava.convert.Converter;
4040
import org.scijava.convert.DefaultConverter;
41+
import org.scijava.util.Types;
4142

4243
/**
4344
* Useful methods for converting and casting between classes and types.
@@ -316,16 +317,16 @@ public static boolean canConvert(final Object src, final Class<?> dest) {
316317
return (handler == null ? false : handler.canConvert(src, dest));
317318
}
318319

319-
/** @deprecated use {@link GenericUtils#getClass(Type)} */
320+
/** @deprecated use {@link Types#raw} */
320321
@Deprecated
321322
public static Class<?> getClass(final Type type) {
322-
return GenericUtils.getClass(type);
323+
return Types.raw(type);
323324
}
324325

325-
/** @deprecated use {@link GenericUtils#getComponentClass(Type)} */
326+
/** @deprecated use {@link Types#raws} and {@link Types#component} */
326327
@Deprecated
327328
public static Class<?> getComponentClass(final Type type) {
328-
return GenericUtils.getComponentClass(type);
329+
return Types.raw(Types.component(type));
329330
}
330331

331332
//-- Helper methods --

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
import org.junit.Test;
4545
import org.scijava.util.ClassUtils;
46-
import org.scijava.util.GenericUtils;
46+
import org.scijava.util.Types;
4747

4848
/**
4949
* Tests individual {@link Converter}s.
@@ -97,7 +97,7 @@ public void testCanConvertToGenericCollection() {
9797
final CastingConverter cc = new CastingConverter();
9898

9999
final Field destField = ClassUtils.getField(getClass(), "collection");
100-
final Type destType = GenericUtils.getFieldType(destField, getClass());
100+
final Type destType = Types.type(destField, getClass());
101101
assertTrue(cc.canConvert(ArrayList.class, destType));
102102
}
103103

0 commit comments

Comments
 (0)