Search in sources :

Example 11 with Type

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;
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) WildcardType(java.lang.reflect.WildcardType) Collection(java.util.Collection) Nullable(javax.annotation.Nullable)

Example 12 with Type

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));
}
Also used : Type(java.lang.reflect.Type) MessageHandlerMetadata(org.eclipse.jetty.websocket.jsr356.metadata.MessageHandlerMetadata) DecoderMetadata(org.eclipse.jetty.websocket.jsr356.metadata.DecoderMetadata) Test(org.junit.Test)

Example 13 with Type

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));
}
Also used : Type(java.lang.reflect.Type) MessageHandlerMetadata(org.eclipse.jetty.websocket.jsr356.metadata.MessageHandlerMetadata) DecoderMetadata(org.eclipse.jetty.websocket.jsr356.metadata.DecoderMetadata) Test(org.junit.Test)

Example 14 with Type

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();
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type)

Example 15 with Type

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));
}
Also used : DTOHelper.convertType(org.eclipse.che.plugin.typescript.dto.DTOHelper.convertType) Type(java.lang.reflect.Type)

Aggregations

Type (java.lang.reflect.Type)6477 ParameterizedType (java.lang.reflect.ParameterizedType)1798 ProgressRequestBody (io.kubernetes.client.ProgressRequestBody)722 ProgressResponseBody (io.kubernetes.client.ProgressResponseBody)722 GenericArrayType (java.lang.reflect.GenericArrayType)711 WildcardType (java.lang.reflect.WildcardType)580 Test (org.junit.Test)513 ArrayList (java.util.ArrayList)429 Method (java.lang.reflect.Method)424 TypeVariable (java.lang.reflect.TypeVariable)350 List (java.util.List)342 Map (java.util.Map)296 Gson (com.google.gson.Gson)230 V1Status (io.kubernetes.client.models.V1Status)228 V1Status (io.kubernetes.client.openapi.models.V1Status)224 HashMap (java.util.HashMap)211 Field (java.lang.reflect.Field)170 Annotation (java.lang.annotation.Annotation)161 IOException (java.io.IOException)146 Collection (java.util.Collection)116