javax.enterprise.inject.spi.AnnotatedField Java Examples

The following examples show how to use javax.enterprise.inject.spi.AnnotatedField. 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: ImmutableInjectionPoint.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
/**
 * Instantiate a new {@link InjectionPoint} based upon an
 * {@link AnnotatedField}, reading the qualifiers from the annotations
 * declared on the field.
 *
 * @param field         the field 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(AnnotatedField<?> field, BeanManager beanManager, Bean<?> declaringBean,
                               boolean isTransient, boolean delegate)
{
    annotated = field;
    member = field.getJavaMember();
    qualifiers = BeanUtils.getQualifiers(beanManager, field.getAnnotations());
    type = field.getJavaMember().getGenericType();
    this.isTransient = isTransient;
    this.delegate = delegate;
    this.declaringBean = declaringBean;
}
 
Example #2
Source File: ImmutableInjectionPoint.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
/**
 * Instantiate a new {@link InjectionPoint} based upon an
 * {@link AnnotatedField}.
 *
 * @param field         the field 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(AnnotatedField<?> field, Set<Annotation> qualifiers, Bean<?> declaringBean,
                               boolean isTransient, boolean delegate)
{
    annotated = field;
    member = field.getJavaMember();
    this.qualifiers = new HashSet<Annotation>(qualifiers);
    type = field.getJavaMember().getGenericType();
    this.isTransient = isTransient;
    this.delegate = delegate;
    this.declaringBean = declaringBean;
}
 
Example #3
Source File: Annotateds.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
public int compare(AnnotatedField<? super T> arg0, AnnotatedField<? super T> arg1)
{
    if (arg0.getJavaMember().getName().equals(arg1.getJavaMember().getName()))
    {
        return arg0.getJavaMember().getDeclaringClass().getName().compareTo(arg1.getJavaMember()
                .getDeclaringClass().getName());
    }
    return arg0.getJavaMember().getName().compareTo(arg1.getJavaMember().getName());
}
 
Example #4
Source File: TransientReferenceDestroyedTest.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Dependent
@Produces
Beer newBeer(InjectionPoint injectionPoint) {
    int id;
    if (injectionPoint.getAnnotated() instanceof AnnotatedField) {
        id = 0;
    } else {
        id = COUNTER.incrementAndGet();
    }
    return new Beer(id);
}
 
Example #5
Source File: DefaultMockFilter.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
protected boolean isMockSupportEnabled(Annotated annotated)
{
    if ((annotated instanceof AnnotatedMethod || annotated instanceof AnnotatedField) &&
            annotated.getAnnotation(Produces.class) != null)
    {
        return TestBaseConfig.MockIntegration.ALLOW_MOCKED_PRODUCERS;
    }
    else
    {
        return TestBaseConfig.MockIntegration.ALLOW_MOCKED_BEANS;
    }
}
 
Example #6
Source File: ConfigurableExtension.java    From thorntail with Apache License 2.0 5 votes vote down vote up
private static <T> boolean isApplicable(AnnotatedType<T> at) {
    if (isApplicable(at.getJavaClass())) {
        return true;
    }

    Set<AnnotatedField<? super T>> fields = at.getFields();

    for (AnnotatedField<? super T> field : fields) {
        if (field.isAnnotationPresent(Configurable.class)) {
            return true;
        }
    }

    return false;
}
 
Example #7
Source File: InjectionHelper.java    From BeanTest with Apache License 2.0 5 votes vote down vote up
/**
 * Adds the {@link Inject} annotation to the fields and setters of the annotated type if required.
 *
 * @param <X>
 *            the type of the annotated type
 * @param annotatedType
 *            the annotated type whose fields and setters the inject annotation should be added to
 * @param builder
 *            the builder that should be used to add the annotation.
 * @see #shouldInjectionAnnotationBeAddedToMember(AnnotatedMember)
 */
public static <X> void addInjectAnnotation(final AnnotatedType<X> annotatedType, AnnotatedTypeBuilder<X> builder) {
    for (AnnotatedField<? super X> field : annotatedType.getFields()) {
        if (shouldInjectionAnnotationBeAddedToMember(field)) {
            builder.addToField(field, AnnotationInstances.INJECT);
        }
    }
    for (AnnotatedMethod<? super X> method : annotatedType.getMethods()) {
        if (shouldInjectionAnnotationBeAddedToMember(method)) {
            builder.addToMethod(method,  AnnotationInstances.INJECT);
        }
    }
}
 
Example #8
Source File: DelegateContextAnnotatedType.java    From cxf with Apache License 2.0 5 votes vote down vote up
private AnnotatedField<? super X> wrap(AnnotatedField<? super X> af) {
    if (af.isAnnotationPresent(Context.class)) {
        return new DelegateAnnotatedField<>(af);
    } else {
        return af;
    }
}
 
Example #9
Source File: DelegateContextAnnotatedType.java    From cxf with Apache License 2.0 4 votes vote down vote up
private Set<AnnotatedField<? super X>> replaceFields(AnnotatedType<? super X> delegate) {
    return delegate.getFields().stream().map(this::wrap).collect(toSet());
}
 
Example #10
Source File: AnnotatedTypeImpl.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Set<AnnotatedField<? super X>> getFields()
{
    return Collections.unmodifiableSet(fields);
}
 
Example #11
Source File: Annotateds.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
/**
 * Generates a unique signature for a concrete class. Annotations are not
 * read directly from the class, but are read from the
 * <code>annotations</code>, <code>methods</code>, <code>fields</code> and
 * <code>constructors</code> arguments
 *
 * @param clazz        The java class type
 * @param annotations  Annotations present on the java class
 * @param methods      The AnnotatedMethods to include in the signature
 * @param fields       The AnnotatedFields to include in the signature
 * @param constructors The AnnotatedConstructors to include in the signature
 * @return A string representation of the type
 */
public static <X> String createTypeId(Class<X> clazz, Collection<Annotation> annotations,
                                      Collection<AnnotatedMethod<? super X>> methods,
                                      Collection<AnnotatedField<? super X>> fields,
                                      Collection<AnnotatedConstructor<X>> constructors)
{
    StringBuilder builder = new StringBuilder();

    builder.append(clazz.getName());
    builder.append(createAnnotationCollectionId(annotations));
    builder.append("{");

    // now deal with the fields
    List<AnnotatedField<? super X>> sortedFields = new ArrayList<AnnotatedField<? super X>>();
    sortedFields.addAll(fields);
    Collections.sort(sortedFields, AnnotatedFieldComparator.<X>instance());
    for (AnnotatedField<? super X> field : sortedFields)
    {
        if (!field.getAnnotations().isEmpty())
        {
            builder.append(createFieldId(field));
            builder.append(SEPARATOR);
        }
    }

    // methods
    List<AnnotatedMethod<? super X>> sortedMethods = new ArrayList<AnnotatedMethod<? super X>>();
    sortedMethods.addAll(methods);
    Collections.sort(sortedMethods, AnnotatedMethodComparator.<X>instance());
    for (AnnotatedMethod<? super X> method : sortedMethods)
    {
        if (!method.getAnnotations().isEmpty() || hasMethodParameters(method))
        {
            builder.append(createCallableId(method));
            builder.append(SEPARATOR);
        }
    }

    // constructors
    List<AnnotatedConstructor<? super X>> sortedConstructors = new ArrayList<AnnotatedConstructor<? super X>>();
    sortedConstructors.addAll(constructors);
    Collections.sort(sortedConstructors, AnnotatedConstructorComparator.<X>instance());
    for (AnnotatedConstructor<? super X> constructor : sortedConstructors)
    {
        if (!constructor.getAnnotations().isEmpty() || hasMethodParameters(constructor))
        {
            builder.append(createCallableId(constructor));
            builder.append(SEPARATOR);
        }
    }
    builder.append("}");

    return builder.toString();
}
 
Example #12
Source File: Annotateds.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
public static <T> Comparator<AnnotatedField<? super T>> instance()
{
    return new AnnotatedFieldComparator<T>();
}
 
Example #13
Source File: AnnotatedTypeDecorator.java    From metrics-cdi with Apache License 2.0 4 votes vote down vote up
@Override
public Set<AnnotatedField<? super X>> getFields() {
    return decoratedType.getFields();
}
 
Example #14
Source File: DelegateContextAnnotatedType.java    From cxf with Apache License 2.0 4 votes vote down vote up
private DelegateAnnotatedField(AnnotatedField<Y> delegate) {
    this.original = delegate;
    this.annotationSet = processAnnotations(delegate.getAnnotations());
}
 
Example #15
Source File: DelegateContextAnnotatedType.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Override
public Set<AnnotatedField<? super X>> getFields() {
    return replacedFields;
}
 
Example #16
Source File: FaultToleranceExtension.java    From smallrye-fault-tolerance with Apache License 2.0 4 votes vote down vote up
public Set<AnnotatedField<? super T>> getFields() {
    return delegate.getFields();
}
 
Example #17
Source File: CurrentInjectionPointProvider.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
public Set<AnnotatedField<? super X>> getFields() {
    throw new UnsupportedOperationException();
}
 
Example #18
Source File: AnnotatedTypeDecorator.java    From smallrye-metrics with Apache License 2.0 4 votes vote down vote up
@Override
public Set<AnnotatedField<? super X>> getFields() {
    return decoratedType.getFields();
}
 
Example #19
Source File: SmallRyeMetricsLogging.java    From smallrye-metrics with Apache License 2.0 4 votes vote down vote up
@LogMessage(level = Logger.Level.DEBUG)
@Message(id = 1100, value = "Metric producer field discovered: %s")
void producerFieldDiscovered(AnnotatedField<?> field);
 
Example #20
Source File: AnnotatedTypeWrapper.java    From krazo with Apache License 2.0 4 votes vote down vote up
@Override
public Set<AnnotatedField<? super T>> getFields() {
    return wrapped.getFields();
}
 
Example #21
Source File: PortletSessionScopedAnnotatedType.java    From portals-pluto with Apache License 2.0 4 votes vote down vote up
@Override
public Set<AnnotatedField<? super SessionScoped>> getFields() {
   return aType.getFields();
}
 
Example #22
Source File: BeanManagerImpl.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
public <X> ProducerFactory<X> getProducerFactory(AnnotatedField<? super X> field, Bean<X> declaringBean) {
    throw new UnsupportedOperationException();
}
 
Example #23
Source File: BeanManagerImpl.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
public InjectionPoint createInjectionPoint(AnnotatedField<?> field) {
    throw new UnsupportedOperationException();
}
 
Example #24
Source File: AnnotatedTypeWrapper.java    From ozark with Apache License 2.0 4 votes vote down vote up
@Override
public Set<AnnotatedField<? super T>> getFields() {
    return wrapped.getFields();
}
 
Example #25
Source File: AutoJpaAnnotationType.java    From openwebbeans-meecrowave with Apache License 2.0 4 votes vote down vote up
@Override
public Set<AnnotatedField<? super T>> getFields() {
    return delegate.getFields();
}
 
Example #26
Source File: ModifiedField.java    From portals-pluto with Apache License 2.0 4 votes vote down vote up
public ModifiedField(AnnotatedField<X> annotatedField, Set<Annotation> annotations) {
	this.annotatedField = annotatedField;
	this.annotations = annotations;
}
 
Example #27
Source File: ModifiedAnnotatedType.java    From portals-pluto with Apache License 2.0 4 votes vote down vote up
public ModifiedAnnotatedType(AnnotatedType<X> annotatedType, Set<AnnotatedField<? super X>> fields,
	Set<AnnotatedMethod<? super X>> methods) {
	this.annotatedType = annotatedType;
	this.fields = fields;
	this.methods = methods;
}
 
Example #28
Source File: ModifiedAnnotatedType.java    From portals-pluto with Apache License 2.0 4 votes vote down vote up
@Override
public Set<AnnotatedField<? super X>> getFields() {
	return fields;
}
 
Example #29
Source File: PortletRequestScopedAnnotatedType.java    From portals-pluto with Apache License 2.0 4 votes vote down vote up
@Override
public Set<AnnotatedField<? super RequestScoped>> getFields() {
   return aType.getFields();
}
 
Example #30
Source File: Annotateds.java    From deltaspike with Apache License 2.0 3 votes vote down vote up
/**
 * <p>
 * Compares {@link AnnotatedField}s for equality.
 * </p>
 * <p>
 * Two {@link AnnotatedField}s are considered equal if they have the same
 * underlying field and annotations.
 * </p>
 */
public static boolean compareAnnotatedField(AnnotatedField<?> f1, AnnotatedField<?> f2)
{
    if (!f1.getJavaMember().equals(f2.getJavaMember()))
    {
        return false;
    }
    return compareAnnotated(f1, f2);
}