diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/Beans.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/Beans.java index 18d3f6d91e5d01..743d111f5a34a9 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/Beans.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/Beans.java @@ -684,7 +684,7 @@ static boolean hasQualifier(BeanDeployment beanDeployment, AnnotationInstance re ClassInfo requiredClazz = beanDeployment.getQualifier(requiredQualifier.name()); List values = new ArrayList<>(); Set nonBindingFields = beanDeployment.getQualifierNonbindingMembers(requiredQualifier.name()); - for (AnnotationValue val : requiredQualifier.values()) { + for (AnnotationValue val : requiredQualifier.valuesWithDefaults(beanDeployment.getBeanArchiveIndex())) { if (!requiredClazz.method(val.name()).hasAnnotation(DotNames.NONBINDING) && !nonBindingFields.contains(val.name())) { values.add(val); @@ -695,7 +695,7 @@ static boolean hasQualifier(BeanDeployment beanDeployment, AnnotationInstance re // Must have the same annotation member value for each member which is not annotated @Nonbinding boolean matches = true; for (AnnotationValue value : values) { - if (!value.equals(qualifier.value(value.name()))) { + if (!value.equals(qualifier.valueWithDefault(beanDeployment.getBeanArchiveIndex(), value.name()))) { matches = false; break; } diff --git a/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/qualifiers/defaultvalues/Animal.java b/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/qualifiers/defaultvalues/Animal.java new file mode 100644 index 00000000000000..7660c5cb90097e --- /dev/null +++ b/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/qualifiers/defaultvalues/Animal.java @@ -0,0 +1,7 @@ +package io.quarkus.arc.test.qualifiers.defaultvalues; + +public interface Animal { + + int noOfLeg(); + +} diff --git a/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/qualifiers/defaultvalues/AnimalQualifier.java b/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/qualifiers/defaultvalues/AnimalQualifier.java new file mode 100644 index 00000000000000..866d8990c998f4 --- /dev/null +++ b/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/qualifiers/defaultvalues/AnimalQualifier.java @@ -0,0 +1,16 @@ +package io.quarkus.arc.test.qualifiers.defaultvalues; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import javax.inject.Qualifier; + +@Qualifier +@Retention(RetentionPolicy.RUNTIME) +@Target({ ElementType.METHOD, ElementType.FIELD, ElementType.CONSTRUCTOR, ElementType.TYPE }) +public @interface AnimalQualifier { + + String value() default ""; + +} diff --git a/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/qualifiers/defaultvalues/Cat.java b/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/qualifiers/defaultvalues/Cat.java new file mode 100644 index 00000000000000..63365663fd64b4 --- /dev/null +++ b/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/qualifiers/defaultvalues/Cat.java @@ -0,0 +1,14 @@ +package io.quarkus.arc.test.qualifiers.defaultvalues; + +import javax.enterprise.context.Dependent; + +@Dependent +@AnimalQualifier("cat") +public class Cat implements Animal { + + @Override + public int noOfLeg() { + return 4; + } + +} diff --git a/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/qualifiers/defaultvalues/Owl.java b/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/qualifiers/defaultvalues/Owl.java new file mode 100644 index 00000000000000..6bd5819732192f --- /dev/null +++ b/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/qualifiers/defaultvalues/Owl.java @@ -0,0 +1,14 @@ +package io.quarkus.arc.test.qualifiers.defaultvalues; + +import javax.enterprise.context.Dependent; + +@Dependent +@AnimalQualifier +public class Owl implements Animal { + + @Override + public int noOfLeg() { + return 2; + } + +} diff --git a/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/qualifiers/defaultvalues/QualifierDefaultValuesTest.java b/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/qualifiers/defaultvalues/QualifierDefaultValuesTest.java new file mode 100644 index 00000000000000..bcf7cf77d0de35 --- /dev/null +++ b/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/qualifiers/defaultvalues/QualifierDefaultValuesTest.java @@ -0,0 +1,33 @@ +package io.quarkus.arc.test.qualifiers.defaultvalues; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import io.quarkus.arc.Arc; +import io.quarkus.arc.test.ArcTestContainer; +import javax.enterprise.context.Dependent; +import javax.inject.Inject; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +public class QualifierDefaultValuesTest { + + @RegisterExtension + public ArcTestContainer container = new ArcTestContainer(Consumer.class, Animal.class, AnimalQualifier.class, Cat.class, + Owl.class); + + @Test + public void testDefaultValues() { + Consumer consumer = Arc.container().instance(Consumer.class).get(); + assertEquals(2, consumer.animal.noOfLeg()); + } + + @Dependent + public static class Consumer { + + @Inject + @AnimalQualifier + Animal animal; + + } + +}