Search in sources :

Example 1 with NewLiteral

use of org.jboss.weld.literal.NewLiteral in project core by weld.

the class ResolvableBuilder method addQualifier.

private ResolvableBuilder addQualifier(Annotation qualifier, InjectionPoint injectionPoint) {
    QualifierInstance qualifierInstance = QualifierInstance.of(qualifier, store);
    final Class<? extends Annotation> annotationType = qualifierInstance.getAnnotationClass();
    // Handle the @New qualifier special case
    if (annotationType.equals(New.class)) {
        New newQualifier = New.class.cast(qualifier);
        if (newQualifier.value().equals(New.class) && rawType == null) {
            throw new IllegalStateException("Cannot transform @New when there is no known raw type");
        } else if (newQualifier.value().equals(New.class)) {
            qualifier = new NewLiteral(rawType);
            qualifierInstance = QualifierInstance.of(qualifier, store);
        }
    } else if (injectionPoint != null && annotationType.equals(Named.class)) {
        Named named = (Named) qualifier;
        if (named.value().equals("")) {
            // WELD-1739
            // This is an injection point with an @Named qualifier, with no value specified, we need to assume the name of the field or parameter is the
            // value
            Member member = injectionPoint.getMember();
            if (member instanceof Executable) {
                // Method or constructor injection
                Executable executable = (Executable) member;
                AnnotatedParameter<?> annotatedParameter = (AnnotatedParameter<?>) injectionPoint.getAnnotated();
                Parameter parameter = executable.getParameters()[annotatedParameter.getPosition()];
                named = new NamedLiteral(parameter.getName());
            } else {
                named = new NamedLiteral(injectionPoint.getMember().getName());
            }
            qualifier = named;
            qualifierInstance = QualifierInstance.of(named, store);
        }
    }
    checkQualifier(qualifier, qualifierInstance, annotationType);
    this.qualifierInstances.add(qualifierInstance);
    return this;
}
Also used : New(javax.enterprise.inject.New) Named(javax.inject.Named) AnnotatedParameter(javax.enterprise.inject.spi.AnnotatedParameter) Parameter(java.lang.reflect.Parameter) AnnotatedParameter(javax.enterprise.inject.spi.AnnotatedParameter) NewLiteral(org.jboss.weld.literal.NewLiteral) Executable(java.lang.reflect.Executable) Member(java.lang.reflect.Member) NamedLiteral(org.jboss.weld.literal.NamedLiteral)

Aggregations

Executable (java.lang.reflect.Executable)1 Member (java.lang.reflect.Member)1 Parameter (java.lang.reflect.Parameter)1 New (javax.enterprise.inject.New)1 AnnotatedParameter (javax.enterprise.inject.spi.AnnotatedParameter)1 Named (javax.inject.Named)1 NamedLiteral (org.jboss.weld.literal.NamedLiteral)1 NewLiteral (org.jboss.weld.literal.NewLiteral)1