public TypeContext(MethodDescriptor methodDescriptor) { this(methodDescriptor, methodDescriptor.getReturnType()); }
Object toDelegate(Object object) { return valueMethod.invoke(object); }
private MethodDescriptor getMethodDescriptor(Method method) { return method != null ? new MethodDescriptor(this, method) : null; }
@Override String toString(int hilightParameter) { return getDeclaringType().getName() + "." + getName() + getParameters().stream() .map(parameterDescriptor -> parameterToString(parameterDescriptor, hilightParameter)) .collect(Collectors.joining(",", "(", ")")); }
private static void validateValueMethod(MethodDescriptor method) { if (method.isStatic()) { throw new IllegalArgumentException("@VersionValue/@JsonValue must not be static"); } if (method.isAbstract()) { throw new IllegalArgumentException("@VersionValue/@JsonValue must not be abstract"); } if (method.getParameterCount() > 0) { throw new IllegalArgumentException("@VersionValue/@JsonValue cannot have parameters"); } if (method.getRawReturnType() == void.class) { throw new IllegalArgumentException("@VersionValue/@JsonValue cannot be void"); } } }
private void validateCreator(StaticExecutable creator, TypeDescriptor type, List<Class<?>> expectedParameters) { if (creator instanceof MethodDescriptor) { MethodDescriptor method = (MethodDescriptor) creator; if (!method.getParameterTypes().equals(expectedParameters)) { throw new IllegalArgumentException("@VersionCreator/@JsonCreator " + method + " parameters should match " + expectedParameters); } if (!type.equalTo(method.getReturnType())) { throw new IllegalArgumentException("@VersionCreator/@JsonCreator " + method + " return type should be " + type); } if (!method.isStatic()) { throw new IllegalArgumentException("@VersionCreator/@JsonCreator method should be static in " + type); } } }
@Override public TypeDescriptor getType() { if (readMethod != null) { return readMethod.getReturnType(); } else { return writeMethod.getParameters().get(0).getType(); } }
@Override public boolean isWritableFrom(TypeDescriptor typeDescriptor) { return writeMethod != null && writeMethod.applies(typeDescriptor); }
public TypeDescriptor getDeclaringType() { if (readMethod != null) { return readMethod.getDeclaringType(); } else { return writeMethod.getDeclaringType(); } }
@Nonnull @Override public Result<MethodDescriptor> delegateValue(MethodDescriptor method) { JsonValue jsonValue = method.getAnnotation(JsonValue.class); if (jsonValue != null && jsonValue.value()) { return Result.of(method); } return Result.notFound(); }
@Override public boolean isReadableFrom(TypeDescriptor typeDescriptor) { return readMethod != null && readMethod.applies(typeDescriptor); }
@Override public Object invokeStatic(Object... args) { return invoke(null, args); }
private void collectMethods(Class<?> clazz, Map<MethodSignature, MethodDescriptor> allMethods) { for (Method method : clazz.getDeclaredMethods()) { if (typeDescriptors.methodFilter.apply(method)) { MethodSignature identifier = new MethodSignature(method); if (!allMethods.containsKey(identifier)) { allMethods.put(identifier, new MethodDescriptor(this, method)); } } } Class<?> superClass = clazz.getSuperclass(); if (superClass != null) { collectMethods(superClass, allMethods); } }
public Object get(Object bean) { return readMethod.invoke(bean); }
public void set(Object bean, Object value) { writeMethod.invoke(bean, value); }