Search in sources :

Example 6 with ParameterizedType

use of java.lang.reflect.ParameterizedType in project cucumber-jvm by cucumber.

the class Java8StepDefinition method getParameterInfos.

private List<ParameterInfo> getParameterInfos(Class<? extends StepdefBody> bodyClass, TypeIntrospector typeIntrospector, int parameterCount) throws Exception {
    Type genericInterface = bodyClass.getGenericInterfaces()[0];
    Type[] argumentTypes;
    if (genericInterface instanceof ParameterizedType) {
        argumentTypes = ((ParameterizedType) genericInterface).getActualTypeArguments();
    } else {
        Class<? extends StepdefBody> interfac3 = (Class<? extends StepdefBody>) bodyClass.getInterfaces()[0];
        argumentTypes = typeIntrospector.getGenericTypes(bodyClass, interfac3);
    }
    Type[] argumentTypesOfCorrectLength = new Type[parameterCount];
    System.arraycopy(argumentTypes, argumentTypes.length - parameterCount, argumentTypesOfCorrectLength, 0, parameterCount);
    verifyNotListOrMap(argumentTypesOfCorrectLength);
    return ParameterInfo.fromTypes(argumentTypesOfCorrectLength);
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) StepdefBody(cucumber.api.java8.StepdefBody)

Example 7 with ParameterizedType

use of java.lang.reflect.ParameterizedType in project che by eclipse.

the class EventService method getEventType.

private Class<?> getEventType(EventSubscriber<?> subscriber) {
    Class<?> eventType = null;
    Class<?> clazz = subscriber.getClass();
    while (clazz != null && eventType == null) {
        for (Type type : clazz.getGenericInterfaces()) {
            if (type instanceof ParameterizedType) {
                final ParameterizedType parameterizedType = (ParameterizedType) type;
                final Type rawType = parameterizedType.getRawType();
                if (EventSubscriber.class == rawType) {
                    final Type[] typeArguments = parameterizedType.getActualTypeArguments();
                    if (typeArguments.length == 1) {
                        if (typeArguments[0] instanceof Class) {
                            eventType = (Class) typeArguments[0];
                        }
                    }
                }
            }
        }
        clazz = clazz.getSuperclass();
    }
    if (eventType == null) {
        throw new IllegalArgumentException(String.format("Unable determine type of events processed by %s", subscriber));
    }
    return eventType;
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type)

Example 8 with ParameterizedType

use of java.lang.reflect.ParameterizedType 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 9 with ParameterizedType

use of java.lang.reflect.ParameterizedType in project druid by druid-io.

the class JsonConfigProvider method bindInstance.

@SuppressWarnings("unchecked")
public static <T> void bindInstance(Binder binder, Key<T> bindKey, T instance) {
    binder.bind(bindKey).toInstance(instance);
    final ParameterizedType supType = Types.newParameterizedType(Supplier.class, bindKey.getTypeLiteral().getType());
    final Key supplierKey;
    if (bindKey.getAnnotationType() != null) {
        supplierKey = Key.get(supType, bindKey.getAnnotationType());
    } else if (bindKey.getAnnotation() != null) {
        supplierKey = Key.get(supType, bindKey.getAnnotation());
    } else {
        supplierKey = Key.get(supType);
    }
    binder.bind(supplierKey).toInstance(Suppliers.<T>ofInstance(instance));
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) Key(com.google.inject.Key)

Example 10 with ParameterizedType

use of java.lang.reflect.ParameterizedType in project dropwizard by dropwizard.

the class OptionalMessageBodyWriter method writeTo.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void writeTo(Optional<?> entity, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException {
    if (!entity.isPresent()) {
        throw EmptyOptionalException.INSTANCE;
    }
    final ParameterizedType actualGenericType = (ParameterizedType) genericType;
    final Type actualGenericTypeArgument = actualGenericType.getActualTypeArguments()[0];
    final MessageBodyWriter writer = mbw.get().getMessageBodyWriter(entity.get().getClass(), actualGenericTypeArgument, annotations, mediaType);
    writer.writeTo(entity.get(), entity.get().getClass(), actualGenericTypeArgument, annotations, mediaType, httpHeaders, entityStream);
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) MediaType(javax.ws.rs.core.MediaType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) MessageBodyWriter(javax.ws.rs.ext.MessageBodyWriter)

Aggregations

ParameterizedType (java.lang.reflect.ParameterizedType)605 Type (java.lang.reflect.Type)456 GenericArrayType (java.lang.reflect.GenericArrayType)203 WildcardType (java.lang.reflect.WildcardType)162 TypeVariable (java.lang.reflect.TypeVariable)126 ArrayList (java.util.ArrayList)79 Method (java.lang.reflect.Method)60 Test (org.junit.Test)55 List (java.util.List)45 Field (java.lang.reflect.Field)43 Map (java.util.Map)39 HashMap (java.util.HashMap)32 Collection (java.util.Collection)18 Annotation (java.lang.annotation.Annotation)13 ImmutableList (com.google.common.collect.ImmutableList)12 TypeLiteral (com.google.inject.TypeLiteral)12 HashSet (java.util.HashSet)11 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)10 GenericType (javax.ws.rs.core.GenericType)10 MediaType (javax.ws.rs.core.MediaType)10