Search in sources :

Example 16 with MethodDescriptor

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

MethodDescriptor (jodd.introspector.MethodDescriptor)16 ClassDescriptor (jodd.introspector.ClassDescriptor)15 ArrayList (java.util.ArrayList)8 Method (java.lang.reflect.Method)7 FieldDescriptor (jodd.introspector.FieldDescriptor)5 PropertyDescriptor (jodd.introspector.PropertyDescriptor)5 PetiteInject (jodd.petite.meta.PetiteInject)3 PetiteException (jodd.petite.PetiteException)2 Annotation (java.lang.annotation.Annotation)1 Field (java.lang.reflect.Field)1 Collection (java.util.Collection)1 MadvocAction (jodd.madvoc.meta.MadvocAction)1 DestroyMethodPoint (jodd.petite.DestroyMethodPoint)1 InitMethodPoint (jodd.petite.InitMethodPoint)1 MethodInjectionPoint (jodd.petite.MethodInjectionPoint)1 PropertyInjectionPoint (jodd.petite.PropertyInjectionPoint)1 ProviderDefinition (jodd.petite.ProviderDefinition)1 SetInjectionPoint (jodd.petite.SetInjectionPoint)1 PetiteDestroyMethod (jodd.petite.meta.PetiteDestroyMethod)1 PetiteInitMethod (jodd.petite.meta.PetiteInitMethod)1