private static NamedTypeInfo newNamedTypeInfo(TypeSignature typeSignature) { final Optional<Object> namedTypeDescriptor = typeSignature.namedTypeDescriptor(); if (!namedTypeDescriptor.isPresent()) { throw new IllegalArgumentException("cannot create a named type from: " + typeSignature); } final Class<?> type = (Class<?>) namedTypeDescriptor.get(); if (type.isEnum()) { @SuppressWarnings("unchecked") final Class<? extends Enum<?>> enumType = (Class<? extends Enum<?>>) type; return new EnumInfo(enumType); } if (TException.class.isAssignableFrom(type)) { @SuppressWarnings("unchecked") final Class<? extends TException> castType = (Class<? extends TException>) type; return newExceptionInfo(castType); } assert TBase.class.isAssignableFrom(type); @SuppressWarnings("unchecked") final Class<? extends TBase<?, ?>> castType = (Class<? extends TBase<?, ?>>) type; return newStructInfo(castType); }
@Test public void testNewExceptionInfo() { final ExceptionInfo exception = newExceptionInfo(FooServiceException.class); assertThat(exception).isEqualTo(new ExceptionInfo( FooServiceException.class.getName(), ImmutableList.of(newFieldInfo( FooServiceException.class, new FieldMetaData("stringVal", TFieldRequirementType.DEFAULT, new FieldValueMetaData(TType.STRING, false)))))); }
private static NamedTypeInfo newNamedTypeInfo(TypeSignature typeSignature) { final Class<?> type = (Class<?>) typeSignature.namedTypeDescriptor().get(); if (type.isEnum()) { return newEnumInfo(type); } if (TException.class.isAssignableFrom(type)) { @SuppressWarnings("unchecked") final Class<? extends TException> castType = (Class<? extends TException>) type; return newExceptionInfo(castType); } assert TBase.class.isAssignableFrom(type); @SuppressWarnings("unchecked") final Class<? extends TBase<?, ?>> castType = (Class<? extends TBase<?, ?>>) type; return newStructInfo(castType); }
private static NamedTypeInfo newNamedTypeInfo(TypeSignature typeSignature) { final Optional<Object> namedTypeDescriptor = typeSignature.namedTypeDescriptor(); if (!namedTypeDescriptor.isPresent()) { throw new IllegalArgumentException("cannot create a named type from: " + typeSignature); } final Class<?> type = (Class<?>) namedTypeDescriptor.get(); if (type.isEnum()) { @SuppressWarnings("unchecked") final Class<? extends Enum<?>> enumType = (Class<? extends Enum<?>>) type; return new EnumInfo(enumType); } if (TException.class.isAssignableFrom(type)) { @SuppressWarnings("unchecked") final Class<? extends TException> castType = (Class<? extends TException>) type; return newExceptionInfo(castType); } assert TBase.class.isAssignableFrom(type); @SuppressWarnings("unchecked") final Class<? extends TBase<?, ?>> castType = (Class<? extends TBase<?, ?>>) type; return newStructInfo(castType); }
private static NamedTypeInfo newNamedTypeInfo(TypeSignature typeSignature) { final Optional<Object> namedTypeDescriptor = typeSignature.namedTypeDescriptor(); if (!namedTypeDescriptor.isPresent()) { throw new IllegalArgumentException("cannot create a named type from: " + typeSignature); } final Class<?> type = (Class<?>) namedTypeDescriptor.get(); if (type.isEnum()) { @SuppressWarnings("unchecked") final Class<? extends Enum<?>> enumType = (Class<? extends Enum<?>>) type; return new EnumInfo(enumType); } if (TException.class.isAssignableFrom(type)) { @SuppressWarnings("unchecked") final Class<? extends TException> castType = (Class<? extends TException>) type; return newExceptionInfo(castType); } assert TBase.class.isAssignableFrom(type); @SuppressWarnings("unchecked") final Class<? extends TBase<?, ?>> castType = (Class<? extends TBase<?, ?>>) type; return newStructInfo(castType); }