Skip to content

Commit 751d5ee

Browse files
committed
Deprecate methods now available in GenericUtils
1 parent e4741de commit 751d5ee

File tree

2 files changed

+27
-132
lines changed

2 files changed

+27
-132
lines changed

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

Lines changed: 13 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131

3232
package org.scijava.util;
3333

34-
import com.googlecode.gentyref.GenericTypeReflector;
35-
3634
import java.io.File;
3735
import java.lang.annotation.Annotation;
3836
import java.lang.reflect.Array;
@@ -341,96 +339,6 @@ public static Field getField(final Class<?> c, final String fieldName) {
341339
}
342340
}
343341

344-
/**
345-
* Returns the "safe" type(s) of the given field, as viewed from the specified
346-
* type. This may be narrower than what {@link Field#getType()} returns, if
347-
* the field is declared in a superclass, or {@code type} has a type parameter
348-
* that is used in the type of the field.
349-
* <p>
350-
* For example, suppose we have the following three classes:
351-
* </p>
352-
*
353-
* <pre>
354-
* public class Thing&lt;T&gt; {
355-
* public T thing;
356-
* }
357-
*
358-
* public class NumberThing&lt;N extends Number&gt; extends Thing&lt;N&gt; { }
359-
*
360-
* public class IntegerThing extends NumberThing&lt;Integer&gt; { }
361-
* </pre>
362-
*
363-
* Then this method operates as follows:
364-
*
365-
* <pre>
366-
* field = ClassUtils.getField(Thing.class, "thing");
367-
*
368-
* field.getType(); // Object
369-
*
370-
* ClassUtils.getTypes(field, Thing.class).get(0); // Object
371-
* ClassUtils.getTypes(field, NumberThing.class).get(0); // Number
372-
* ClassUtils.getTypes(field, IntegerThing.class).get(0); // Integer
373-
* </pre>
374-
*
375-
* <p>
376-
* In cases of complex generics which take the intersection of
377-
* multiple types using the {@code &} operator, there may be multiple types
378-
* returned by this method. For example:
379-
* </p>
380-
*
381-
* <pre>
382-
* public class ComplexThing&lt;T extends Serializable &amp; Cloneable&gt; extends Thing&lt;T&gt; { }
383-
*
384-
* ClassUtils.getTypes(field, ComplexThing.class); // Serializable, Cloneable
385-
* </pre>
386-
*
387-
* @see #getGenericType(Field, Class)
388-
*/
389-
public static List<Class<?>> getTypes(final Field field, final Class<?> type)
390-
{
391-
final Type genericType = getGenericType(field, type);
392-
return GenericTypeReflector.getUpperBoundClassAndInterfaces(genericType);
393-
}
394-
395-
/**
396-
* Returns the "safe" generic type of the given field, as viewed from the
397-
* given type. This may be narrower than what {@link Field#getGenericType()}
398-
* returns, if the field is declared in a superclass, or {@code type} has a
399-
* type parameter that is used in the type of the field.
400-
* <p>
401-
* For example, suppose we have the following three classes:
402-
* </p>
403-
*
404-
* <pre>
405-
* public class Thing&lt;T&gt; {
406-
* public T thing;
407-
* }
408-
*
409-
* public class NumberThing&lt;N extends Number&gt; extends Thing&lt;N&gt; { }
410-
*
411-
* public class IntegerThing extends NumberThing&lt;Integer&gt; { }
412-
* </pre>
413-
*
414-
* Then this method operates as follows:
415-
*
416-
* <pre>
417-
* field = ClassUtils.getField(Thing.class, "thing");
418-
*
419-
* field.getType(); // Object
420-
* field.getGenericType(); // T
421-
*
422-
* ClassUtils.getGenericType(field, Thing.class); // T
423-
* ClassUtils.getGenericType(field, NumberThing.class); // N extends Number
424-
* ClassUtils.getGenericType(field, IntegerThing.class); // Integer
425-
* </pre>
426-
*
427-
* @see #getTypes(Field, Class)
428-
*/
429-
public static Type getGenericType(final Field field, final Class<?> type) {
430-
final Type wildType = GenericTypeReflector.addWildcardParameters(type);
431-
return GenericTypeReflector.getExactFieldType(field, wildType);
432-
}
433-
434342
/**
435343
* Gets the given field's value of the specified object instance, or null if
436344
* the value cannot be obtained.
@@ -599,4 +507,17 @@ public static <T> T getNullValue(final Class<T> type) {
599507
return ConversionUtils.getNullValue(type);
600508
}
601509

510+
/** @deprecated use {@link GenericUtils#getFieldClasses(Field, Class)} */
511+
@Deprecated
512+
public static List<Class<?>> getTypes(final Field field, final Class<?> type)
513+
{
514+
return GenericUtils.getFieldClasses(field, type);
515+
}
516+
517+
/** @deprecated use {@link GenericUtils#getFieldType(Field, Class)} */
518+
@Deprecated
519+
public static Type getGenericType(final Field field, final Class<?> type) {
520+
return GenericUtils.getFieldType(field, type);
521+
}
522+
602523
}

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

Lines changed: 14 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,9 @@
3333

3434
import java.lang.reflect.Array;
3535
import java.lang.reflect.Constructor;
36-
import java.lang.reflect.GenericArrayType;
3736
import java.lang.reflect.Modifier;
3837
import java.lang.reflect.ParameterizedType;
3938
import java.lang.reflect.Type;
40-
import java.lang.reflect.TypeVariable;
4139
import java.util.ArrayList;
4240
import java.util.Collection;
4341
import java.util.HashSet;
@@ -438,44 +436,6 @@ public static <T> T getNullValue(final Class<T> type) {
438436
return result;
439437
}
440438

441-
/**
442-
* Gets the raw class corresponding to the given type.
443-
* <p>
444-
* If the type is a {@link Class} it is simply casted. In the case of a
445-
* {@link ParameterizedType}, then {@link ParameterizedType#getRawType()} is
446-
* returned. Otherwise, returns null.
447-
* </p>
448-
*/
449-
public static Class<?> getClass(final Type type) {
450-
if (type instanceof Class) return (Class<?>) type;
451-
452-
if (type instanceof ParameterizedType) {
453-
return getClass(((ParameterizedType) type).getRawType());
454-
}
455-
456-
if (type instanceof TypeVariable<?>) {
457-
final Type[] types = ((TypeVariable<?>) type).getBounds();
458-
if (types.length == 1) return getClass(types[0]);
459-
}
460-
461-
return null;
462-
}
463-
464-
/**
465-
* Gets the component type of the given array type, or null if not an array.
466-
* Supports both regular array types (i.e., {@link Class#getComponentType()}
467-
* if {@code type} is a {@link Class}) and generic array types (i.e.,
468-
* {@link GenericArrayType#getGenericComponentType()} if {@code type} is a
469-
* {@link GenericArrayType}).
470-
*/
471-
public static Class<?> getComponentClass(final Type type) {
472-
if (type instanceof Class) return ((Class<?>) type).getComponentType();
473-
if (type instanceof GenericArrayType) {
474-
return getClass(((GenericArrayType) type).getGenericComponentType());
475-
}
476-
return null;
477-
}
478-
479439
// -- Helper methods --
480440

481441
private static Constructor<?> getConstructor(final Class<?> type,
@@ -560,4 +520,18 @@ private static Collection<Object> createCollection(final Class<?> type) {
560520
}
561521
}
562522

523+
// -- Deprecated methods --
524+
525+
/** @deprecated use {@link GenericUtils#getClass(Type)} */
526+
@Deprecated
527+
public static Class<?> getClass(final Type type) {
528+
return GenericUtils.getClass(type);
529+
}
530+
531+
/** @deprecated use {@link GenericUtils#getComponentClass(Type)} */
532+
@Deprecated
533+
public static Class<?> getComponentClass(final Type type) {
534+
return GenericUtils.getComponentClass(type);
535+
}
536+
563537
}

0 commit comments

Comments
 (0)