/** * Determine whether the given method is an "equals" method. * @see java.lang.Object#equals */ public static boolean isEqualsMethod(@Nullable Method method) { return ReflectionUtils.isEqualsMethod(method); }
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (ReflectionUtils.isEqualsMethod(method)) { // Only consider equal when proxies are identical. return (proxy == args[0]); } else if (ReflectionUtils.isHashCodeMethod(method)) { // Use hashCode of service locator proxy. return System.identityHashCode(proxy); } else if (ReflectionUtils.isToStringMethod(method)) { return "Service locator: " + serviceLocatorInterface; } else { return invokeServiceLocatorMethod(method, args); } }
public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException { if ((method.getModifiers() & Modifier.PUBLIC) == 0 || method.isBridge()) { return; } if (method.getParameterTypes() == null || method.getParameterTypes().length != 1) { return; } if (method.getReturnType().equals(Void.TYPE) || ReflectionUtils.isEqualsMethod(method)) { return; } Assert.state(methodHolder.get() == null, "More than one non-void public method detected with single argument."); methodHolder.set(method); } });
/** * Create a {@link MethodInvoker} for the delegate from a single public * method. * * @param target an object to search for an appropriate method. * @param <C> the class. * @param <T> the type. * @return a {@link MethodInvoker} that calls a method on the delegate. */ public static <C, T> MethodInvoker getMethodInvokerForSingleArgument(Object target) { final AtomicReference<Method> methodHolder = new AtomicReference<>(); ReflectionUtils.doWithMethods(target.getClass(), method -> { if (method.getParameterTypes() == null || method.getParameterTypes().length != 1) { return; } if (method.getReturnType().equals(Void.TYPE) || ReflectionUtils.isEqualsMethod(method)) { return; } Assert.state(methodHolder.get() == null, "More than one non-void public method detected with single argument."); methodHolder.set(method); }); Method method = methodHolder.get(); return new SimpleMethodInvoker(target, method); } }
@Override @Nullable public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (ReflectionUtils.isEqualsMethod(method)) { return (isProxyForSameBshObject(args[0])); } else if (ReflectionUtils.isHashCodeMethod(method)) { return this.xt.hashCode(); } else if (ReflectionUtils.isToStringMethod(method)) { return "BeanShell object [" + this.xt + "]"; } try { Object result = this.xt.invokeMethod(method.getName(), args); if (result == Primitive.NULL || result == Primitive.VOID) { return null; } if (result instanceof Primitive) { return ((Primitive) result).getValue(); } return result; } catch (EvalError ex) { throw new BshExecutionException(ex); } }
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (ReflectionUtils.isEqualsMethod(method)) { // Only consider equal when proxies are identical. return (proxy == args[0]); } else if (ReflectionUtils.isHashCodeMethod(method)) { // Use hashCode of service locator proxy. return System.identityHashCode(proxy); } else if (ReflectionUtils.isToStringMethod(method)) { return "Service locator: " + serviceLocatorInterface; } else { return invokeServiceLocatorMethod(method, args); } }
@Override @Nullable public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (ReflectionUtils.isEqualsMethod(method)) { return (isProxyForSameBshObject(args[0])); } else if (ReflectionUtils.isHashCodeMethod(method)) { return this.xt.hashCode(); } else if (ReflectionUtils.isToStringMethod(method)) { return "BeanShell object [" + this.xt + "]"; } try { Object result = this.xt.invokeMethod(method.getName(), args); if (result == Primitive.NULL || result == Primitive.VOID) { return null; } if (result instanceof Primitive) { return ((Primitive) result).getValue(); } return result; } catch (EvalError ex) { throw new BshExecutionException(ex); } }
if (ReflectionUtils.isEqualsMethod(method)) { return proxyEquals(proxy, args[0]);
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (ReflectionUtils.isEqualsMethod(method)) { return annotationEquals(args[0]); } if (ReflectionUtils.isHashCodeMethod(method)) { return annotationHashCode(); } if (ReflectionUtils.isToStringMethod(method)) { return annotationToString(); } if (AnnotationUtils.isAnnotationTypeMethod(method)) { return annotationType(); } if (!AnnotationUtils.isAttributeMethod(method)) { throw new AnnotationConfigurationException(String.format( "Method [%s] is unsupported for synthesized annotation type [%s]", method, annotationType())); } return getAttributeValue(method); }
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (ReflectionUtils.isEqualsMethod(method)) { return annotationEquals(args[0]); } if (ReflectionUtils.isHashCodeMethod(method)) { return annotationHashCode(); } if (ReflectionUtils.isToStringMethod(method)) { return annotationToString(); } if (AnnotationUtils.isAnnotationTypeMethod(method)) { return annotationType(); } if (!AnnotationUtils.isAttributeMethod(method)) { throw new AnnotationConfigurationException(String.format( "Method [%s] is unsupported for synthesized annotation type [%s]", method, annotationType())); } return getAttributeValue(method); }
private static boolean isMethodDefinedOnObjectClass(Method method) { return method != null && (method.getDeclaringClass().equals(Object.class) || ReflectionUtils.isEqualsMethod(method) || ReflectionUtils.isHashCodeMethod(method) || ReflectionUtils.isToStringMethod(method) || AopUtils.isFinalizeMethod(method) || (method.getName().equals("clone") && method.getParameterTypes().length == 0)); }
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (ReflectionUtils.isEqualsMethod(method)) { // Only consider equal when proxies are identical. return (proxy == args[0]); } else if (ReflectionUtils.isHashCodeMethod(method)) { // Use hashCode of service locator proxy. return System.identityHashCode(proxy); } else if (ReflectionUtils.isToStringMethod(method)) { return "Service locator: " + serviceLocatorInterface.getName(); } else { return invokeServiceLocatorMethod(method, args); } }
public int accept(Method method) { if (isEqualsMethod(method) || isHashCodeMethod(method) || isToStringMethod(method) || isProxyTargetFactoryMethod(method)) { return 0; // invoke super } else { return 1; // invoke proxied object } }
public int accept(Method method) { if (isEqualsMethod(method) || isHashCodeMethod(method) || isToStringMethod(method) || isProxyTargetFactoryMethod(method)) { return 0; // invoke super } else { return 1; // invoke proxied object } }
public int accept(Method method) { if (isEqualsMethod(method) || isHashCodeMethod(method) || isToStringMethod(method) || isProxyTargetFactoryMethod(method)) { return 0; // invoke super } else { return 1; // invoke proxied object } }
if (ReflectionUtils.isEqualsMethod(method)) { return proxyEquals(proxy, args[0]);
public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException { if (found.value || method.getDeclaringClass() == Object.class) { return; } if (ReflectionUtils.isEqualsMethod(method)) { found.value = true; } } });
/** * Determine whether the given method is an "equals" method. * @see java.lang.Object#equals */ public static boolean isEqualsMethod(@Nullable Method method) { return ReflectionUtils.isEqualsMethod(method); }
private static boolean isMethodDefinedOnObjectClass(Method method) { return method != null && (method.getDeclaringClass().equals(Object.class) || ReflectionUtils.isEqualsMethod(method) || ReflectionUtils.isHashCodeMethod(method) || ReflectionUtils.isToStringMethod(method) || AopUtils.isFinalizeMethod(method) || (method.getName().equals("clone") && method.getParameterTypes().length == 0)); }
public int accept(Method method) { if (isEqualsMethod(method) || isHashCodeMethod(method) || isToStringMethod(method) || isProxyTargetFactoryMethod(method)) { return 0; // invoke super } else { return 1; // invoke proxied object } }