javax.enterprise.inject.spi.AnnotatedParameter Java Examples
The following examples show how to use
javax.enterprise.inject.spi.AnnotatedParameter.
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 |
/** * Obtain all the injection points for the handler * * @param bm a BeanManager to use to obtain the beans */ public Set<InjectionPoint> getInjectionPoints(final BeanManager bm) { if (injectionPoints == null) { injectionPoints = new HashSet<InjectionPoint>(handler.getParameters().size() - 1); for (AnnotatedParameter<?> param : handler.getParameters()) { if (!param.equals(handlerParameter)) { injectionPoints.add( new ImmutableInjectionPoint(param, bm, getDeclaringBean(), false, false)); } } } return new HashSet<InjectionPoint>(injectionPoints); }
Example #2
Source File: Annotateds.java From deltaspike with Apache License 2.0 | 6 votes |
/** * Generates a unique string representation of a list of * {@link AnnotatedParameter}s. */ public static <X> String createParameterListId(List<AnnotatedParameter<X>> parameters) { StringBuilder builder = new StringBuilder(); builder.append("("); for (int i = 0; i < parameters.size(); ++i) { AnnotatedParameter<X> ap = parameters.get(i); builder.append(createParameterId(ap)); if (i + 1 != parameters.size()) { builder.append(','); } } builder.append(")"); return builder.toString(); }
Example #3
Source File: Annotateds.java From deltaspike with Apache License 2.0 | 6 votes |
/** * Compares two annotated elements to see if they have the same annotations */ private static boolean compareAnnotatedParameters(List<? extends AnnotatedParameter<?>> p1, List<? extends AnnotatedParameter<?>> p2) { if (p1.size() != p2.size()) { return false; } for (int i = 0; i < p1.size(); ++i) { if (!compareAnnotated(p1.get(i), p2.get(i))) { return false; } } return true; }
Example #4
Source File: AnnotatedTypeBuilder.java From deltaspike with Apache License 2.0 | 6 votes |
/** * Remove an annotation from the specified parameter. * * @param parameter the parameter to remove the annotation from * @param annotationType the annotation type to remove * @throws IllegalArgumentException if the annotationType is null, if the * callable which declares the parameter is not currently declared * on the type or if the parameter is not declared on either a * constructor or a method */ public AnnotatedTypeBuilder<X> removeFromParameter(AnnotatedParameter<? super X> parameter, Class<? extends Annotation> annotationType) { if (parameter.getDeclaringCallable().getJavaMember() instanceof Method) { Method method = (Method) parameter.getDeclaringCallable().getJavaMember(); return removeFromMethodParameter(method, parameter.getPosition(), annotationType); } if (parameter.getDeclaringCallable().getJavaMember() instanceof Constructor<?>) { @SuppressWarnings("unchecked") Constructor<X> constructor = (Constructor<X>) parameter.getDeclaringCallable().getJavaMember(); return removeFromConstructorParameter(constructor, parameter.getPosition(), annotationType); } else { throw new IllegalArgumentException("Cannot remove from parameter " + parameter + " - cannot operate on member " + parameter.getDeclaringCallable().getJavaMember()); } }
Example #5
Source File: AnnotatedTypeBuilder.java From deltaspike with Apache License 2.0 | 6 votes |
/** * Add an annotation to the specified parameter. If the callable which * declares the parameter is not already present, it will be added. If the * parameter is not already present on the callable, it will be added. * * @param parameter the parameter to add the annotation to * @param annotation the annotation to add * @throws IllegalArgumentException if the annotation is null or if the * parameter is not declared on either a constructor or a method */ public AnnotatedTypeBuilder<X> addToParameter(AnnotatedParameter<? super X> parameter, Annotation annotation) { if (parameter.getDeclaringCallable().getJavaMember() instanceof Method) { Method method = (Method) parameter.getDeclaringCallable().getJavaMember(); return addToMethodParameter(method, parameter.getPosition(), annotation); } if (parameter.getDeclaringCallable().getJavaMember() instanceof Constructor<?>) { @SuppressWarnings("unchecked") Constructor<X> constructor = (Constructor<X>) parameter.getDeclaringCallable().getJavaMember(); return addToConstructorParameter(constructor, parameter.getPosition(), annotation); } else { throw new IllegalArgumentException("Cannot remove from parameter " + parameter + " - cannot operate on member " + parameter.getDeclaringCallable().getJavaMember()); } }
Example #6
Source File: AnnotatedTypeBuilder.java From deltaspike with Apache License 2.0 | 6 votes |
/** * Override the declared type of a parameter. * * @param parameter the parameter to override the type on * @param type the new type of the parameter * @throws IllegalArgumentException if parameter or type is null */ public AnnotatedTypeBuilder<X> overrideParameterType(AnnotatedParameter<? super X> parameter, Type type) { if (parameter.getDeclaringCallable().getJavaMember() instanceof Method) { Method method = (Method) parameter.getDeclaringCallable().getJavaMember(); return overrideMethodParameterType(method, parameter.getPosition(), type); } if (parameter.getDeclaringCallable().getJavaMember() instanceof Constructor<?>) { @SuppressWarnings("unchecked") Constructor<X> constructor = (Constructor<X>) parameter.getDeclaringCallable().getJavaMember(); return overrideConstructorParameterType(constructor, parameter.getPosition(), type); } else { throw new IllegalArgumentException("Cannot remove from parameter " + parameter + " - cannot operate on member " + parameter.getDeclaringCallable().getJavaMember()); } }
Example #7
Source File: MailTemplateProducer.java From quarkus with Apache License 2.0 | 6 votes |
@Produces MailTemplate getDefault(InjectionPoint injectionPoint) { final String name; if (injectionPoint.getMember() instanceof Field) { // For "@Inject MailTemplate test" use "test" name = injectionPoint.getMember().getName(); } else { AnnotatedParameter<?> parameter = (AnnotatedParameter<?>) injectionPoint.getAnnotated(); if (parameter.getJavaParameter().isNamePresent()) { name = parameter.getJavaParameter().getName(); } else { name = injectionPoint.getMember().getName(); LOGGER.warnf("Parameter name not present - using the method name as the template name instead %s", name); } } return new MailTemplate() { @Override public MailTemplateInstance instance() { return new MailTemplateInstanceImpl(mailer, template.select(new ResourcePath.Literal(name)).get().instance()); } }; }
Example #8
Source File: TemplateProducer.java From quarkus with Apache License 2.0 | 6 votes |
@Produces Template getDefaultTemplate(InjectionPoint injectionPoint) { String name = null; if (injectionPoint.getMember() instanceof Field) { // For "@Inject Template items" use "items" name = injectionPoint.getMember().getName(); } else { AnnotatedParameter<?> parameter = (AnnotatedParameter<?>) injectionPoint.getAnnotated(); if (parameter.getJavaParameter().isNamePresent()) { name = parameter.getJavaParameter().getName(); } else { name = injectionPoint.getMember().getName(); LOGGER.warnf("Parameter name not present - using the method name as the template name instead %s", name); } } return new InjectableTemplate(name, templateVariants, engine); }
Example #9
Source File: InjectionPointMetadataTest.java From quarkus with Apache License 2.0 | 6 votes |
@SuppressWarnings({ "unchecked", "serial" }) @Test public void testObserverInjectionPointMetadata() { AtomicReference<InjectionPoint> ip = new AtomicReference<>(); Arc.container().beanManager().getEvent().select(new TypeLiteral<AtomicReference<InjectionPoint>>() { }).fire(ip); InjectionPoint injectionPoint = ip.get(); assertNotNull(injectionPoint); assertEquals(Controlled.class, injectionPoint.getType()); Set<Annotation> qualifiers = injectionPoint.getQualifiers(); assertEquals(1, qualifiers.size()); assertEquals(Default.class, qualifiers.iterator().next().annotationType()); Assertions.assertNull(injectionPoint.getBean()); assertNotNull(injectionPoint.getAnnotated()); assertTrue(injectionPoint.getAnnotated() instanceof AnnotatedParameter); AnnotatedParameter<Controller> annotatedParam = (AnnotatedParameter<Controller>) injectionPoint.getAnnotated(); assertEquals(Controlled.class, annotatedParam.getBaseType()); assertEquals(1, annotatedParam.getAnnotations().size()); assertFalse(annotatedParam.isAnnotationPresent(Inject.class)); assertTrue(annotatedParam.isAnnotationPresent(FooAnnotation.class)); assertTrue(annotatedParam.getAnnotation(Singleton.class) == null); assertTrue(annotatedParam.getAnnotations(Singleton.class).isEmpty()); }
Example #10
Source File: AnnotatedTypeBuilderTest.java From deltaspike with Apache License 2.0 | 6 votes |
@Test public void modifyAnnotationsOnConstructorParameter() throws NoSuchMethodException { final AnnotatedTypeBuilder<Cat> builder = new AnnotatedTypeBuilder<Cat>(); builder.readFromType(Cat.class, true); builder.removeFromConstructorParameter(Cat.class.getConstructor(String.class, String.class), 1, Default.class); builder.addToConstructorParameter(Cat.class.getConstructor(String.class, String.class), 1, new AnyLiteral()); final AnnotatedType<Cat> catAnnotatedType = builder.create(); Set<AnnotatedConstructor<Cat>> catCtors = catAnnotatedType.getConstructors(); assertThat(catCtors.size(), is(2)); for (AnnotatedConstructor<Cat> ctor : catCtors) { if (ctor.getParameters().size() == 2) { List<AnnotatedParameter<Cat>> ctorParams = ctor.getParameters(); assertThat(ctorParams.get(1).getAnnotations().size(), is(1)); assertThat((AnyLiteral) ctorParams.get(1).getAnnotations().toArray()[0], is(new AnyLiteral())); } } }
Example #11
Source File: HandlerMethodImpl.java From deltaspike with Apache License 2.0 | 6 votes |
/** * 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 #12
Source File: HandlerMethodImpl.java From deltaspike with Apache License 2.0 | 6 votes |
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 #13
Source File: ImmutableInjectionPoint.java From deltaspike with Apache License 2.0 | 5 votes |
/** * Instantiate a new {@link InjectionPoint} based upon an * {@link AnnotatedParameter}. * * @param parameter the parameter for which to create the injection point * @param qualifiers the qualifiers on the injection point * @param declaringBean the declaringBean declaring the injection point * @param isTransient <code>true</code> if the injection point is transient * @param delegate <code>true</code> if the injection point is a delegate * injection point on a decorator */ public ImmutableInjectionPoint(AnnotatedParameter<?> parameter, Set<Annotation> qualifiers, Bean<?> declaringBean, boolean isTransient, boolean delegate) { annotated = parameter; member = parameter.getDeclaringCallable().getJavaMember(); this.qualifiers = new HashSet<Annotation>(qualifiers); this.isTransient = isTransient; this.delegate = delegate; this.declaringBean = declaringBean; type = parameter.getBaseType(); }
Example #14
Source File: ImmutableInjectionPoint.java From deltaspike with Apache License 2.0 | 5 votes |
/** * Instantiate a new {@link InjectionPoint} based upon an * {@link AnnotatedParameter}, reading the qualifiers from the annotations * declared on the parameter. * * @param parameter the parameter for which to create the injection point * @param declaringBean the declaringBean declaring the injection point * @param isTransient <code>true</code> if the injection point is transient * @param delegate <code>true</code> if the injection point is a delegate * injection point on a decorator */ public ImmutableInjectionPoint(AnnotatedParameter<?> parameter, BeanManager beanManager, Bean<?> declaringBean, boolean isTransient, boolean delegate) { annotated = parameter; member = parameter.getDeclaringCallable().getJavaMember(); qualifiers = BeanUtils.getQualifiers(beanManager, parameter.getAnnotations()); this.isTransient = isTransient; this.delegate = delegate; this.declaringBean = declaringBean; type = parameter.getBaseType(); }
Example #15
Source File: AnnotatedCallableImpl.java From deltaspike with Apache License 2.0 | 5 votes |
private static <X, Y extends Member> List<AnnotatedParameter<X>> getAnnotatedParameters( AnnotatedCallableImpl<X, Y> callable, Class<?>[] parameterTypes, Type[] genericTypes, Map<Integer, AnnotationStore> parameterAnnotations, Map<Integer, Type> parameterTypeOverrides) { List<AnnotatedParameter<X>> parameters = new ArrayList<AnnotatedParameter<X>>(); int len = parameterTypes.length; for (int i = 0; i < len; ++i) { AnnotationBuilder builder = new AnnotationBuilder(); if (parameterAnnotations != null && parameterAnnotations.containsKey(i)) { builder.addAll(parameterAnnotations.get(i)); } Type over = null; if (parameterTypeOverrides != null) { over = parameterTypeOverrides.get(i); } AnnotatedParameterImpl<X> p = new AnnotatedParameterImpl<X>( callable, parameterTypes[i], i, builder.create(), genericTypes[i], over); parameters.add(p); } return parameters; }
Example #16
Source File: BeanUtils.java From deltaspike with Apache License 2.0 | 5 votes |
/** * Given a method, and the bean on which the method is declared, create a * collection of injection points representing the parameters of the method. * * @param <X> the type declaring the method * @param method the method * @param declaringBean the bean on which the method is declared * @param beanManager the bean manager to use to create the injection points * @return the injection points */ public static <X> List<InjectionPoint> createInjectionPoints(AnnotatedMethod<X> method, Bean<?> declaringBean, BeanManager beanManager) { List<InjectionPoint> injectionPoints = new ArrayList<InjectionPoint>(); for (AnnotatedParameter<X> parameter : method.getParameters()) { InjectionPoint injectionPoint = new ImmutableInjectionPoint(parameter, beanManager, declaringBean, false, false); injectionPoints.add(injectionPoint); } return injectionPoints; }
Example #17
Source File: Annotateds.java From deltaspike with Apache License 2.0 | 5 votes |
private static <X> boolean hasMethodParameters(AnnotatedCallable<X> callable) { for (AnnotatedParameter<X> parameter : callable.getParameters()) { if (!parameter.getAnnotations().isEmpty()) { return true; } } return false; }
Example #18
Source File: SeMetricName.java From metrics-cdi with Apache License 2.0 | 5 votes |
private String getParameterName(AnnotatedParameter<?> parameter) { Parameter[] parameters = ((Method) parameter.getDeclaringCallable().getJavaMember()).getParameters(); Parameter param = parameters[parameter.getPosition()]; if (param.isNamePresent()) { return param.getName(); } else { throw new UnsupportedOperationException("Unable to retrieve name for parameter [" + parameter + "], activate the -parameters compiler argument or annotate the injected parameter with the @Metric annotation"); } }
Example #19
Source File: Annotateds.java From deltaspike with Apache License 2.0 | 5 votes |
/** * Creates a deterministic signature for a {@link Constructor}. * * @param constructor The constructor to generate the signature for * @param annotations The annotations to include in the signature * @param parameters The {@link AnnotatedParameter}s to include in the * signature */ public static <X> String createConstructorId(Constructor<X> constructor, Set<Annotation> annotations, List<AnnotatedParameter<X>> parameters) { StringBuilder builder = new StringBuilder(); builder.append(constructor.getDeclaringClass().getName()); builder.append('.'); builder.append(constructor.getName()); builder.append(createAnnotationCollectionId(annotations)); builder.append(createParameterListId(parameters)); return builder.toString(); }
Example #20
Source File: Annotateds.java From deltaspike with Apache License 2.0 | 5 votes |
/** * Creates a deterministic signature for a {@link Method}. * * @param method The method to generate the signature for * @param annotations The annotations to include in the signature * @param parameters The {@link AnnotatedParameter}s to include in the * signature */ public static <X> String createMethodId(Method method, Set<Annotation> annotations, List<AnnotatedParameter<X>> parameters) { StringBuilder builder = new StringBuilder(); builder.append(method.getDeclaringClass().getName()); builder.append('.'); builder.append(method.getName()); builder.append(createAnnotationCollectionId(annotations)); builder.append(createParameterListId(parameters)); return builder.toString(); }
Example #21
Source File: SeMetricName.java From metrics-cdi with Apache License 2.0 | 5 votes |
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)); } }
Example #22
Source File: SeMetricName.java From smallrye-metrics with Apache License 2.0 | 5 votes |
@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 #23
Source File: SeMetricName.java From smallrye-metrics with Apache License 2.0 | 5 votes |
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 #24
Source File: SeMetricName.java From smallrye-metrics with Apache License 2.0 | 5 votes |
private String getParameterName(AnnotatedParameter<?> parameter) { try { Method method = Method.class.getMethod("getParameters"); Object[] parameters = (Object[]) method.invoke(parameter.getDeclaringCallable().getJavaMember()); Object param = parameters[parameter.getPosition()]; Class<?> Parameter = Class.forName("java.lang.reflect.Parameter"); if ((Boolean) Parameter.getMethod("isNamePresent").invoke(param)) { return (String) Parameter.getMethod("getName").invoke(param); } else { throw SmallRyeMetricsMessages.msg.unableToRetrieveParameterName(parameter); } } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | ClassNotFoundException cause) { throw SmallRyeMetricsMessages.msg.unableToRetrieveParameterName(parameter); } }
Example #25
Source File: MockResourceInjectionServices.java From weld-junit with Apache License 2.0 | 5 votes |
private Resource getResourceAnnotation(InjectionPoint injectionPoint) { Annotated annotated = injectionPoint.getAnnotated(); if (annotated instanceof AnnotatedParameter<?>) { annotated = ((AnnotatedParameter<?>) annotated).getDeclaringCallable(); } return annotated.getAnnotation(Resource.class); }
Example #26
Source File: RouteExtension.java From weld-vertx with Apache License 2.0 | 5 votes |
private boolean hasEventParameter(AnnotatedMethod<?> annotatedMethod) { for (AnnotatedParameter<?> param : annotatedMethod.getParameters()) { if (param.isAnnotationPresent(Observes.class)) { return true; } } return false; }
Example #27
Source File: CdiHelper.java From metrics-cdi with Apache License 2.0 | 5 votes |
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 #28
Source File: SeMetricName.java From metrics-cdi with Apache License 2.0 | 5 votes |
@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 #29
Source File: MetricCdiInjectionExtension.java From smallrye-metrics with Apache License 2.0 | 5 votes |
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 #30
Source File: ModifiedMethod.java From portals-pluto with Apache License 2.0 | 4 votes |
@Override public List<AnnotatedParameter<X>> getParameters() { return annotatedMethod.getParameters(); }