freefair / spi

Automatically exported from code.google.com/p/spi
0 stars 0 forks source link

Enhancement: Annotate Annotations to create specific service providers. #6

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Imagine I want to create a new annotation.  That annotation that accepts 
additional fields for configuring the service implementation.  My implementing 
classes can of course have my new annotation and the ProviderFor annotation, 
but it's a bit redundant.  

Instead, I want to apply the ProviderFor annotation on my new annotation.  Then 
any class with my new annotation should automatically work as if the 
providerFor annotation were applied.

@ProviderFor(RequestHandler.class)
public @interface CustomAnnotation {
    String name();
    int value();
}

@CustomAnnoation(name="example", value=25)
public class HelloHandler {
...
}

When I do a ServiceLoader.load(RequestHandler.class), HelloHandler should be 
loaded.  I don't need to apply @ProviderFor to it, because I already indicated 
in the CustomAnnotation that any class with that annotation applied is a 
provider for the RequestHandler class.

Obviously you can't automatically add the provider for annotation to the 
implementing class.  Instead I would expect the annotation processor to 
determine that CustomAnnotation had ProviderFor applied.  Then the annotation 
processor would know anything with CustomAnnotation should be operated on as if 
ProviderFor(RequestHandler.class) had been present.

Original issue reported on code.google.com by crodste...@gmail.com on 17 Apr 2013 at 5:21

GoogleCodeExporter commented 8 years ago

Original comment by r.spilker on 18 Apr 2013 at 7:43