javax.enterprise.inject.spi.AnnotatedMember Java Examples

The following examples show how to use javax.enterprise.inject.spi.AnnotatedMember. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MetricCdiInjectionExtension.java    From smallrye-metrics with Apache License 2.0 6 votes vote down vote up
private <X> void findAnnotatedMethods(@Observes ProcessManagedBean<X> bean) {
    Package pack = bean.getBean().getBeanClass().getPackage();
    if (pack != null && pack.equals(GaugeRegistrationInterceptor.class.getPackage())) {
        return;
    }
    ArrayList<AnnotatedMember<?>> list = new ArrayList<>();
    for (AnnotatedMethod<? super X> aMethod : bean.getAnnotatedBeanClass().getMethods()) {
        Method method = aMethod.getJavaMember();
        if (!method.isSynthetic() && !Modifier.isPrivate(method.getModifiers())) {
            list.add(aMethod);
        }
    }
    list.addAll(bean.getAnnotatedBeanClass().getConstructors());
    if (!list.isEmpty()) {
        metricsFromAnnotatedMethods.put(bean.getBean(), list);
    }
}
 
Example #2
Source File: ConfigProducerUtil.java    From smallrye-config with Apache License 2.0 6 votes vote down vote up
static String getConfigKey(InjectionPoint ip, ConfigProperty configProperty) {
    String key = configProperty.name();
    if (!key.trim().isEmpty()) {
        return key;
    }
    if (ip.getAnnotated() instanceof AnnotatedMember) {
        AnnotatedMember<?> member = (AnnotatedMember<?>) ip.getAnnotated();
        AnnotatedType<?> declaringType = member.getDeclaringType();
        if (declaringType != null) {
            String[] parts = declaringType.getJavaClass().getCanonicalName().split("\\.");
            StringBuilder sb = new StringBuilder(parts[0]);
            for (int i = 1; i < parts.length; i++) {
                sb.append(".").append(parts[i]);
            }
            sb.append(".").append(member.getJavaMember().getName());
            return sb.toString();
        }
    }
    throw InjectionMessages.msg.noConfigPropertyDefaultName(ip);
}
 
Example #3
Source File: MetricsExtension.java    From metrics-cdi with Apache License 2.0 6 votes vote down vote up
private void configuration(@Observes AfterDeploymentValidation adv, BeanManager manager) {
    // Fire configuration event
    manager.fireEvent(configuration);
    configuration.unmodifiable();

    // Produce and register custom metrics
    MetricRegistry registry = getReference(manager, MetricRegistry.class);
    MetricName metricName = getReference(manager, MetricName.class);
    for (Map.Entry<Bean<?>, AnnotatedMember<?>> bean : metrics.entrySet()) {
        // TODO: add MetricSet metrics into the metric registry
        if (bean.getKey().getTypes().contains(MetricSet.class)
            // skip non @Default beans
            || !bean.getKey().getQualifiers().contains(DEFAULT)
            // skip producer methods with injection point
            || hasInjectionPoints(bean.getValue()))
            continue;
        registry.register(metricName.of(bean.getValue()), (Metric) getReference(manager, bean.getValue().getBaseType(), bean.getKey()));
    }

    // Let's clear the collected metric producers
    metrics.clear();
}
 
Example #4
Source File: MetricCdiInjectionExtension.java    From smallrye-metrics with Apache License 2.0 5 votes vote down vote up
private static boolean hasInjectionPointMetadata(AnnotatedMember<?> member) {
    if (!(member instanceof AnnotatedMethod)) {
        return false;
    }
    AnnotatedMethod<?> method = (AnnotatedMethod<?>) member;
    for (AnnotatedParameter<?> parameter : method.getParameters()) {
        if (parameter.getBaseType().equals(InjectionPoint.class)) {
            return true;
        }
    }
    return false;
}
 
Example #5
Source File: SeMetricName.java    From smallrye-metrics with Apache License 2.0 5 votes vote down vote up
@Override
public String of(InjectionPoint ip) {
    Annotated annotated = ip.getAnnotated();
    if (annotated instanceof AnnotatedMember) {
        return of((AnnotatedMember<?>) annotated);
    } else if (annotated instanceof AnnotatedParameter) {
        return of((AnnotatedParameter<?>) annotated);
    } else {
        throw SmallRyeMetricsMessages.msg.unableToRetrieveMetricNameForInjectionPoint(ip);
    }
}
 
Example #6
Source File: SeMetricName.java    From smallrye-metrics with Apache License 2.0 5 votes vote down vote up
@Override
public String of(AnnotatedMember<?> member) {
    if (member.isAnnotationPresent(Metric.class)) {
        Metric metric = member.getAnnotation(Metric.class);
        String name = (metric.name().isEmpty()) ? member.getJavaMember().getName() : of(metric.name());
        return metric.absolute() | parameters.contains(MetricsParameter.useAbsoluteName) ? name
                : MetricRegistry.name(member.getJavaMember().getDeclaringClass(), name);
    } else {
        return parameters.contains(MetricsParameter.useAbsoluteName) ? member.getJavaMember().getName()
                : MetricRegistry.name(member.getJavaMember().getDeclaringClass(), member.getJavaMember().getName());
    }
}
 
Example #7
Source File: AxonCdiExtension.java    From cdi with Apache License 2.0 5 votes vote down vote up
/**
 * Scans for a serializer producer.
 *
 * @param processProducer process producer event.
 */
<T> void processSerializerProducer(
        @Observes final ProcessProducer<T, Serializer> processProducer) {
    // TODO Handle multiple serializer definitions of the same type.

    AnnotatedMember<T> annotatedMember = processProducer.getAnnotatedMember();
    Named named = annotatedMember.getAnnotation(Named.class);

    if (named != null) {
        String namedValue = named.value();
        String serializerName = "".equals(namedValue)
                ? annotatedMember.getJavaMember().getName()
                : namedValue;
        switch (serializerName) {
            case "eventSerializer":
                logger.debug("Producer for event serializer found: {}.",
                        processProducer.getProducer());
                eventSerializerProducer = processProducer.getProducer();
                break;
            case "messageSerializer":
                logger.debug("Producer for message serializer found: {}.",
                        processProducer.getProducer());
                messageSerializerProducer = processProducer.getProducer();
                break;
            case "serializer":
                logger.debug("Producer for serializer found: {}.",
                        processProducer.getProducer());
                this.serializerProducer = processProducer.getProducer();
                break;
            default:
                logger.warn("Unknown named serializer configured: " + serializerName);
        }
    } else {
        logger.debug("Producer for serializer found: {}.", processProducer.getProducer());
        this.serializerProducer = processProducer.getProducer();
    }
}
 
Example #8
Source File: CdiUtilities.java    From cdi with Apache License 2.0 5 votes vote down vote up
static String extractBeanName(AnnotatedMember<?> annotatedMember) {
    Named named = annotatedMember.getAnnotation(Named.class);

    if (named != null && !"".equals(named.value())) {
        return named.value();
    }

    // TODO: Should not try to derive the name of a member that does not
    // have the @Named annotation on it.
    return annotatedMember.getJavaMember().getName();
}
 
Example #9
Source File: SeMetricName.java    From metrics-cdi with Apache License 2.0 5 votes vote down vote up
@Override
public String of(AnnotatedMember<?> member) {
    if (member.isAnnotationPresent(Metric.class)) {
        Metric metric = member.getAnnotation(Metric.class);
        String name = metric.name().isEmpty() ? member.getJavaMember().getName() : of(metric.name());
        return metric.absolute() | extension.<Boolean>getParameter(UseAbsoluteName).orElse(false) ? name : MetricRegistry.name(member.getJavaMember().getDeclaringClass(), name);
    } else {
        return extension.<Boolean>getParameter(UseAbsoluteName).orElse(false) ? member.getJavaMember().getName() : MetricRegistry.name(member.getJavaMember().getDeclaringClass(), member.getJavaMember().getName());
    }
}
 
Example #10
Source File: SeMetricName.java    From metrics-cdi with Apache License 2.0 5 votes vote down vote up
@Override
public String of(InjectionPoint ip) {
    Annotated annotated = ip.getAnnotated();
    if (annotated instanceof AnnotatedMember)
        return of((AnnotatedMember<?>) annotated);
    else if (annotated instanceof AnnotatedParameter)
        return of((AnnotatedParameter<?>) annotated);
    else
        throw new IllegalArgumentException("Unable to retrieve metric name for injection point [" + ip + "], only members and parameters are supported");
}
 
Example #11
Source File: CdiHelper.java    From metrics-cdi with Apache License 2.0 5 votes vote down vote up
static boolean hasInjectionPoints(AnnotatedMember<?> member) {
    if (!(member instanceof AnnotatedMethod))
        return false;
    AnnotatedMethod<?> method = (AnnotatedMethod<?>) member;
    for (AnnotatedParameter<?> parameter : method.getParameters()) {
        if (parameter.getBaseType().equals(InjectionPoint.class))
            return true;
    }
    return false;
}
 
Example #12
Source File: MockExtension.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
public <X, T> void onProcessProducer(@Observes ProcessProducer<X, T> processProducer, BeanManager beanManager)
{
    if (!isActivated)
    {
        return;
    }

    for (MockFilter mockFilter : mockFilters)
    {
        if (!mockFilter.isMockedImplementationSupported(beanManager, processProducer.getAnnotatedMember()))
        {
            return;
        }
    }

    final Producer<T> originalProducer = processProducer.getProducer();
    AnnotatedMember<X> annotatedMember = processProducer.getAnnotatedMember();
    List<Annotation> qualifiers = new ArrayList<Annotation>();
    for (Annotation annotation : annotatedMember.getAnnotations())
    {
        if (beanManager.isQualifier(annotation.annotationType()))
        {
            qualifiers.add(annotation);
        }
    }

    Typed typed = annotatedMember.getAnnotation(Typed.class);

    List<Type> foundTypes = new ArrayList<Type>();
    if (typed != null)
    {
        Collections.addAll(foundTypes, typed.value());
    }
    else if (annotatedMember.getBaseType() instanceof Class)
    {
        foundTypes.addAll(extractTypes((Class)annotatedMember.getBaseType()));
    }

    if (foundTypes.isEmpty())
    {
        return;
    }

    processProducer.setProducer(new MockAwareProducerWrapper<T>(
        beanManager, originalProducer, foundTypes, qualifiers));
}
 
Example #13
Source File: DefaultMockFilter.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isMockedImplementationSupported(BeanManager beanManager, Annotated annotated)
{
    if (!isMockSupportEnabled(annotated))
    {
        return false;
    }

    Class origin = null;
    if (annotated instanceof AnnotatedType)
    {
        origin = ((AnnotatedType)annotated).getJavaClass();
        Set<Annotation> annotations = new HashSet<Annotation>();
        annotations.addAll(annotated.getAnnotations());

        for (AnnotatedMethod annotatedMethod :
            (Set<javax.enterprise.inject.spi.AnnotatedMethod>)((AnnotatedType) annotated).getMethods())
        {
            annotations.addAll(annotatedMethod.getAnnotations());
        }

        if (isEjbOrAnnotatedTypeWithInterceptorAnnotation(
            beanManager, annotations, origin.getName()))
        {
            return false;
        }
    }
    else if (annotated instanceof AnnotatedMember)
    {
        Member member = ((AnnotatedMember)annotated).getJavaMember();
        origin = member.getDeclaringClass();
        if (isEjbOrAnnotatedTypeWithInterceptorAnnotation(
            beanManager, annotated.getAnnotations(), member.toString()))
        {
            return false;
        }
    }

    if (origin != null && origin.getPackage() == null)
    {
        LOG.warning("Please don't use the default-package for " + origin.getName());
        return true;
    }

    return origin != null && !isInternalPackage(origin.getPackage().getName());
}
 
Example #14
Source File: BeanManagerImpl.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
public BeanAttributes<?> createBeanAttributes(AnnotatedMember<?> type) {
    throw new UnsupportedOperationException();
}
 
Example #15
Source File: InjectionHelper.java    From BeanTest with Apache License 2.0 3 votes vote down vote up
/**
 * Returns <code>true</code> if at least one of the following Java EE annotations is present in the given member:
 * <ul>
 * <li> {@link EJB}
 * <li> {@link PersistenceContext}
 * <li> {@link Resource}
 * </ul>
 * Otherwise, it returns <code>false</code>.
 * @param <X> the type of the annotated member.
 * @param member the member whose annotations should be verified.
 * @return <code>true</code> if the member is at least annotated with one of the following annotations: {@link EJB}, {@link PersistenceContext} or {@link Resource}.
 */
private static <X> boolean hasJavaEEAnnotations(AnnotatedMember<? super X> member) {
     for(Class<? extends Annotation> javaEEannotation : JAVA_EE_ANNOTATIONS) {
         if (member.isAnnotationPresent(javaEEannotation)) {
             return true;
         }
     }
     return false;
}
 
Example #16
Source File: InjectionHelper.java    From BeanTest with Apache License 2.0 2 votes vote down vote up
/**
 * Returns <code>true</code> if the member is NOT annotated with {@link Inject} and is annotated with one of the following annotations:
 * <ul>
 * <li> {@link EJB}
 * <li> {@link PersistenceContext}
 * <li> {@link Resource}
 * </ul>
 * Otherwise, it returns <code>false</code>.
 *
 * @param <X>
 *            the type of the annotated member
 * @param member
 *            the annotated member whose annotations should be verified.
 * @return <code>true</code> if the member is NOT annotated with {@link Inject} and is annotated with {@link EJB},
 *         {@link PersistenceContext} or {@link Resource}
 */
public static <X>  boolean shouldInjectionAnnotationBeAddedToMember(AnnotatedMember<? super X> member) {
    return !member.isAnnotationPresent(Inject.class) && hasJavaEEAnnotations(member);
}
 
Example #17
Source File: MetricName.java    From metrics-cdi with Apache License 2.0 votes vote down vote up
String of(AnnotatedMember<?> member); 
Example #18
Source File: MetricName.java    From smallrye-metrics with Apache License 2.0 votes vote down vote up
String of(AnnotatedMember<?> member);