use of net.sf.cglib.reflect.FastClass in project codeforces-commons by Codeforces.
the class MethodArgumentsFormatUtil method getPropertyMethod.
private static FastMethod getPropertyMethod(Class<?> clazz, String property) {
ClassAndProperty classAndProperty = new ClassAndProperty(clazz, property);
FastMethod method = methodByProperty.get(classAndProperty);
if (method == null) {
FastClass cglibClazz = FastClass.create(clazz);
try {
method = cglibClazz.getMethod("get" + StringUtils.capitalize(property), ArrayUtils.EMPTY_CLASS_ARRAY);
} catch (NoSuchMethodError ignored) {
// No operations.
}
if (method == null) {
try {
method = cglibClazz.getMethod("is" + StringUtils.capitalize(property), ArrayUtils.EMPTY_CLASS_ARRAY);
} catch (NoSuchMethodError ignored) {
// No operations.
}
}
if (method == null) {
try {
method = cglibClazz.getMethod(property, ArrayUtils.EMPTY_CLASS_ARRAY);
} catch (NoSuchMethodError ignored) {
// No operations.
}
}
if (method != null) {
methodByProperty.put(classAndProperty, method);
} else {
throw new IllegalArgumentException("Unable to find getter for property `" + property + "` in " + clazz + '.');
}
}
return method;
}
use of net.sf.cglib.reflect.FastClass in project swift by luastar.
the class RpcServerChannelHandler method handleRequest.
protected Object handleRequest(RpcRequest request) throws Exception {
// 获取服务对象
String serviceName = request.getInterfaceName();
String serviceVersion = request.getServiceVersion();
if (StringUtils.isNotEmpty(serviceVersion)) {
serviceName += "-" + serviceVersion;
}
Object serviceBean = handlerMap.get(serviceName);
if (serviceBean == null) {
throw new RuntimeException(String.format("can not find service bean by key: %s", serviceName));
}
// 获取反射调用所需的参数
Class<?> serviceClass = serviceBean.getClass();
String methodName = request.getMethodName();
Class<?>[] parameterTypes = request.getParameterTypes();
Object[] parameters = request.getParameters();
// 执行反射调用
/*
Method method = serviceClass.getMethod(methodName, parameterTypes);
method.setAccessible(true);
return method.invoke(serviceBean, parameters);
*/
// 使用 CGLib 执行反射调用
FastClass serviceFastClass = FastClass.create(serviceClass);
FastMethod serviceFastMethod = serviceFastClass.getMethod(methodName, parameterTypes);
return serviceFastMethod.invoke(serviceBean, parameters);
}
use of net.sf.cglib.reflect.FastClass in project codeforces-commons by Codeforces.
the class ReflectionUtil method buildSettersMap.
private static Map<String, FastMethod> buildSettersMap(Class<?> clazz) {
Map<String, FastMethod> result = new HashMap<>();
FastClass fastClass = getFastClass(clazz);
Method[] methods = clazz.getMethods();
for (Method method : methods) {
if (!Modifier.isStatic(method.getModifiers())) {
String property = getSetterProperty(method);
if (property != null) {
result.put(property, fastClass.getMethod(method));
}
}
}
return result;
}
use of net.sf.cglib.reflect.FastClass in project codeforces-commons by Codeforces.
the class ReflectionUtil method getFastClass.
private static FastClass getFastClass(Class<?> clazz) {
FastClass result = fastClassCache.get(clazz);
while (result == null) {
FastClass fastClass = FastClass.create(clazz);
fastClassCache.putIfAbsent(clazz, fastClass);
result = fastClassCache.get(clazz);
}
return result;
}
use of net.sf.cglib.reflect.FastClass in project codeforces-commons by Codeforces.
the class ReflectionUtil method buildGettersMap.
private static Map<String, FastMethod> buildGettersMap(Class<?> clazz) {
Map<String, FastMethod> result = new HashMap<>();
FastClass fastClass = getFastClass(clazz);
Method[] methods = clazz.getMethods();
for (Method method : methods) {
if (!Modifier.isStatic(method.getModifiers())) {
String property = getGetterProperty(method);
if (property != null) {
result.put(property, fastClass.getMethod(method));
}
}
}
return result;
}
Aggregations