Search in sources :

Example 1 with PetiteDestroyMethod

use of jodd.petite.meta.PetiteDestroyMethod in project jodd by oblac.

the class DestroyMethodResolver method resolve.

public DestroyMethodPoint[] resolve(Object bean) {
    Class<?> type = bean.getClass();
    // lookup methods
    List<DestroyMethodPoint> list = new ArrayList<>();
    ClassDescriptor cd = new ClassDescriptor(type, false, false, false, null);
    MethodDescriptor[] allMethods = cd.getAllMethodDescriptors();
    for (MethodDescriptor methodDescriptor : allMethods) {
        Method method = methodDescriptor.getMethod();
        PetiteDestroyMethod petiteDestroyMethod = method.getAnnotation(PetiteDestroyMethod.class);
        if (petiteDestroyMethod == null) {
            continue;
        }
        if (method.getParameterTypes().length > 0) {
            throw new PetiteException("Arguments are not allowed for Petite destroy method: " + type.getName() + '#' + method.getName());
        }
        list.add(new DestroyMethodPoint(method));
    }
    DestroyMethodPoint[] methods;
    if (list.isEmpty()) {
        methods = DestroyMethodPoint.EMPTY;
    } else {
        methods = list.toArray(new DestroyMethodPoint[list.size()]);
    }
    return methods;
}
Also used : DestroyMethodPoint(jodd.petite.DestroyMethodPoint) ClassDescriptor(jodd.introspector.ClassDescriptor) PetiteDestroyMethod(jodd.petite.meta.PetiteDestroyMethod) ArrayList(java.util.ArrayList) PetiteDestroyMethod(jodd.petite.meta.PetiteDestroyMethod) Method(java.lang.reflect.Method) MethodDescriptor(jodd.introspector.MethodDescriptor) PetiteException(jodd.petite.PetiteException)

Aggregations

Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 ClassDescriptor (jodd.introspector.ClassDescriptor)1 MethodDescriptor (jodd.introspector.MethodDescriptor)1 DestroyMethodPoint (jodd.petite.DestroyMethodPoint)1 PetiteException (jodd.petite.PetiteException)1 PetiteDestroyMethod (jodd.petite.meta.PetiteDestroyMethod)1