Search in sources :

Example 31 with ClassDescriptor

use of jodd.introspector.ClassDescriptor 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)

Example 32 with ClassDescriptor

use of jodd.introspector.ClassDescriptor in project jodd by oblac.

the class InitMethodResolver method resolve.

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

Example 33 with ClassDescriptor

use of jodd.introspector.ClassDescriptor in project jodd by oblac.

the class ProviderResolver method resolve.

/**
	 * Resolves all providers in the class
	 */
public ProviderDefinition[] resolve(BeanDefinition beanDefinition) {
    Class type = beanDefinition.getType();
    ClassDescriptor cd = ClassIntrospector.lookup(type);
    MethodDescriptor[] methods = cd.getAllMethodDescriptors();
    List<ProviderDefinition> list = new ArrayList<>();
    for (MethodDescriptor methodDescriptor : methods) {
        Method method = methodDescriptor.getMethod();
        PetiteProvider petiteProvider = method.getAnnotation(PetiteProvider.class);
        if (petiteProvider == null) {
            continue;
        }
        String providerName = petiteProvider.value();
        if (StringUtil.isBlank(providerName)) {
            // default provider name
            providerName = method.getName();
            if (providerName.endsWith("Provider")) {
                providerName = StringUtil.substring(providerName, 0, -8);
            }
        }
        ProviderDefinition providerDefinition;
        if (Modifier.isStatic(method.getModifiers())) {
            providerDefinition = new ProviderDefinition(providerName, method);
        } else {
            providerDefinition = new ProviderDefinition(providerName, beanDefinition.getName(), method);
        }
        list.add(providerDefinition);
    }
    ProviderDefinition[] providers;
    if (list.isEmpty()) {
        providers = ProviderDefinition.EMPTY;
    } else {
        providers = list.toArray(new ProviderDefinition[list.size()]);
    }
    return providers;
}
Also used : ClassDescriptor(jodd.introspector.ClassDescriptor) ArrayList(java.util.ArrayList) ProviderDefinition(jodd.petite.ProviderDefinition) Method(java.lang.reflect.Method) MethodDescriptor(jodd.introspector.MethodDescriptor) PetiteProvider(jodd.petite.meta.PetiteProvider)

Aggregations

ClassDescriptor (jodd.introspector.ClassDescriptor)33 PropertyDescriptor (jodd.introspector.PropertyDescriptor)16 MethodDescriptor (jodd.introspector.MethodDescriptor)15 ArrayList (java.util.ArrayList)10 Method (java.lang.reflect.Method)8 FieldDescriptor (jodd.introspector.FieldDescriptor)5 Test (org.junit.Test)5 HashMap (java.util.HashMap)4 PetiteInject (jodd.petite.meta.PetiteInject)4 Map (java.util.Map)3 CtorDescriptor (jodd.introspector.CtorDescriptor)3 PetiteException (jodd.petite.PetiteException)3 Annotation (java.lang.annotation.Annotation)2 Constructor (java.lang.reflect.Constructor)2 Collection (java.util.Collection)2 LifeBean (jodd.bean.data.LifeBean)2 CachingIntrospector (jodd.introspector.CachingIntrospector)2 Field (java.lang.reflect.Field)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 List (java.util.List)1