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);
}
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;
}
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();
}
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));
}
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);
}
Aggregations