javax.enterprise.inject.spi.AnnotatedConstructor Java Examples

The following examples show how to use javax.enterprise.inject.spi.AnnotatedConstructor. 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: AnnotatedTypeBuilderTest.java    From deltaspike with Apache License 2.0 6 votes vote down vote up
@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 #2
Source File: Annotateds.java    From deltaspike with Apache License 2.0 6 votes vote down vote up
public int compare(AnnotatedConstructor<? super T> arg0, AnnotatedConstructor<? super T> arg1)
{
    int result = callableComparator.compare(arg0, arg1);
    if (result != 0)
    {
        return result;
    }
    for (int i = 0; i < arg0.getJavaMember().getParameterTypes().length; ++i)
    {
        Class<?> p0 = arg0.getJavaMember().getParameterTypes()[i];
        Class<?> p1 = arg1.getJavaMember().getParameterTypes()[i];
        result = p0.getName().compareTo(p1.getName());
        if (result != 0)
        {
            return result;
        }
    }
    return 0;
}
 
Example #3
Source File: DelegateContextAnnotatedType.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Override
public Set<AnnotatedConstructor<X>> getConstructors() {
    return original.getConstructors();
}
 
Example #4
Source File: AnnotatedTypeImpl.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Set<AnnotatedConstructor<X>> getConstructors()
{
    return Collections.unmodifiableSet(constructors);
}
 
Example #5
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 #6
Source File: Annotateds.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
public static <T> Comparator<AnnotatedConstructor<? super T>> instance()
{
    return new AnnotatedConstructorComparator<T>();
}
 
Example #7
Source File: AnnotatedTypeDecorator.java    From metrics-cdi with Apache License 2.0 4 votes vote down vote up
@Override
public Set<AnnotatedConstructor<X>> getConstructors() {
    return decoratedType.getConstructors();
}
 
Example #8
Source File: FaultToleranceExtension.java    From smallrye-fault-tolerance with Apache License 2.0 4 votes vote down vote up
public Set<AnnotatedConstructor<T>> getConstructors() {
    return delegate.getConstructors();
}
 
Example #9
Source File: PortletSessionScopedAnnotatedType.java    From portals-pluto with Apache License 2.0 4 votes vote down vote up
@Override
public Set<AnnotatedConstructor<SessionScoped>> getConstructors() {
   return aType.getConstructors();
}
 
Example #10
Source File: PortletRequestScopedAnnotatedType.java    From portals-pluto with Apache License 2.0 4 votes vote down vote up
@Override
public Set<AnnotatedConstructor<RequestScoped>> getConstructors() {
   return aType.getConstructors();
}
 
Example #11
Source File: ModifiedAnnotatedType.java    From portals-pluto with Apache License 2.0 4 votes vote down vote up
@Override
public Set<AnnotatedConstructor<X>> getConstructors() {
	return annotatedType.getConstructors();
}
 
Example #12
Source File: AutoJpaAnnotationType.java    From openwebbeans-meecrowave with Apache License 2.0 4 votes vote down vote up
@Override
public Set<AnnotatedConstructor<T>> getConstructors() {
    return delegate.getConstructors();
}
 
Example #13
Source File: AnnotatedTypeWrapper.java    From ozark with Apache License 2.0 4 votes vote down vote up
@Override
public Set<AnnotatedConstructor<T>> getConstructors() {
    return wrapped.getConstructors();
}
 
Example #14
Source File: CurrentInjectionPointProvider.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
public Set<AnnotatedConstructor<X>> getConstructors() {
    throw new UnsupportedOperationException();
}
 
Example #15
Source File: AnnotatedTypeWrapper.java    From krazo with Apache License 2.0 4 votes vote down vote up
@Override
public Set<AnnotatedConstructor<T>> getConstructors() {
    return wrapped.getConstructors();
}
 
Example #16
Source File: AnnotatedTypeDecorator.java    From smallrye-metrics with Apache License 2.0 4 votes vote down vote up
@Override
public Set<AnnotatedConstructor<X>> getConstructors() {
    return decoratedType.getConstructors();
}
 
Example #17
Source File: AnnotatedTypeBuilder.java    From deltaspike with Apache License 2.0 2 votes vote down vote up
/**
 * Add an annotation to the specified constructor. If the constructor is not
 * already present, it will be added.
 *
 * @param constructor the constructor to add the annotation to
 * @param annotation  the annotation to add
 * @throws IllegalArgumentException if the annotation is null
 */
public AnnotatedTypeBuilder<X> addToConstructor(AnnotatedConstructor<X> constructor, Annotation annotation)
{
    return addToConstructor(constructor.getJavaMember(), annotation);
}
 
Example #18
Source File: AnnotatedTypeBuilder.java    From deltaspike with Apache License 2.0 2 votes vote down vote up
/**
 * Remove an annotation from the specified constructor.
 *
 * @param constructor    the constructor to add the annotation to
 * @param annotationType the annotation to add
 * @throws IllegalArgumentException if the annotationType is null, if the
 *                                  annotation does not exist on the type or if the constructor is
 *                                  not currently declared on the type
 */
public AnnotatedTypeBuilder<X> removeFromConstructor(AnnotatedConstructor<X> constructor,
                                                     Class<? extends Annotation> annotationType)
{
    return removeFromConstructor(constructor.getJavaMember(), annotationType);
}