Search in sources :

Example 71 with ParameterizedType

use of java.lang.reflect.ParameterizedType in project flink by apache.

the class ReflectionUtil method getTemplateTypes.

public static Class<?>[] getTemplateTypes(ParameterizedType paramterizedType) {
    Class<?>[] types = new Class<?>[paramterizedType.getActualTypeArguments().length];
    int i = 0;
    for (Type templateArgument : paramterizedType.getActualTypeArguments()) {
        assert templateArgument instanceof Class<?>;
        types[i++] = (Class<?>) templateArgument;
    }
    return types;
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type)

Example 72 with ParameterizedType

use of java.lang.reflect.ParameterizedType in project flink by apache.

the class ReflectionUtil method getTemplateTypes.

public static Class<?>[] getTemplateTypes(Class<?> clazz) {
    Type type = clazz.getGenericSuperclass();
    assert (type instanceof ParameterizedType);
    ParameterizedType paramterizedType = (ParameterizedType) type;
    Class<?>[] types = new Class<?>[paramterizedType.getActualTypeArguments().length];
    int i = 0;
    for (Type templateArgument : paramterizedType.getActualTypeArguments()) {
        assert (templateArgument instanceof Class<?>);
        types[i++] = (Class<?>) templateArgument;
    }
    return types;
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type)

Example 73 with ParameterizedType

use of java.lang.reflect.ParameterizedType in project flink by apache.

the class ReflectionUtil method getFullTemplateType.

/**
	 * Extract the full type information from the given type.
	 *
	 * @param type to be analyzed
	 * @return Full type information describing the given type
	 */
public static FullTypeInfo getFullTemplateType(Type type) {
    if (type instanceof ParameterizedType) {
        ParameterizedType parameterizedType = (ParameterizedType) type;
        FullTypeInfo[] templateTypeInfos = new FullTypeInfo[parameterizedType.getActualTypeArguments().length];
        for (int i = 0; i < parameterizedType.getActualTypeArguments().length; i++) {
            templateTypeInfos[i] = getFullTemplateType(parameterizedType.getActualTypeArguments()[i]);
        }
        return new FullTypeInfo((Class<?>) parameterizedType.getRawType(), templateTypeInfos);
    } else {
        return new FullTypeInfo((Class<?>) type, null);
    }
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType)

Example 74 with ParameterizedType

use of java.lang.reflect.ParameterizedType in project camel by apache.

the class CdiCamelExtension method beans.

private void beans(@Observes ProcessBean<?> pb, BeanManager manager) {
    cdiBeans.add(pb.getBean());
    // Lookup for CDI event endpoint injection points
    pb.getBean().getInjectionPoints().stream().filter(ip -> CdiEventEndpoint.class.equals(getRawType(ip.getType()))).forEach(ip -> {
        Type type = ip.getType() instanceof ParameterizedType ? ((ParameterizedType) ip.getType()).getActualTypeArguments()[0] : Object.class;
        String uri = eventEndpointUri(type, ip.getQualifiers());
        cdiEventEndpoints.put(uri, new CdiEventEndpoint<>(uri, type, ip.getQualifiers(), manager));
    });
}
Also used : CdiSpiHelper.isAnnotationType(org.apache.camel.cdi.CdiSpiHelper.isAnnotationType) Produces(javax.enterprise.inject.Produces) AfterBeanDiscovery(javax.enterprise.inject.spi.AfterBeanDiscovery) LoggerFactory(org.slf4j.LoggerFactory) ProcessBean(javax.enterprise.inject.spi.ProcessBean) Endpoint(org.apache.camel.Endpoint) PropertyInject(org.apache.camel.PropertyInject) EventObject(java.util.EventObject) ProcessProducerField(javax.enterprise.inject.spi.ProcessProducerField) ProcessObserverMethod(javax.enterprise.inject.spi.ProcessObserverMethod) Map(java.util.Map) Observes(javax.enterprise.event.Observes) ProducerTemplate(org.apache.camel.ProducerTemplate) ANY(org.apache.camel.cdi.AnyLiteral.ANY) Method(java.lang.reflect.Method) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Collectors.toSet(java.util.stream.Collectors.toSet) CamelContextAware(org.apache.camel.CamelContextAware) Annotated(javax.enterprise.inject.spi.Annotated) Extension(javax.enterprise.inject.spi.Extension) CdiSpiHelper.hasType(org.apache.camel.cdi.CdiSpiHelper.hasType) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ProcessAnnotatedType(javax.enterprise.inject.spi.ProcessAnnotatedType) BeanManagerHelper.getReference(org.apache.camel.cdi.BeanManagerHelper.getReference) Set(java.util.Set) ResourceHelper.getResource(org.apache.camel.cdi.ResourceHelper.getResource) CdiSpiHelper.getRawType(org.apache.camel.cdi.CdiSpiHelper.getRawType) ProcessProducerMethod(javax.enterprise.inject.spi.ProcessProducerMethod) BeanInject(org.apache.camel.BeanInject) Stream(java.util.stream.Stream) Type(java.lang.reflect.Type) CdiEventEndpoint.eventEndpointUri(org.apache.camel.cdi.CdiEventEndpoint.eventEndpointUri) Annotation(java.lang.annotation.Annotation) ConsumerTemplate(org.apache.camel.ConsumerTemplate) EXCLUDED(org.apache.camel.cdi.Excluded.EXCLUDED) Bean(javax.enterprise.inject.spi.Bean) RoutesBuilder(org.apache.camel.RoutesBuilder) EndpointInject(org.apache.camel.EndpointInject) Component(org.apache.camel.Component) AbstractExchangeEvent(org.apache.camel.management.event.AbstractExchangeEvent) Collectors.collectingAndThen(java.util.stream.Collectors.collectingAndThen) AnnotatedType(javax.enterprise.inject.spi.AnnotatedType) Produce(org.apache.camel.Produce) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ProcessProducer(javax.enterprise.inject.spi.ProcessProducer) Collections.newSetFromMap(java.util.Collections.newSetFromMap) APPLICATION_SCOPED(org.apache.camel.cdi.ApplicationScopedLiteral.APPLICATION_SCOPED) BeanManagerHelper.getReferencesByType(org.apache.camel.cdi.BeanManagerHelper.getReferencesByType) FluentProducerTemplate(org.apache.camel.FluentProducerTemplate) AfterDeploymentValidation(javax.enterprise.inject.spi.AfterDeploymentValidation) Stream.concat(java.util.stream.Stream.concat) Named(javax.inject.Named) DEFAULT(org.apache.camel.cdi.DefaultLiteral.DEFAULT) ServiceStatus(org.apache.camel.ServiceStatus) CamelContext(org.apache.camel.CamelContext) Default(javax.enterprise.inject.Default) Logger(org.slf4j.Logger) CdiSpiHelper.getQualifiers(org.apache.camel.cdi.CdiSpiHelper.getQualifiers) Consume(org.apache.camel.Consume) Predicate.isEqual(java.util.function.Predicate.isEqual) STARTUP(org.apache.camel.cdi.Startup.Literal.STARTUP) InjectionException(javax.enterprise.inject.InjectionException) Converter(org.apache.camel.Converter) ProcessInjectionTarget(javax.enterprise.inject.spi.ProcessInjectionTarget) TypeConverter(org.apache.camel.TypeConverter) ParameterizedType(java.lang.reflect.ParameterizedType) RouteContainer(org.apache.camel.model.RouteContainer) CdiSpiHelper.hasAnnotation(org.apache.camel.cdi.CdiSpiHelper.hasAnnotation) InjectionPoint(javax.enterprise.inject.spi.InjectionPoint) BeanManager(javax.enterprise.inject.spi.BeanManager) ParameterizedType(java.lang.reflect.ParameterizedType) CdiSpiHelper.isAnnotationType(org.apache.camel.cdi.CdiSpiHelper.isAnnotationType) CdiSpiHelper.hasType(org.apache.camel.cdi.CdiSpiHelper.hasType) ProcessAnnotatedType(javax.enterprise.inject.spi.ProcessAnnotatedType) CdiSpiHelper.getRawType(org.apache.camel.cdi.CdiSpiHelper.getRawType) Type(java.lang.reflect.Type) AnnotatedType(javax.enterprise.inject.spi.AnnotatedType) BeanManagerHelper.getReferencesByType(org.apache.camel.cdi.BeanManagerHelper.getReferencesByType) ParameterizedType(java.lang.reflect.ParameterizedType)

Example 75 with ParameterizedType

use of java.lang.reflect.ParameterizedType in project Genius-Android by qiujuer.

the class Reflector method getClass.

/**
     * Get the underlying class for a type, or null if the type is a variable
     * type.
     *
     * @param type the type
     * @return the underlying class
     */
public static Class<?> getClass(Type type) {
    if (type instanceof Class) {
        return (Class) type;
    } else if (type instanceof ParameterizedType) {
        return getClass(((ParameterizedType) type).getRawType());
    } else if (type instanceof GenericArrayType) {
        Type componentType = ((GenericArrayType) type).getGenericComponentType();
        Class<?> componentClass = getClass(componentType);
        if (componentClass != null) {
            return Array.newInstance(componentClass, 0).getClass();
        } else {
            return null;
        }
    } else {
        return null;
    }
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) GenericArrayType(java.lang.reflect.GenericArrayType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) GenericArrayType(java.lang.reflect.GenericArrayType)

Aggregations

ParameterizedType (java.lang.reflect.ParameterizedType)704 Type (java.lang.reflect.Type)532 GenericArrayType (java.lang.reflect.GenericArrayType)226 WildcardType (java.lang.reflect.WildcardType)182 TypeVariable (java.lang.reflect.TypeVariable)137 ArrayList (java.util.ArrayList)94 Method (java.lang.reflect.Method)71 Test (org.junit.Test)59 List (java.util.List)55 Field (java.lang.reflect.Field)49 Map (java.util.Map)47 HashMap (java.util.HashMap)42 Collection (java.util.Collection)26 MediaType (javax.ws.rs.core.MediaType)23 Annotation (java.lang.annotation.Annotation)18 HashSet (java.util.HashSet)13 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)13 ImmutableList (com.google.common.collect.ImmutableList)12 TypeLiteral (com.google.inject.TypeLiteral)12 IOException (java.io.IOException)11