/** * Returns an array containing {@code Class} objects for all public classes * and interfaces that are members of this class. This includes public * members inherited from super classes and interfaces. If there are no such * class members or if this object represents a primitive type then an array * of length 0 is returned. * * @return the public class members of the class represented by this object. */ public Class<?>[] getClasses() { return getClassCache().getClasses(true); }
/** * Returns an array containing all the annotations of this class. If there are no annotations * then an empty array is returned. * * @see #getDeclaredAnnotations() */ public Annotation[] getAnnotations() { return getClassCache().getAnnotations(true); }
/** * Returns the annotations that are directly defined on the class * represented by this {@code Class}. Annotations that are inherited are not * included in the result. If there are no annotations at all, an empty * array is returned. * * @see #getAnnotations() */ public Annotation[] getDeclaredAnnotations() { return getClassCache().getDeclaredAnnotations(true); }
/** * Returns an array containing {@code Constructor} objects for all * constructors declared in the class represented by this {@code Class}. If * there are no constructors or if this {@code Class} represents an array * class, a primitive type, or void then an empty array is returned. * * @see #getConstructors() */ public Constructor<?>[] getDeclaredConstructors() { return getClassCache().getDeclaredConstructors(true); }
/** * Returns the name of the class represented by this {@code Class}. For a * description of the format which is used, see the class definition of * {@link Class}. */ public String getName() { return getClassCache().getName(); }
private List<Class<?>> buildClassesList(List<Class<?>> result, Set<String> seen, boolean publicOnly) { for (Class<?> c = clazz; c != null; c = c.getSuperclass()) { for (Class<?> f : c.getClassCache().getDeclaredClasses(false, publicOnly)) { String s = f.toString(); if (!seen.contains(s)) { result.add(f); seen.add(s); } } } return result; }
/** * Returns an array containing {@code Constructor} objects for all public * constructors for this {@code Class}. If there * are no public constructors or if this {@code Class} represents an array * class, a primitive type or void then an empty array is returned. * * @see #getDeclaredConstructors() */ public Constructor<?>[] getConstructors() { return getClassCache().getDeclaredPublicConstructors(true); }
/** * Returns an array containing {@code Method} objects for all methods * declared in the class represented by this {@code Class}. If there are no * methods or if this {@code Class} represents an array class, a primitive * type or void then an empty array is returned. * * @see #getMethods() */ public Method[] getDeclaredMethods() { return getClassCache().getDeclaredMethods(true); }
/** * Returns a {@code Field} object for the field with the given name * which is declared in the class represented by this {@code Class}. * * @throws NoSuchFieldException if the requested field can not be found. * @see #getField(String) */ public Field getDeclaredField(String name) throws NoSuchFieldException { if (name == null) { throw new NullPointerException("name == null"); } return getClassCache().getDeclaredField(true, name); }
/** * Returns an array containing {@code Class} objects for all classes and * interfaces that are declared as members of the class which this {@code * Class} represents. If there are no classes or interfaces declared or if * this class represents an array class, a primitive type or void, then an * empty array is returned. */ public Class<?>[] getDeclaredClasses() { return getClassCache().getDeclaredClasses(true); }
/** * Returns an array containing {@code Field} objects for all fields declared * in the class represented by this {@code Class}. If there are no fields or * if this {@code Class} represents an array class, a primitive type or void * then an empty array is returned. * * @see #getFields() */ public Field[] getDeclaredFields() { return getClassCache().getDeclaredFields(true); }
/** * Returns an array containing {@code Field} objects for all public fields * for the class C represented by this {@code Class}. Fields may be declared * in C, the interfaces it implements or in the superclasses of C. The * elements in the returned array are in no particular order. * * <p>If there are no public fields or if this class represents an array class, * a primitive type or {@code void} then an empty array is returned. * * @see #getDeclaredFields() */ public Field[] getFields() { return getClassCache().getFields(true); }
/** * Returns a {@code Constructor} object which represents the public * constructor matching the given parameter types. * {@code (Class[]) null} is equivalent to the empty array. * * <p>See {@link #getMethod} for details of the search order. * Use {@link #getDeclaredConstructor} if you don't want to search superclasses. * * @throws NoSuchMethodException * if the constructor can not be found. */ @SuppressWarnings("unchecked") public Constructor<T> getConstructor(Class<?>... parameterTypes) throws NoSuchMethodException { return getClassCache().getConstructor(true, parameterTypes); }
/** * Returns an array containing {@code Method} objects for all public methods * for the class C represented by this {@code Class}. Methods may be * declared in C, the interfaces it implements or in the superclasses of C. * The elements in the returned array are in no particular order. * * <p>If there are no public methods or if this {@code Class} represents a * primitive type or {@code void} then an empty array is returned. * * @see #getDeclaredMethods() */ public Method[] getMethods() { return getClassCache().getMethods(true); }
private List<Field> buildFieldsList(List<Field> result, Set<String> seen, boolean publicOnly) { for (Class<?> c = clazz; c != null; c = c.getSuperclass()) { for (Field f : c.getClassCache().getDeclaredFields(false, publicOnly)) { String s = f.toString(); if (!seen.contains(s)) { result.add(f); seen.add(s); } } for (Class<?> intf : c.getInterfaces()) { intf.getClassCache().buildFieldsList(result, seen, publicOnly); } } return result; }
/** * Returns the annotation if it exists. */ private <A extends Annotation> A getDeclaredAnnotation(Class<A> annotationClass) { if (annotationClass == null) { throw new NullPointerException("annotationClass == null"); } Annotation[] annos = getClassCache().getDeclaredAnnotations(false); for (int i = annos.length-1; i >= 0; --i) { if (annos[i].annotationType() == annotationClass) { return (A) annos[i]; } } return null; }
/** * Returns a {@code Constructor} object which represents the constructor * matching the given parameter types that is declared by the class * represented by this {@code Class}. * {@code (Class[]) null} is equivalent to the empty array. * * <p>Use {@link #getConstructor} if you want to search superclasses. * * @throws NoSuchMethodException * if the requested constructor can not be found. */ @SuppressWarnings("unchecked") public Constructor<T> getDeclaredConstructor(Class<?>... parameterTypes) throws NoSuchMethodException { return getClassCache().getDeclaredConstructor(true, parameterTypes); }
/** * Returns a {@code Field} object which represents the public field with the * given name. This method first searches the class C represented by * this {@code Class}, then the interfaces implemented by C and finally the * superclasses of C. * * @throws NoSuchFieldException * if the field can not be found. * @see #getDeclaredField(String) */ public Field getField(String name) throws NoSuchFieldException { if (name == null) { throw new NullPointerException("name == null"); } return getClassCache().getField(true, name); }
/** * Returns a {@code Method} object which represents the method matching the * given name and parameter types that is declared by the class * represented by this {@code Class}. * {@code (Class[]) null} is equivalent to the empty array. * * <p>See {@link #getMethod} if you want to search superclasses. * * @throws NoSuchMethodException * if the requested method can not be found. * @throws NullPointerException * if {@code name} is {@code null}. */ public Method getDeclaredMethod(String name, Class<?>... parameterTypes) throws NoSuchMethodException { return getClassCache().getDeclaredMethod(true, name, parameterTypes); }
private List<Method> buildMethodsList(List<Method> result, Set<MethodHashKey> seen, boolean publicOnly) { for (Class<?> c = clazz; c != null; c = c.getSuperclass()) { for (Method m : c.getClassCache().getDeclaredMethods(false, publicOnly)) { MethodHashKey key = new MethodHashKey(m); if (!seen.contains(key)) { result.add(m); seen.add(key); } } } for (Class<?> c = clazz; c != null; c = c.getSuperclass()) { for (Class<?> intf : c.getInterfaces()) { intf.getClassCache().buildMethodsList(result, seen, publicOnly); } } return result; }