com.github.datalking.web.mvc.method.HandlerMethodSelector Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of play-mvc Show documentation
Show all versions of play-mvc Show documentation
simple mvc framework based on java servlet.
The newest version!
package com.github.datalking.web.mvc.method;
import com.github.datalking.util.ClassUtils;
import com.github.datalking.util.ReflectionUtils;
import com.github.datalking.util.ReflectionUtils.MethodFilter;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.Set;
/**
* 方法选择 工具类
*
* @author yaoo on 4/28/18
*/
public abstract class HandlerMethodSelector {
/**
* 返回handlerType中符合handlerMethodFilter的方法set
*/
public static Set selectMethods(final Class> handlerType, final MethodFilter handlerMethodFilter) {
Set handlerMethods = new LinkedHashSet<>();
Set> handlerTypes = new LinkedHashSet<>();
Class> specificHandlerType = null;
if (!Proxy.isProxyClass(handlerType)) {
handlerTypes.add(handlerType);
specificHandlerType = handlerType;
}
handlerTypes.addAll(Arrays.asList(handlerType.getInterfaces()));
for (Class> currentHandlerType : handlerTypes) {
final Class> targetClass = (specificHandlerType != null ? specificHandlerType : currentHandlerType);
ReflectionUtils.doWithMethods(currentHandlerType, new ReflectionUtils.MethodCallback() {
public void doWith(Method method) {
Method specificMethod = ClassUtils.getMostSpecificMethod(method, targetClass);
// Method bridgedMethod = BridgeMethodResolver.findBridgedMethod(specificMethod);
Method bridgedMethod = specificMethod;
if (handlerMethodFilter.matches(specificMethod) &&
(bridgedMethod == specificMethod || !handlerMethodFilter.matches(bridgedMethod))) {
handlerMethods.add(specificMethod);
}
}
}, ReflectionUtils.USER_DECLARED_METHODS);
}
return handlerMethods;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy