static boolean isMultiValue(Method method) { final FacadingInvocationHandler.OPERATOR oper = FacadingInvocationHandler.OPERATOR.getOperator(method); final boolean isMultiValue = oper.writeOp && method.getParameterTypes().length == 0 || FacadeUtils.isCollection( oper.writeOp && oper.numArgs > 0 ? method.getParameterTypes()[0] : method.getReturnType()); return isMultiValue; }
static String getBaseName(Method method) { final String name = method.getName(); final boolean isMultiValue = isMultiValue(method); String bName = null; final String[] prefixes = FacadingInvocationHandler.OPERATOR.getLengthSortedOperatorPrefixes(); for (String op : prefixes) { if (name.startsWith(op)) { if (isMultiValue && name.endsWith("s")) { bName = name.substring(op.length(), name.length() - 1); break; } else { bName = name.substring(op.length()); break; } } } return bName != null ? bName : name; }
static <A extends Annotation> A getAnnotation(Method method, Class<A> annotation) { if (method.isAnnotationPresent(annotation)) { return method.getAnnotation(annotation); } final String field = getBaseName(method); Class<?> clazz = method.getDeclaringClass(); for (Method m : clazz.getMethods()) { final boolean multiValue = isMultiValue(m); if (m.isAnnotationPresent(annotation)) { for (String op : FacadingInvocationHandler.OPERATOR.getOperatorPrefixes()) { if (m.getName().equals(op + field)) { return m.getAnnotation(annotation); } else if (multiValue && m.getName().equals(op + field + "s")) { return m.getAnnotation(annotation); } else { } } } } return null; }