88 * %%
99 * Redistribution and use in source and binary forms, with or without
1010 * modification, are permitted provided that the following conditions are met:
11- *
11+ *
1212 * 1. Redistributions of source code must retain the above copyright notice,
1313 * this list of conditions and the following disclaimer.
1414 * 2. Redistributions in binary form must reproduce the above copyright notice,
1515 * this list of conditions and the following disclaimer in the documentation
1616 * and/or other materials provided with the distribution.
17- *
17+ *
1818 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1919 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2020 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
5050
5151/**
5252 * Useful methods for working with {@link Class} objects and primitive types.
53- *
53+ *
5454 * @author Curtis Rueden
5555 */
5656public final class ClassUtils {
@@ -67,7 +67,9 @@ private ClassUtils() {
6767 * This map serves as a cache, as these annotations should not change at
6868 * runtime and thus can alleviate the frequency field querying.
6969 * </p>
70- * @see <a href="https://github.com/scijava/scijava-common/issues/142">issue #142</a>
70+ *
71+ * @see <a href="https://github.com/scijava/scijava-common/issues/142">issue
72+ * #142</a>
7173 */
7274 private static final FieldCache fieldCache = new FieldCache ();
7375
@@ -79,7 +81,9 @@ private ClassUtils() {
7981 * This map serves as a cache, as these annotations should not change at
8082 * runtime and thus can alleviate the frequency of method querying.
8183 * </p>
82- * @see <a href="https://github.com/scijava/scijava-common/issues/142">issue #142</a>
84+ *
85+ * @see <a href="https://github.com/scijava/scijava-common/issues/142">issue
86+ * #142</a>
8387 */
8488 private static final MethodCache methodCache = new MethodCache ();
8589
@@ -88,7 +92,7 @@ private ClassUtils() {
8892 /**
8993 * Loads the class with the given name, using the current thread's context
9094 * class loader, or null if it cannot be loaded.
91- *
95+ *
9296 * @see #loadClass(String, ClassLoader)
9397 */
9498 public static Class <?> loadClass (final String className ) {
@@ -99,10 +103,9 @@ public static Class<?> loadClass(final String className) {
99103 * Loads the class with the given name, using the specified
100104 * {@link ClassLoader}, or null if it cannot be loaded.
101105 * <p>
102- * This method is capable of parsing several different class name syntaxes.
103- * In particular, array classes (including primitives) represented using
104- * either square brackets or internal Java array name syntax are supported.
105- * Examples:
106+ * This method is capable of parsing several different class name syntaxes. In
107+ * particular, array classes (including primitives) represented using either
108+ * square brackets or internal Java array name syntax are supported. Examples:
106109 * </p>
107110 * <ul>
108111 * <li>{@code boolean} is loaded as {@code boolean.class}</li>
@@ -111,7 +114,7 @@ public static Class<?> loadClass(final String className) {
111114 * <li>{@code string[]} is loaded as {@code java.lang.String.class}</li>
112115 * <li>{@code [F} is loaded as {@code float[].class}</li>
113116 * </ul>
114- *
117+ *
115118 * @param name The name of the class to load.
116119 * @param classLoader The class loader with which to load the class; if null,
117120 * the current thread's context class loader will be used.
@@ -208,7 +211,7 @@ public static boolean hasClass(final String className,
208211 * "/path/to/my-jar.jar!/my/package/MyClass.class") then it will return the
209212 * path to the JAR (e.g., "/path/to/my-jar.jar").
210213 * </p>
211- *
214+ *
212215 * @param className The name of the class whose location is desired.
213216 * @see FileUtils#urlToFile(URL) to convert the result to a {@link File}.
214217 */
@@ -228,7 +231,7 @@ public static URL getLocation(final String className) {
228231 * "/path/to/my-jar.jar!/my/package/MyClass.class") then it will return the
229232 * path to the JAR (e.g., "/path/to/my-jar.jar").
230233 * </p>
231- *
234+ *
232235 * @param className The name of the class whose location is desired.
233236 * @param classLoader The class loader to use when loading the class.
234237 * @see FileUtils#urlToFile(URL) to convert the result to a {@link File}.
@@ -252,7 +255,7 @@ public static URL getLocation(final String className,
252255 * "/path/to/my-jar.jar!/my/package/MyClass.class") then it will return the
253256 * path to the JAR (e.g., "file:/path/to/my-jar.jar").
254257 * </p>
255- *
258+ *
256259 * @param c The class whose location is desired.
257260 * @see FileUtils#urlToFile(URL) to convert the result to a {@link File}.
258261 */
@@ -345,7 +348,7 @@ public static <A extends Annotation> List<Method> getAnnotatedMethods(
345348 List <Method > cachedMethods = methodCache .getList (c , annotationClass );
346349
347350 if (cachedMethods == null ) {
348- Query query = new Query ();
351+ final Query query = new Query ();
349352 query .put (annotationClass , Method .class );
350353 cacheAnnotatedObjects (c , query );
351354 cachedMethods = methodCache .getList (c , annotationClass );
@@ -361,7 +364,7 @@ public static <A extends Annotation> List<Method> getAnnotatedMethods(
361364 * Unlike {@link Class#getFields()}, the result will include any non-public
362365 * fields, including fields defined in supertypes of the given class.
363366 * </p>
364- *
367+ *
365368 * @param c The class to scan for annotated fields.
366369 * @param annotationClass The type of annotation for which to scan.
367370 * @return A new list containing all fields with the requested annotation.
@@ -380,13 +383,13 @@ public static <A extends Annotation> List<Field> getAnnotatedFields(
380383 }
381384
382385 /**
383- * Gets the given class's {@link Field}s marked with the annotation of the
384- * specified class.
385- * <p>
386+ * Gets the given class's {@link Field}s marked with the annotation of the
387+ * specified class.
388+ * <p>
386389 * Unlike {@link Class#getFields()}, the result will include any non-public
387390 * fields, including fields defined in supertypes of the given class.
388391 * </p>
389- *
392+ *
390393 * @param c The class to scan for annotated fields.
391394 * @param annotationClass The type of annotation for which to scan.
392395 * @param fields The list to which matching fields will be added.
@@ -397,7 +400,7 @@ public static <A extends Annotation> void getAnnotatedFields(
397400 List <Field > cachedFields = fieldCache .getList (c , annotationClass );
398401
399402 if (cachedFields == null ) {
400- Query query = new Query ();
403+ final Query query = new Query ();
401404 query .put (annotationClass , Field .class );
402405 cacheAnnotatedObjects (c , query );
403406 cachedFields = fieldCache .getList (c , annotationClass );
@@ -456,17 +459,14 @@ else if (methodCache.getList(scannedClass, annotationClass) != null) {
456459 final Class <?> superClass = scannedClass .getSuperclass ();
457460 if (superClass != null ) {
458461 // Recursive step
459- cacheAnnotatedObjects (
460- superClass , new Query (query ));
462+ cacheAnnotatedObjects (superClass , new Query (query ));
461463 inherited .add (superClass );
462464 }
463465
464466 // cache all interfaces recursively
465467 for (final Class <?> ifaceClass : scannedClass .getInterfaces ()) {
466468 // Recursive step
467- cacheAnnotatedObjects (
468- ifaceClass ,
469- new Query (query ));
469+ cacheAnnotatedObjects (ifaceClass , new Query (query ));
470470 inherited .add (ifaceClass );
471471 }
472472
@@ -524,7 +524,7 @@ public static Object getValue(final Field field, final Object instance) {
524524
525525 /**
526526 * Sets the given field's value of the specified object instance.
527- *
527+ *
528528 * @throws IllegalArgumentException if the value cannot be set.
529529 */
530530 // FIXME: Move to ConvertService and deprecate this signature.
@@ -541,7 +541,7 @@ public static void setValue(final Field field, final Object instance,
541541 else {
542542 // the given value needs to be converted to a compatible type
543543 final Type fieldType =
544- GenericUtils .getFieldType (field , instance .getClass ());
544+ GenericUtils .getFieldType (field , instance .getClass ());
545545 compatibleValue = ConversionUtils .convert (value , fieldType );
546546 }
547547 field .set (instance , compatibleValue );
@@ -610,7 +610,7 @@ public static boolean isText(final Class<?> type) {
610610 * impose logic beyond that of this method, for breaking ties, if a total
611611 * ordering consistent with equals is always required.
612612 * </p>
613- *
613+ *
614614 * @see org.scijava.Priority#compare(org.scijava.Prioritized,
615615 * org.scijava.Prioritized)
616616 */
@@ -629,19 +629,19 @@ public static int compare(final Class<?> c1, final Class<?> c2) {
629629 * annotationClass. If no matches are found, an empty mapping is created to
630630 * mark this class complete.
631631 */
632- private static <T extends AnnotatedElement > void
633- populateCache ( final Class <?> scannedClass , final List <Class <?>> inherited ,
634- final Class <? extends Annotation > annotationClass ,
635- CacheMap <T > cacheMap , T [] declaredElements )
632+ private static <T extends AnnotatedElement > void populateCache (
633+ final Class <?> scannedClass , final List <Class <?>> inherited ,
634+ final Class <? extends Annotation > annotationClass ,
635+ final CacheMap <T > cacheMap , final T [] declaredElements )
636636 {
637637 // Add inherited elements
638638 for (final Class <?> inheritedClass : inherited ) {
639639 final List <T > annotatedElements =
640- cacheMap .getList (inheritedClass , annotationClass );
640+ cacheMap .getList (inheritedClass , annotationClass );
641641
642642 if (annotatedElements != null && !annotatedElements .isEmpty ()) {
643643 final List <T > scannedElements =
644- cacheMap .makeList (scannedClass , annotationClass );
644+ cacheMap .makeList (scannedClass , annotationClass );
645645
646646 scannedElements .addAll (annotatedElements );
647647 }
@@ -664,7 +664,8 @@ public static int compare(final Class<?> c1, final Class<?> c2) {
664664 // If there were no elements for this query, map an empty
665665 // list to mark the query complete
666666 if (cacheMap .getList (scannedClass , annotationClass ) == null ) {
667- cacheMap .putList (scannedClass , annotationClass , Collections .<T >emptyList ());
667+ cacheMap .putList (scannedClass , annotationClass , Collections
668+ .<T > emptyList ());
668669 }
669670 }
670671
@@ -734,18 +735,20 @@ public static Type getGenericType(final Field field, final Class<?> type) {
734735 // -- Helper classes --
735736
736737 /**
737- * Convenience class to further type narrow {@link CacheMap} to {@link Field}s.
738+ * Convenience class to further type narrow {@link CacheMap} to {@link Field}
739+ * s.
738740 */
739- private static class FieldCache extends CacheMap <Field > { }
741+ private static class FieldCache extends CacheMap <Field > {}
740742
741743 /**
742- * Convenience class to further type narrow {@link CacheMap} to {@link Method}s.
744+ * Convenience class to further type narrow {@link CacheMap} to {@link Method}
745+ * s.
743746 */
744- private static class MethodCache extends CacheMap <Method > { }
747+ private static class MethodCache extends CacheMap <Method > {}
745748
746749 /**
747- * Convenience class for {@code Map > Map > List} hierarchy. Cleans up generics
748- * and contains helper methods for traversing the two map levels.
750+ * Convenience class for {@code Map > Map > List} hierarchy. Cleans up
751+ * generics and contains helper methods for traversing the two map levels.
749752 *
750753 * @param <T> - {@link AnnotatedElement} {@link List} ultimately referenced by
751754 * this map
@@ -764,7 +767,7 @@ public List<T> getList(final Class<?> c,
764767 final Class <? extends Annotation > annotationClass )
765768 {
766769 List <T > annotatedFields = null ;
767- Map <Class <? extends Annotation >, List <T >> annotationTypes = get (c );
770+ final Map <Class <? extends Annotation >, List <T >> annotationTypes = get (c );
768771 if (annotationTypes != null ) {
769772 annotatedFields = annotationTypes .get (annotationClass );
770773 }
@@ -781,7 +784,7 @@ public List<T> getList(final Class<?> c,
781784 */
782785 public void putList (final Class <?> c ,
783786 final Class <? extends Annotation > annotationClass ,
784- List <T > annotatedMethods )
787+ final List <T > annotatedMethods )
785788 {
786789 Map <Class <? extends Annotation >, List <T >> map = get (c );
787790 if (map == null ) {
0 commit comments