You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shindig.apache.org by Henning Schmiedehausen <he...@schmiedehausen.org> on 2010/05/26 18:51:53 UTC
Keeping track of the @Named annotations
Hi,
while working on our headless implementation of the RESTy part of
Opensocial, it took me quite some time to find all the @Named
annotations that I have to supply information for. I was wondering if
we could benefit from replacing all the
@Named("shindig.something.or.other") with constants. @ $WORKPLACE we
use something like this:
public abstract class NamedConstants
{
private NamedConstants() {
}
public static final String REQUIRED_CONSTANT_NAME = "required.constant";
public static final Named REQUIRED_CONSTANT_NAMED =
Names.named(REQUIRED_CONSTANT_NAME);
}
and in the code you would use
bind(Foo.class).annotatedWith(NamedConstants.REQUIRED_CONSTANT_NAMED).to(FooImpl.class);
and
public Baz(@Named(NamedConstants.REQUIRED.CONSTANT.NAME) Foo foo) { ... }
The advantage is that it is possible to figure out which constants are
in use in the code base, and (by adding meaningful comments to the
class above :-) ) figure out what they do. Also, the compiler will
catch possible typos in @Named and annotatedWith usage.
The process of putting this in is pretty much mechanical but some
work. I can do that if no one objects strongly.
-h
Re: Keeping track of the @Named annotations
Posted by Henning Schmiedehausen <he...@schmiedehausen.org>.
Yes, this is correct. The vote is IMHO still out whether using @Named
and Strings or specific annotations are the better way to use; at
$DAYJOB, engineering is almost evenly split. I would feel
uncomfortable about the huge number of classes required but it
certainly is an option to do it this way.
-h
On Wed, May 26, 2010 at 11:08, Brian Eaton <be...@google.com> wrote:
> Guice binding annotations are another good option for some use cases:
>
> @Retention(RetentionPolicy.RUNTIME)
> @BindingAnnotation
> public @interface SomeNewAnnotation {}
>
> Then later:
>
> @SomeNewAnnotation String foo;
>
> Cheers,
> Brian
> On Wed, May 26, 2010 at 11:00 AM, John Hjelmstad <fa...@google.com> wrote:
>> Seems like a reasonable idea to me.
>>
>> On Wed, May 26, 2010 at 9:51 AM, Henning Schmiedehausen <
>> henning@schmiedehausen.org> wrote:
>>
>>> Hi,
>>>
>>> while working on our headless implementation of the RESTy part of
>>> Opensocial, it took me quite some time to find all the @Named
>>> annotations that I have to supply information for. I was wondering if
>>> we could benefit from replacing all the
>>> @Named("shindig.something.or.other") with constants. @ $WORKPLACE we
>>> use something like this:
>>>
>>>
>>> public abstract class NamedConstants
>>> {
>>> private NamedConstants() {
>>> }
>>>
>>> public static final String REQUIRED_CONSTANT_NAME = "required.constant";
>>> public static final Named REQUIRED_CONSTANT_NAMED =
>>> Names.named(REQUIRED_CONSTANT_NAME);
>>>
>>> }
>>>
>>> and in the code you would use
>>>
>>>
>>> bind(Foo.class).annotatedWith(NamedConstants.REQUIRED_CONSTANT_NAMED).to(FooImpl.class);
>>>
>>> and
>>>
>>> public Baz(@Named(NamedConstants.REQUIRED.CONSTANT.NAME) Foo foo) {
>>> ... }
>>>
>>> The advantage is that it is possible to figure out which constants are
>>> in use in the code base, and (by adding meaningful comments to the
>>> class above :-) ) figure out what they do. Also, the compiler will
>>> catch possible typos in @Named and annotatedWith usage.
>>>
>>> The process of putting this in is pretty much mechanical but some
>>> work. I can do that if no one objects strongly.
>>>
>>> -h
>>>
>>
>
Re: Keeping track of the @Named annotations
Posted by Brian Eaton <be...@google.com>.
Guice binding annotations are another good option for some use cases:
@Retention(RetentionPolicy.RUNTIME)
@BindingAnnotation
public @interface SomeNewAnnotation {}
Then later:
@SomeNewAnnotation String foo;
Cheers,
Brian
On Wed, May 26, 2010 at 11:00 AM, John Hjelmstad <fa...@google.com> wrote:
> Seems like a reasonable idea to me.
>
> On Wed, May 26, 2010 at 9:51 AM, Henning Schmiedehausen <
> henning@schmiedehausen.org> wrote:
>
>> Hi,
>>
>> while working on our headless implementation of the RESTy part of
>> Opensocial, it took me quite some time to find all the @Named
>> annotations that I have to supply information for. I was wondering if
>> we could benefit from replacing all the
>> @Named("shindig.something.or.other") with constants. @ $WORKPLACE we
>> use something like this:
>>
>>
>> public abstract class NamedConstants
>> {
>> private NamedConstants() {
>> }
>>
>> public static final String REQUIRED_CONSTANT_NAME = "required.constant";
>> public static final Named REQUIRED_CONSTANT_NAMED =
>> Names.named(REQUIRED_CONSTANT_NAME);
>>
>> }
>>
>> and in the code you would use
>>
>>
>> bind(Foo.class).annotatedWith(NamedConstants.REQUIRED_CONSTANT_NAMED).to(FooImpl.class);
>>
>> and
>>
>> public Baz(@Named(NamedConstants.REQUIRED.CONSTANT.NAME) Foo foo) {
>> ... }
>>
>> The advantage is that it is possible to figure out which constants are
>> in use in the code base, and (by adding meaningful comments to the
>> class above :-) ) figure out what they do. Also, the compiler will
>> catch possible typos in @Named and annotatedWith usage.
>>
>> The process of putting this in is pretty much mechanical but some
>> work. I can do that if no one objects strongly.
>>
>> -h
>>
>
Re: Keeping track of the @Named annotations
Posted by John Hjelmstad <fa...@google.com>.
Seems like a reasonable idea to me.
On Wed, May 26, 2010 at 9:51 AM, Henning Schmiedehausen <
henning@schmiedehausen.org> wrote:
> Hi,
>
> while working on our headless implementation of the RESTy part of
> Opensocial, it took me quite some time to find all the @Named
> annotations that I have to supply information for. I was wondering if
> we could benefit from replacing all the
> @Named("shindig.something.or.other") with constants. @ $WORKPLACE we
> use something like this:
>
>
> public abstract class NamedConstants
> {
> private NamedConstants() {
> }
>
> public static final String REQUIRED_CONSTANT_NAME = "required.constant";
> public static final Named REQUIRED_CONSTANT_NAMED =
> Names.named(REQUIRED_CONSTANT_NAME);
>
> }
>
> and in the code you would use
>
>
> bind(Foo.class).annotatedWith(NamedConstants.REQUIRED_CONSTANT_NAMED).to(FooImpl.class);
>
> and
>
> public Baz(@Named(NamedConstants.REQUIRED.CONSTANT.NAME) Foo foo) {
> ... }
>
> The advantage is that it is possible to figure out which constants are
> in use in the code base, and (by adding meaningful comments to the
> class above :-) ) figure out what they do. Also, the compiler will
> catch possible typos in @Named and annotatedWith usage.
>
> The process of putting this in is pretty much mechanical but some
> work. I can do that if no one objects strongly.
>
> -h
>