From f56077a1717795617ba3eec38a43558652d6e596 Mon Sep 17 00:00:00 2001 From: Ladislav Thon Date: Mon, 29 Nov 2021 10:13:33 +0100 Subject: [PATCH 1/3] Allow @Enhancement to not restrict the types based on annotations In case an unannotated type is added through `@Discovery`, such type previously couldn't be transformed during `@Enhancement`. With this commit, it is possible to specify that the set of types considered for `@Enhancement` is not restricted based on annotations in any way. To do that, the `@Enhancement#withAnnotations` member should be set to an empty array. --- .../build/compatible/spi/Enhancement.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/api/src/main/java/jakarta/enterprise/inject/build/compatible/spi/Enhancement.java b/api/src/main/java/jakarta/enterprise/inject/build/compatible/spi/Enhancement.java index d49064e2..47eaaef9 100644 --- a/api/src/main/java/jakarta/enterprise/inject/build/compatible/spi/Enhancement.java +++ b/api/src/main/java/jakarta/enterprise/inject/build/compatible/spi/Enhancement.java @@ -72,20 +72,24 @@ * parameter of any member of the type, or as a meta-annotation on any annotation * that is considered by these rules. *

- * Defaults to the {@linkplain BeanDefiningAnnotations set of bean defining annotations}. + * If empty, the set of expected types is not narrowed down in any way. + * If {@code java.lang.Annotation} is present, the set of expected types + * is narrowed down to types that use any annotation. + * The {@link BeanDefiningAnnotations @BeanDefiningAnnotations} marker type may + * be used to narrow down the set of expected types to types that use + * any bean defining annotation. *

- * If empty, or if {@code java.lang.Annotation} is present, all annotations are used. - * That is, the set of expected types is narrowed down to the set of types - * that use any annotation. + * Defaults to the {@linkplain BeanDefiningAnnotations set of bean defining annotations}. * * @return types of annotations that must be present on the expected types */ Class[] withAnnotations() default BeanDefiningAnnotations.class; /** - * Marker annotation type that represents set of bean defining annotations after - * the {@link Discovery @Discovery} phase is finished. That is, it includes custom - * normal scope annotations as well as custom stereotypes. + * Marker annotation type that, for the purpose of {@link Enhancement#withAnnotations()}, + * represents set of bean defining annotations after the {@link Discovery @Discovery} + * phase is finished. That is, it includes custom normal scope annotations as well as + * custom stereotypes. */ @interface BeanDefiningAnnotations { } From a63aa70ea9eb801bd6ccbfb425a26354abbef39c Mon Sep 17 00:00:00 2001 From: Ladislav Thon Date: Mon, 29 Nov 2021 10:17:16 +0100 Subject: [PATCH 2/3] Change @Enhancement#withAnnotations default value to empty array Previously, the default value of `@Enhancement#withAnnotations` was the `BeanDefiningAnnotations.class` marker type. To align with Portable Extensions, which don't have any annotation restriction by default, this commit changes the default value to an empty array. --- .../enterprise/inject/build/compatible/spi/Enhancement.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/jakarta/enterprise/inject/build/compatible/spi/Enhancement.java b/api/src/main/java/jakarta/enterprise/inject/build/compatible/spi/Enhancement.java index 47eaaef9..86ef3575 100644 --- a/api/src/main/java/jakarta/enterprise/inject/build/compatible/spi/Enhancement.java +++ b/api/src/main/java/jakarta/enterprise/inject/build/compatible/spi/Enhancement.java @@ -79,11 +79,12 @@ * be used to narrow down the set of expected types to types that use * any bean defining annotation. *

- * Defaults to the {@linkplain BeanDefiningAnnotations set of bean defining annotations}. + * Defaults to an empty array, so that the set of expected types is not + * narrowed down in any way. * * @return types of annotations that must be present on the expected types */ - Class[] withAnnotations() default BeanDefiningAnnotations.class; + Class[] withAnnotations() default {}; /** * Marker annotation type that, for the purpose of {@link Enhancement#withAnnotations()}, From 560f83235b5adf4ef2a3e48d125121c7f23918c2 Mon Sep 17 00:00:00 2001 From: Ladislav Thon Date: Mon, 29 Nov 2021 10:53:41 +0100 Subject: [PATCH 3/3] Clarify how @Discovery and @Enhancement participate in type discovery The terms "type discovery" and "bean discovery" are sometimes used interchangeably, though they really shouldn't. This commit improves the usage of these terms in `@Discovery` and `@Enhancement`. In particular, the `@Enhancement` wording is changed to refer to "type discovery" instead of "bean discovery", because bean discovery happens _after_ `@Enhancement`. --- .../enterprise/inject/build/compatible/spi/Discovery.java | 2 +- .../inject/build/compatible/spi/Enhancement.java | 2 +- .../inject/build/compatible/spi/ScannedClasses.java | 8 +++++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/api/src/main/java/jakarta/enterprise/inject/build/compatible/spi/Discovery.java b/api/src/main/java/jakarta/enterprise/inject/build/compatible/spi/Discovery.java index 1be79120..076d41a8 100644 --- a/api/src/main/java/jakarta/enterprise/inject/build/compatible/spi/Discovery.java +++ b/api/src/main/java/jakarta/enterprise/inject/build/compatible/spi/Discovery.java @@ -7,7 +7,7 @@ /** * 1st phase of {@linkplain BuildCompatibleExtension build compatible extension} execution. - * Allow registering additional classes to be scanned during bean discovery. + * Allow adding additional classes to the set of types discovered during type discovery. * Also allows registering custom CDI meta-annotations. *

* Methods annotated {@code @Discovery} may declare parameters of these types: diff --git a/api/src/main/java/jakarta/enterprise/inject/build/compatible/spi/Enhancement.java b/api/src/main/java/jakarta/enterprise/inject/build/compatible/spi/Enhancement.java index 86ef3575..d7e6e0e5 100644 --- a/api/src/main/java/jakarta/enterprise/inject/build/compatible/spi/Enhancement.java +++ b/api/src/main/java/jakarta/enterprise/inject/build/compatible/spi/Enhancement.java @@ -13,7 +13,7 @@ * In the following text, the term expected types denotes the set of types defined by * the {@link #types() types}, {@link #withSubtypes() withSubtypes} and {@link #withAnnotations() withAnnotations} * members of the {@code @Enhancement} annotation. The term discovered types denotes - * the subset of expected types that were discovered during bean discovery. + * the subset of expected types that were discovered during type discovery. *

* Methods annotated {@code @Enhancement} must declare exactly one parameter of one of these types: *