-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Simplify name and alias annotation processing #3877
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Hi @jvz, Don't worry, I have seen your PR, but until the end of the week I don't really have the time to review it. |
I'm trying to get the build to work 😆 |
The MacOS failure is due to a problem in the Maven Wrapper script. |
Now it seems there's a Windows-specific build issue related to TLS settings. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jvz, +93/-615 LoC is impressive! 💯 I've some questions that I will appreciate it if you can help with.
/** | ||
* Marks another annotation as one providing a name for an object. The name is obtained from | ||
* the annotation element named {@code value}. This element can be a {@code String} or {@code String[]}. | ||
* When specified as an array, the first element is used. | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Marks another annotation as one providing a name for an object.
Oookay... PluginElement
, PluginValue
, etc. are NameProvider
s. Got it.
The name is obtained from the annotation element named
value
.
This element can be aString
orString[]
.
When specified as an array, the first element is used.
I am totally lost here. Would you mind elaborating on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can try. The idea here is that an annotation like @Named(String[] value)
can specify both the name (the first element of the array) and additional aliases (the rest of the array). However, some annotations like @PluginAliases(String[] value)
use the whole array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right! Got it!
/** | |
* Marks another annotation as one providing a name for an object. The name is obtained from | |
* the annotation element named {@code value}. This element can be a {@code String} or {@code String[]}. | |
* When specified as an array, the first element is used. | |
*/ | |
/** | |
* Marks another annotation as one providing a name for an object. | |
* The name is obtained from the annotation element named {@code value}. | |
* This element can be a {@code String} or {@code String[]}. | |
* When specified as an array, the first element is used. | |
* <h2>Examples:</h2> | |
* <ul> | |
* <li>{@code @NameProvider @Named(String value)} - {@code value} will be used as the name | |
* <li>{@code @NameProvider @PluginAliases(String[] value)} - {@code value[0]} will be used as the name | |
* </ul> | |
*/ |
@NameProvider(NamedQualifierNameProvider.class) | ||
@AliasesProvider(NamedQualifierNameProvider.class) | ||
@NameProvider | ||
@AliasesProvider(offset = 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused by offset
and its function. (Yes, I've read its Javadoc.) Would you mind explaining it a little bit more, please?
@@ -23,7 +23,7 @@ | |||
import java.lang.annotation.Target; | |||
|
|||
/** | |||
* Annotations to separate {@link org.apache.logging.log4j.plugins.name.NameProvider} names into namespaces. | |||
* Annotations to separate {@link NameProvider} names into namespaces. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does "NameProvider
names" mean? "Names provided by NameProvider
s"?
* For example, the {@linkplain Configurable Core namespace} is used with the {@link Node} API, while the TypeConverter | ||
* namespace is used with the {@link org.apache.logging.log4j.plugins.convert.TypeConverter} API. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this example needs to be explained more.
@@ -53,7 +53,7 @@ Injection points are injectable fields or parameters where a dependency should b | |||
_Injectable fields_ are fields annotated with `@Inject` or a qualifier annotation. | |||
_Injectable methods_ are methods annotated with `@Inject` or are not annotated with a factory annotation and have at least one parameter annotated with a qualifier annotation. | |||
_Injectable constructors_ are constructors annotated with `@Inject`; only one such constructor should exist per class. | |||
When a field or parameter is annotated with a name-providing annotation (i.e., an annotation annotated with `@org.apache.logging.log4j.plugins.name.NameProvider`), then the provided name or name of the field or parameter are included in the `Key<T>` for the injection point. | |||
When a field or parameter is annotated with a name-providing annotation (i.e., an annotation annotated with `@org.apache.logging.log4j.plugins.NameProvider`), then the provided name or name of the field or parameter are included in the `Key<T>` for the injection point. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a field or parameter is annotated with a name-providing annotation (i.e., an annotation annotated with `@org.apache.logging.log4j.plugins.NameProvider`), then the provided name or name of the field or parameter are included in the `Key<T>` for the injection point. | |
When a field or parameter is annotated with `@NameProvider`, then the provided name or name of the field or parameter are included in the `Key<T>` for the injection point. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... Lastly, no-arg methods annotated with
@Inject
are invoked which can be useful for post-injection initialization logic. Additional strategies for resolving factories for unbound keys may be registered which are consulted first before falling back to this@Inject
reflection logic.
Do we have a use case for every single logic described above? For instance, I was not able to find a single usage of @Inject
on a no-arg method. In a follow-up PR, can we remove and all other functionalities that do not (yet) serve a purpose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's there for a sort of @PostConstruct
type of thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but without any usage. I am not keen on growing the public API, knowing that not even ourselves using it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't "grow" the public API; it has been in the plugin DI system for multiple 3.0.0 releases already. If you're suggesting we can review old code that's already in main
, then I don't see the point of reviewing PRs since it could be reviewed directly from main
as demonstrated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not suggesting to address this (or any other remark of mine applying to old text) in this PR. I will create a separate issue for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as bundles which are instances or injectable
Class<T>
instances that contain one or more annotated factory methods.
"Bundle" is a very convoluted term in the Java ecosystem. Above statement literally describes a "factory collection/set", which we can consider replacing bundle
with as a more self-explanatory term.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I called it "module" before as the concept is borrowed from Guice, but that gets confusing with Java modules. They're similar to spring @Configuration
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll leave the decision to you. You can resolve this conversation as you wish.
This fixes #3870