use of java.lang.reflect.Type in project buck by facebook.
the class Types method getContainerClass.
/**
* @return The raw type of the {@link Collection} a field represents, even if contained in an
* {@link Optional}, but without the ParameterizedType information.
*/
@SuppressWarnings("unchecked")
@Nullable
public static Class<? extends Collection<?>> getContainerClass(Field field) {
Type type = getFirstNonOptionalType(field);
if (!(type instanceof ParameterizedType)) {
return null;
}
Type rawType = ((ParameterizedType) type).getRawType();
if (!(rawType instanceof Class)) {
return null;
}
Class<?> clazz = (Class<?>) rawType;
if (!(Collection.class.isAssignableFrom(clazz))) {
return null;
}
return (Class<? extends Collection<?>>) clazz;
}
use of java.lang.reflect.Type in project jetty.project by eclipse.
the class MessageHandlerFactoryTest method testStringPartial.
@Test
public void testStringPartial() throws DeploymentException {
List<MessageHandlerMetadata> metadatas = factory.getMetadata(StringPartialHandler.class);
Assert.assertThat("Metadata.list.size", metadatas.size(), is(1));
MessageHandlerMetadata handlerMetadata = metadatas.get(0);
DecoderMetadata decoderMetadata = decoders.getMetadataFor(handlerMetadata.getMessageClass());
Assert.assertThat("Message Type", decoderMetadata.getMessageType(), is(MessageType.TEXT));
Assert.assertThat("Message Class", handlerMetadata.getMessageClass(), is((Type) String.class));
}
use of java.lang.reflect.Type in project jetty.project by eclipse.
the class MessageHandlerFactoryTest method testByteArrayPartial.
@Test
public void testByteArrayPartial() throws DeploymentException {
List<MessageHandlerMetadata> metadatas = factory.getMetadata(ByteArrayPartialHandler.class);
Assert.assertThat("Metadata.list.size", metadatas.size(), is(1));
MessageHandlerMetadata handlerMetadata = metadatas.get(0);
DecoderMetadata decoderMetadata = decoders.getMetadataFor(handlerMetadata.getMessageClass());
Assert.assertThat("Message Type", decoderMetadata.getMessageType(), is(MessageType.BINARY));
Assert.assertThat("Message Class", handlerMetadata.getMessageClass(), is((Type) byte[].class));
}
use of java.lang.reflect.Type in project che by eclipse.
the class DTOHelper method convertType.
/**
* Convert Java type to TypeScript type
*/
public static String convertType(Type type) {
if (type instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType) type;
Type rawType = parameterizedType.getRawType();
return convertParametrizedType(type, parameterizedType, rawType);
} else if (String.class.equals(type) || (type instanceof Class && ((Class) type).isEnum())) {
// Maybe find a better enum type for typescript
return "string";
} else if (Integer.class.equals(type) || Integer.TYPE.equals(type) || Long.class.equals(type) || Long.TYPE.equals(type) || Double.class.equals(type) || Double.TYPE.equals(type)) {
return "number";
} else if (Boolean.class.equals(type)) {
return "boolean";
}
return type.getTypeName();
}
use of java.lang.reflect.Type in project che by eclipse.
the class DtoModel method analyzeDtoWithMethod.
/**
* Populate model from given reflect with method
* @param method the method to analyze
* @param methodModel the model to update
*/
protected void analyzeDtoWithMethod(Method method, MethodModel methodModel) {
methodModel.setWith(true);
// add the parameter
Type fieldType = method.getGenericParameterTypes()[0];
String fieldName = getWithFieldName(method);
fieldAttributes.put(fieldName, fieldType);
methodModel.setFieldName(fieldName);
methodModel.setFieldType(convertType(fieldType));
}
Aggregations