Java Code Examples for javax.enterprise.inject.spi.AnnotatedParameter#isAnnotationPresent()

The following examples show how to use javax.enterprise.inject.spi.AnnotatedParameter#isAnnotationPresent() . 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: HandlerMethodImpl.java    From deltaspike with Apache License 2.0 6 votes vote down vote up
/**
 * Determines if the given method is a handler by looking for the {@link Handles} annotation on a parameter.
 *
 * @param method method to search
 * @return true if {@link Handles} is found, false otherwise
 */
public static boolean isHandler(final AnnotatedMethod<?> method)
{
    if (method == null)
    {
        throw new IllegalArgumentException("Method must not be null");
    }

    for (AnnotatedParameter<?> param : method.getParameters())
    {
        if (param.isAnnotationPresent(Handles.class) || param.isAnnotationPresent(BeforeHandles.class))
        {
            return true;
        }
    }

    return false;
}
 
Example 2
Source File: HandlerMethodImpl.java    From deltaspike with Apache License 2.0 6 votes vote down vote up
public static AnnotatedParameter<?> findHandlerParameter(final AnnotatedMethod<?> method)
{
    if (!isHandler(method))
    {
        throw new IllegalArgumentException("Method is not a valid handler");
    }

    AnnotatedParameter<?> returnParam = null;

    for (AnnotatedParameter<?> param : method.getParameters())
    {
        if (param.isAnnotationPresent(Handles.class) || param.isAnnotationPresent(BeforeHandles.class))
        {
            returnParam = param;
            break;
        }
    }

    return returnParam;
}
 
Example 3
Source File: SeMetricName.java    From smallrye-metrics with Apache License 2.0 5 votes vote down vote up
private String of(AnnotatedParameter<?> parameter) {
    if (parameter.isAnnotationPresent(Metric.class)) {
        Metric metric = parameter.getAnnotation(Metric.class);
        String name = (metric.name().isEmpty()) ? getParameterName(parameter) : of(metric.name());
        return metric.absolute() | parameters.contains(MetricsParameter.useAbsoluteName) ? name
                : MetricRegistry.name(parameter.getDeclaringCallable().getJavaMember().getDeclaringClass(), name);
    } else {
        return parameters.contains(MetricsParameter.useAbsoluteName) ? getParameterName(parameter)
                : MetricRegistry.name(parameter.getDeclaringCallable().getJavaMember().getDeclaringClass(),
                        getParameterName(parameter));
    }
}
 
Example 4
Source File: RouteExtension.java    From weld-vertx with Apache License 2.0 5 votes vote down vote up
private boolean hasEventParameter(AnnotatedMethod<?> annotatedMethod) {
    for (AnnotatedParameter<?> param : annotatedMethod.getParameters()) {
        if (param.isAnnotationPresent(Observes.class)) {
            return true;
        }
    }
    return false;
}
 
Example 5
Source File: SeMetricName.java    From metrics-cdi with Apache License 2.0 5 votes vote down vote up
private String of(AnnotatedParameter<?> parameter) {
    if (parameter.isAnnotationPresent(Metric.class)) {
        Metric metric = parameter.getAnnotation(Metric.class);
        String name = metric.name().isEmpty() ? getParameterName(parameter) : of(metric.name());
        return metric.absolute() | extension.<Boolean>getParameter(UseAbsoluteName).orElse(false) ? name : MetricRegistry.name(parameter.getDeclaringCallable().getJavaMember().getDeclaringClass(), name);
    } else {
        return extension.<Boolean>getParameter(UseAbsoluteName).orElse(false) ? getParameterName(parameter) : MetricRegistry.name(parameter.getDeclaringCallable().getJavaMember().getDeclaringClass(), getParameterName(parameter));
    }
}