Search in sources :

Example 1 with Type

use of com.badlogic.gwtref.client.Type in project libgdx by libgdx.

the class ClassReflection method getAnnotations.

/** Returns an array of {@link Annotation} objects reflecting all annotations declared by the supplied class, and inherited
	 * from its superclass. Returns an empty array if there are none. */
public static Annotation[] getAnnotations(Class c) {
    Type declType = ReflectionCache.getType(c);
    java.lang.annotation.Annotation[] annotations = declType.getDeclaredAnnotations();
    // annotations of supplied class
    Annotation[] result = new Annotation[annotations.length];
    for (int i = 0; i < annotations.length; i++) {
        result[i] = new Annotation(annotations[i]);
    }
    // search super classes, until Object.class is reached
    Type superType = declType.getSuperclass();
    java.lang.annotation.Annotation[] superAnnotations;
    while (!superType.getClassOfType().equals(Object.class)) {
        superAnnotations = superType.getDeclaredAnnotations();
        for (int i = 0; i < superAnnotations.length; i++) {
            // check for annotation types marked as Inherited
            Type annotationType = ReflectionCache.getType(superAnnotations[i].annotationType());
            if (annotationType.getDeclaredAnnotation(Inherited.class) != null) {
                // ignore duplicates
                boolean duplicate = false;
                for (Annotation annotation : result) {
                    if (annotation.getAnnotationType().equals(annotationType)) {
                        duplicate = true;
                        break;
                    }
                }
                // append to result set
                if (!duplicate) {
                    Annotation[] copy = new Annotation[result.length + 1];
                    for (int j = 0; j < result.length; j++) {
                        copy[j] = result[j];
                    }
                    copy[result.length] = new Annotation(superAnnotations[i]);
                    result = copy;
                }
            }
        }
        superType = superType.getSuperclass();
    }
    return result;
}
Also used : Type(com.badlogic.gwtref.client.Type) Inherited(java.lang.annotation.Inherited)

Example 2 with Type

use of com.badlogic.gwtref.client.Type in project libgdx by libgdx.

the class ClassReflection method isAssignableFrom.

/** Determines if the class or interface represented by first Class parameter is either the same as, or is a superclass or
	 * superinterface of, the class or interface represented by the second Class parameter. */
public static boolean isAssignableFrom(Class c1, Class c2) {
    Type c1Type = ReflectionCache.getType(c1);
    Type c2Type = ReflectionCache.getType(c2);
    return c1Type.isAssignableFrom(c2Type);
}
Also used : Type(com.badlogic.gwtref.client.Type)

Aggregations

Type (com.badlogic.gwtref.client.Type)2 Inherited (java.lang.annotation.Inherited)1