Class ReflectionUtils


  • public final class ReflectionUtils
    extends Object
    Author:
    John DeRegnaucourt ([email protected])
    Copyright (c) Cedar Software LLC

    Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
    • Method Detail

      • getClassAnnotation

        public static <T extends Annotation> T getClassAnnotation​(Class<?> classToCheck,
                                                                  Class<T> annoClass)
        Determine if the passed in class (classToCheck) has the annotation (annoClass) on itself, any of its super classes, any of it's interfaces, or any of it's super interfaces. This is a exhaustive check throughout the complete inheritance hierarchy.
        Returns:
        the Annotation if found, null otherwise.
      • getMethodAnnotation

        public static <T extends Annotation> T getMethodAnnotation​(Method method,
                                                                   Class<T> annoClass)
      • getDeepDeclaredFields

        public static Collection<Field> getDeepDeclaredFields​(Class<?> c)
        Get all non static, non transient, fields of the passed in class, including private fields. Note, the special this$ field is also not returned. The result is cached in a static ConcurrentHashMap to benefit execution performance.
        Parameters:
        c - Class instance
        Returns:
        Collection of only the fields in the passed in class that would need further processing (reference fields). This makes field traversal on a class faster as it does not need to continually process known fields like primitives.
      • getDeclaredFields

        public static void getDeclaredFields​(Class<?> c,
                                             Collection<Field> fields)
        Get all non static, non transient, fields of the passed in class, including private fields. Note, the special this$ field is also not returned. The resulting fields are stored in a Collection.
        Parameters:
        c - Class instance that would need further processing (reference fields). This makes field traversal on a class faster as it does not need to continually process known fields like primitives.
      • getDeepDeclaredFieldMap

        public static Map<String,​Field> getDeepDeclaredFieldMap​(Class<?> c)
        Return all Fields from a class (including inherited), mapped by String field name to java.lang.reflect.Field.
        Parameters:
        c - Class whose fields are being fetched.
        Returns:
        Map of all fields on the Class, keyed by String field name to java.lang.reflect.Field.
      • getClassName

        public static String getClassName​(Object o)
        Return the name of the class on the object, or "null" if the object is null.
        Parameters:
        o - Object to get the class name.
        Returns:
        String name of the class or "null"
      • getClassNameFromByteCode

        public static String getClassNameFromByteCode​(byte[] byteCode)
                                               throws Exception
        Throws:
        Exception