jodd.petite.resolver.MethodResolver Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jodd-petite Show documentation
Show all versions of jodd-petite Show documentation
Jodd Petite is slick and lightweight DI container that uses annotations and supports sufficient most of features offered by other containers.
// Copyright (c) 2003-2014, Jodd Team (jodd.org). All Rights Reserved.
package jodd.petite.resolver;
import jodd.introspector.ClassDescriptor;
import jodd.introspector.ClassIntrospector;
import jodd.introspector.MethodDescriptor;
import jodd.petite.InjectionPointFactory;
import jodd.petite.MethodInjectionPoint;
import jodd.petite.PetiteUtil;
import jodd.petite.meta.PetiteInject;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
/**
* Method reference resolver.
*/
public class MethodResolver {
protected final InjectionPointFactory injectionPointFactory;
public MethodResolver(InjectionPointFactory injectionPointFactory) {
this.injectionPointFactory = injectionPointFactory;
}
public MethodInjectionPoint[] resolve(Class type) {
// lookup methods
ClassDescriptor cd = ClassIntrospector.lookup(type);
List list = new ArrayList();
MethodDescriptor[] allMethods = cd.getAllMethodDescriptors();
for (MethodDescriptor methodDescriptor : allMethods) {
Method method = methodDescriptor.getMethod();
PetiteInject ref = method.getAnnotation(PetiteInject.class);
if (ref == null) {
continue;
}
String[][] references = PetiteUtil.convertAnnValueToReferences(ref.value());
list.add(injectionPointFactory.createMethodInjectionPoint(method, references));
}
MethodInjectionPoint[] methods;
if (list.isEmpty()) {
methods = MethodInjectionPoint.EMPTY;
} else {
methods = list.toArray(new MethodInjectionPoint[list.size()]);
}
return methods;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy