本文整理匯總了Java中org.reflections.ReflectionUtils.getMethods方法的典型用法代碼示例。如果您正苦於以下問題:Java ReflectionUtils.getMethods方法的具體用法?Java ReflectionUtils.getMethods怎麽用?Java ReflectionUtils.getMethods使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.reflections.ReflectionUtils
的用法示例。
在下文中一共展示了ReflectionUtils.getMethods方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getUpgradeMethod
import org.reflections.ReflectionUtils; //導入方法依賴的package包/類
private Method getUpgradeMethod(DomainEvent event) {
Class<?> providerClass = eventTypeToProvider.get(event.getClass()).getClass();
Set<Method> methods =
ReflectionUtils.getMethods(providerClass,
ReflectionUtils.withAnnotation(EventUpgrader.class),
ReflectionUtils.withParametersCount(1),
ReflectionUtils.withParameters(event.getClass()));
if (methods.size() != 1) {
throw new RuntimeException(
String.format("Duplicate upgrade methods for event type %s in class %s.",
event.getClass(), providerClass));
}
return methods.stream().findFirst().get();
}
示例2: supportedDomainEvents
import org.reflections.ReflectionUtils; //導入方法依賴的package包/類
Set<Class<DomainEvent>> supportedDomainEvents(Class<?> upgradeProvider) {
Set<Method> methods =
ReflectionUtils.getMethods(upgradeProvider,
ReflectionUtils.withAnnotation(EventUpgrader.class));
if (methods.isEmpty()) {
throw new RuntimeException(
String.format("No event eventTypeToProvider found in class %s", upgradeProvider));
}
Set<Class<DomainEvent>> result = new HashSet<>();
for (Method method : methods) {
if (method.getParameterCount() != 1) {
throw new RuntimeException(
String.format("Parameter count for upgrade method %s must be exactly one.", method));
}
result.add((Class<DomainEvent>) method.getParameters()[0].getType());
}
return result;
}
示例3: findLifecycleMethod
import org.reflections.ReflectionUtils; //導入方法依賴的package包/類
@SuppressWarnings({ "rawtypes", "unchecked" })
private Method findLifecycleMethod(final Class lifecycleAnnotationClass) {
Set<Method> methods = ReflectionUtils.getMethods(declaringClass, new Predicate<Method>() {
@Override
public boolean apply(Method input) {
return input != null && input.getAnnotation(lifecycleAnnotationClass) != null;
}
});
if (methods.isEmpty()) {
return null;
}
if (methods.size() > 1) {
throw new BootstrapException("Found multiple " + lifecycleAnnotationClass.getSimpleName() + " methods in class " + declaringClass.getSimpleName() + ". Only 1 is allowed.");
}
return methods.iterator().next();
}
示例4: createMethodInvokers
import org.reflections.ReflectionUtils; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
List<MethodInvoker> createMethodInvokers(Class<?> cls) {
LambdaLocal lambdaLocal = cls.getAnnotation(LambdaLocal.class);
if (lambdaLocal.value().length != 1) {
throw new IllegalArgumentException(
"@LambdaLocal must have only one value() if using with AbstractLambdaRestService");
}
String lambdaLocalPath = lambdaLocal.value()[0];
Set<Method> methods = ReflectionUtils.getMethods(cls, ReflectionUtils.withAnnotation(RestMethod.class));
return methods.stream()
.map(method -> new MethodInvoker(cls, method, lambdaLocalPath))
.collect(Collectors.toList());
}
示例5: resolvePolicyMethod
import org.reflections.ReflectionUtils; //導入方法依賴的package包/類
private Method resolvePolicyMethod(Class<?> clazz, Class<? extends Annotation> annotationClass) {
Set<Method> methods = ReflectionUtils.getMethods(
clazz,
withModifier(Modifier.PUBLIC),
withAnnotation(annotationClass));
if (methods.isEmpty()) {
return null;
}
return methods.iterator().next();
}
示例6: findActionMethod
import org.reflections.ReflectionUtils; //導入方法依賴的package包/類
/**
* Uses reflection to find and return the method that we later on want to invoke in our {@link #propertyChangeEx(PropertyChangeEvent)} method. The method instance searched for needs to
* <ul>
* <li>belong to the given <code>componentClass</code></li>
* <li>the given name actionMethodName</li>
* <li>have no parameter</li>
* </ul>
*
* @param componentClass
* @param actionMethodName
* @return
* @throws IllegalStateException if more or less than one matching method is found.
*/
@SuppressWarnings("unchecked")
public static final <T extends Object> Method findActionMethod(final Class<T> componentClass, final String actionMethodName)
{
Check.assumeNotNull(componentClass, "componentClass not null");
Check.assumeNotEmpty(actionMethodName, "actionMethodName not empty");
final Set<Method> methods = ReflectionUtils.getMethods(componentClass, new Predicate<Method>()
{
@Override
public boolean apply(final Method method)
{
if (method.getParameterTypes().length > 0)
{
return false;
}
final String methodName = method.getName();
if (!actionMethodName.equals(methodName))
{
return false;
}
return true;
}
});
if (methods == null || methods.isEmpty())
{
throw new IllegalStateException("No action method found in " + componentClass + " for action name'" + actionMethodName + "'");
}
else if (methods.size() > 1)
{
throw new IllegalStateException("More then one action method found in " + componentClass + " for action name'" + actionMethodName + "': " + methods);
}
else
{
return methods.iterator().next();
}
}
示例7: findMethodForProperty
import org.reflections.ReflectionUtils; //導入方法依賴的package包/類
/**
*
* @param object
* @param propertyName
* @param <T>
* @return
*/
@SuppressWarnings("unchecked")
public static <T> Optional<Method> findMethodForProperty(T object, String propertyName) {
final Set<Method> methods = ReflectionUtils.getMethods(
object.getClass(),
ReflectionUtils.withModifier(Modifier.PUBLIC),
ReflectionUtils.withName(PROPERTY_TO_METHOD_NAME.apply("set", propertyName))
);
return methods.size() == 1 ? methods.stream().findFirst() : Optional.empty();
}
示例8: getDomainEventHandlerMethods
import org.reflections.ReflectionUtils; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
private Set<Method> getDomainEventHandlerMethods() {
return ReflectionUtils.getMethods(getClass(),
ReflectionUtils.withAnnotation(DomainEventHandler.class),
ReflectionUtils.withParametersCount(1));
}