protected final void addMethod(Type type, Method method, boolean allowReaders, boolean allowWriters)
{
checkArgument(method.isAnnotationPresent(ThriftField.class));
ThriftField annotation = method.getAnnotation(ThriftField.class);
Class<?> clazz = TypeToken.of(type).getRawType();
// verify parameters
if (isValidateGetter(method)) {
if (allowReaders) {
MethodExtractor methodExtractor = new MethodExtractor(type, method, annotation, THRIFT_FIELD);
fields.add(methodExtractor);
extractors.add(methodExtractor);
}
else {
metadataErrors.addError("Reader method %s.%s is not allowed on a builder class", clazz.getName(), method.getName());
}
}
else if (isValidateSetter(method)) {
if (allowWriters) {
List<ParameterInjection> parameters;
if (method.getParameterTypes().length > 1 || Iterables.any(asList(method.getParameterAnnotations()[0]), Predicates.instanceOf(ThriftField.class))) {
parameters = getParameterInjections(
type,
method.getParameterAnnotations(),
resolveFieldTypes(type, method.getGenericParameterTypes()),
extractParameterNames(method));
if (annotation.value() != Short.MIN_VALUE) {
metadataErrors.addError("A method with annotated parameters can not have a field id specified: %s.%s ", clazz.getName(), method.getName());
}
if (!annotation.name().isEmpty()) {
metadataErrors.addError("A method with annotated parameters can not have a field name specified: %s.%s ", clazz.getName(), method.getName());
}
if (annotation.requiredness() == Requiredness.REQUIRED) {
metadataErrors.addError("A method with annotated parameters can not be marked as required: %s.%s ", clazz.getName(), method.getName());
}
}
else {
Type parameterType = resolveFieldTypes(type, method.getGenericParameterTypes())[0];