square/dagger — pull request #27 by cgruber (2012-09-18 06:43:18+00:00)
Title: Add support for bindings of `@Provides @Element Foo provideFoo() {...}`

This change provides "Set bindings". This pull request is mostly for comment. I need to flesh out the tests, and make sure we're covering some important cases, and that the behaviour is documented in the README.

Current functionality (with spaces to avoid tagging people on github)

```java
@Module public class MyModule {
@Provides @Element String provideString1() { return "String1"; }
@Provides @Element String provideString2() { return "String2"; }
}
```

will allow someone to do
```
...
@ Inject Set strings;
...
```

Each item is bound when the Set is bound, and elements within can be singleton, or one-per-injection, depending on whether the `@Provides @Element` method is singleton or not. It's a bit of a straw man and we want to do the same for `@MapEntry(key="foo")` or some such also.

This change should also allow for

```java
@Module public class MyModule {
@Provides @Element String provideString1() { return "String1"; }
@Provides @Element String provideString2() { return "String2"; }
@Provides @Element @MyQualifier String provideString3() { return "String3"; }
@Provides @Element @MyQualifier String provideString4() { return "String4"; }
}
```

to create two Set bindings - one keyed `"java.util.Set"` and one keyed as `"@com.foo.MyQualifier/java.util.Set"`, each containing two elements.

Examples of usage:
* plugin architectures riding on top of a managed object space
* command-line flag bindings systems
* No-op broadcast/listen functionality with extra modules providing extension.