protected final void addMethods(Type type, boolean allowReaders, boolean allowWriters) { Class<?> clazz = TypeToken.of(type).getRawType(); for (Method fieldMethod : findAnnotatedMethods(clazz, ThriftField.class)) { addMethod(type, fieldMethod, allowReaders, allowWriters); } // find invalid methods not skipped by findAnnotatedMethods() for (Method method : getAllDeclaredMethods(clazz)) { if (method.isAnnotationPresent(ThriftField.class) || hasThriftFieldAnnotation(method)) { if (!Modifier.isPublic(method.getModifiers())) { metadataErrors.addError("@ThriftField method '%s' is not public", method.toGenericString()); } if (Modifier.isStatic(method.getModifiers())) { metadataErrors.addError("@ThriftField method '%s' is static", method.toGenericString()); } } } }
public static ThriftType array(ThriftTypeReference valueTypeReference) { checkNotNull(valueTypeReference, "valueTypeReference is null"); Class<?> javaType = ReflectionHelper.getArrayOfType(valueTypeReference.getJavaType()); return new ThriftType(ThriftProtocolType.LIST, javaType, null, valueTypeReference); }
private static <T extends Annotation> void addEffectiveClassAnnotations(Class<?> type, Class<T> annotation, ImmutableSet.Builder<T> builder) { if (type.isAnnotationPresent(annotation)) { builder.add(type.getAnnotation(annotation)); return; } if (type.getSuperclass() != null) { addEffectiveClassAnnotations(type.getSuperclass(), annotation, builder); } for (Class<?> anInterface : type.getInterfaces()) { addEffectiveClassAnnotations(anInterface, annotation, builder); } }
Type mapKeyType = getMapKeyType(javaType); Type mapValueType = getMapValueType(javaType); return isSupportedStructFieldType(mapKeyType) && isSupportedStructFieldType(mapValueType); Type elementType = getIterableType(javaType); return isSupportedStructFieldType(elementType); Type elementType = getIterableType(javaType); return isSupportedStructFieldType(elementType);
Type mapKeyType = getMapKeyType(javaType); Type mapValueType = getMapValueType(javaType); return map(getMapKeyThriftTypeReference(mapKeyType), getMapValueThriftTypeReference(mapValueType)); Type elementType = getIterableType(javaType); return set(getCollectionElementThriftTypeReference(elementType)); Type elementType = getIterableType(javaType); return list(getCollectionElementThriftTypeReference(elementType)); Type returnType = getFutureReturnType(javaType);
protected final void addBuilderMethods() for (Method method : findAnnotatedMethods(getBuilderClass(), ThriftConstructor.class)) { List<ParameterInjection> parameters = getParameterInjections( builderType, method.getParameterAnnotations(), resolveFieldTypes(builderType, method.getGenericParameterTypes()), extractParameterNames(method)); for (Method method : getAllDeclaredMethods(getBuilderClass())) { if (method.isAnnotationPresent(ThriftConstructor.class) || hasThriftFieldAnnotation(method)) { if (!Modifier.isPublic(method.getModifiers())) {
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()); Type parameterType = resolveFieldTypes(type, method.getGenericParameterTypes())[0]; parameters = ImmutableList.of(new ParameterInjection(type, 0, annotation, ReflectionHelper.extractFieldName(method), parameterType));
private void extractThriftUnionId() Collection<Field> idFields = ReflectionHelper.findAnnotatedFields(getStructClass(), ThriftUnionId.class); Collection<Method> idMethods = findAnnotatedMethods(getStructClass(), ThriftUnionId.class);
protected final void addFields(Class<?> clazz, boolean allowReaders, boolean allowWriters) { for (Field fieldField : ReflectionHelper.findAnnotatedFields(clazz, ThriftField.class)) { addField(fieldField, allowReaders, allowWriters); } // find invalid fields not skipped by findAnnotatedFields() for (Field field : getAllDeclaredFields(clazz)) { if (field.isAnnotationPresent(ThriftField.class)) { if (!Modifier.isPublic(field.getModifiers())) { metadataErrors.addError("@ThriftField field '%s' is not public", field.toGenericString()); } if (Modifier.isStatic(field.getModifiers())) { metadataErrors.addError("@ThriftField field '%s' is static", field.toGenericString()); } } } }
type, constructor.getParameterAnnotations(), resolveFieldTypes(structType, constructor.getGenericParameterTypes()), extractParameterNames(constructor)); if (parameters != null) { fields.addAll(parameters);
@DataProvider public Object[][] getTestCasesWithLegacyFieldIds() { List<Object[]> cases = new ArrayList<>(); for (Method m : ReflectionHelper.findAnnotatedMethods(DummyService.class, ThriftMethod.class)) { String name = m.getName(); if (name.startsWith("validNonLegacy")) { continue; } else if (name.startsWith("validLegacy")) { cases.add(new Object[] { new Method[] { m } }); } else if (name.startsWith("invalid")) { continue; } else { throw new AssertionError("Weird method " + m); } } return cases.toArray(new Object[][] {}); }
@Test public void testExtractParameterNamesNoAnnotations() throws Exception { assertEquals(extractParameterNames(getClass().getDeclaredMethod("noAnnotations", String.class, String.class, String.class)), new String[]{"a", "b", "c"}); }
for (Field f : ReflectionHelper.findAnnotatedFields(SomeThriftFields.class, ThriftField.class)) { final Optional<Boolean> expected; if (f.getName().startsWith("expectTrue")) {
@Override public String extractName() { return extractFieldName(method.getName()); }
@SuppressWarnings("PMD.EmptyCatchBlock") public static Method findAnnotatedMethod(Class<?> configClass, Class<? extends Annotation> annotation, String methodName, Class<?>... paramTypes) { try { Method method = configClass.getDeclaredMethod(methodName, paramTypes); if (method != null && method.isAnnotationPresent(annotation)) { return method; } } catch (NoSuchMethodException e) { // ignore } if (configClass.getSuperclass() != null) { Method managedMethod = findAnnotatedMethod( configClass.getSuperclass(), annotation, methodName, paramTypes); if (managedMethod != null) { return managedMethod; } } for (Class<?> iface : configClass.getInterfaces()) { Method managedMethod = findAnnotatedMethod(iface, annotation, methodName, paramTypes); if (managedMethod != null) { return managedMethod; } } return null; }
Type mapKeyType = getMapKeyType(javaType); Type mapValueType = getMapValueType(javaType); if (isSupportedStructFieldType(mapKeyType) && isSupportedStructFieldType(mapValueType)) { Type elementType = getIterableType(javaType); if (isSupportedStructFieldType(elementType)) { return ThriftProtocolType.SET; Type elementType = getIterableType(javaType); if (isSupportedStructFieldType(elementType)) { return ThriftProtocolType.LIST;
Type mapKeyType = getMapKeyType(javaType); Type mapValueType = getMapValueType(javaType); return map(getThriftType(mapKeyType), getThriftType(mapValueType)); Type elementType = getIterableType(javaType); return set(getThriftType(elementType)); Type elementType = getIterableType(javaType); return list(getThriftType(elementType)); Type returnType = getFutureReturnType(javaType); return getThriftType(returnType);
protected final void addBuilderMethods() for (Method method : findAnnotatedMethods(getBuilderClass(), ThriftConstructor.class)) { List<ParameterInjection> parameters = getParameterInjections( builderType, method.getParameterAnnotations(), resolveFieldTypes(builderType, method.getGenericParameterTypes()), extractParameterNames(method)); for (Method method : getAllDeclaredMethods(getBuilderClass())) { if (method.isAnnotationPresent(ThriftConstructor.class) || hasThriftFieldAnnotation(method)) { if (!Modifier.isPublic(method.getModifiers())) {
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()); Type parameterType = resolveFieldTypes(type, method.getGenericParameterTypes())[0]; parameters = ImmutableList.of(new ParameterInjection(type, 0, annotation, ReflectionHelper.extractFieldName(method), parameterType));
private void extractThriftUnionId() Collection<Field> idFields = ReflectionHelper.findAnnotatedFields(getStructClass(), ThriftUnionId.class); Collection<Method> idMethods = findAnnotatedMethods(getStructClass(), ThriftUnionId.class);