Updates:
        Status: Invalid

Comment #1 on issue 638 by sberlin: ProvisionListener doesn't report annotation in dependency chain
http://code.google.com/p/google-guice/issues/detail?id=638

Looked into this a bit.. In the output, none of those [none]'s should be replaced by [@Named("rose")], because those are all outputs for provisioning AnnotationProvisionListenerTest, not the '@Named("rose") int'. The reason the int isn't being printed is because Guice doesn't need to provision it -- it's already bound to a precreated instance. toInstance bindings (which constant bindings necessarily are) don't need provisioning.

However, it is a little quirky with what's printed out -- take this test for example:

  private static class A1 {
    @Inject @Named("foo") B1 b;
    @Inject @Named("unknown") B1 b1;
  }
  private static class B1 { }
  public void testAnnotations() {
    Injector injector = Guice.createInjector(new AbstractModule() {
      @Override
      protected void configure() {
        bind(A1.class).annotatedWith(named("start")).to(A1.class);
        bind(B1.class).annotatedWith(named("foo")).to(B1.class);
        bind(B1.class).annotatedWith(Named.class).to(B1.class);
        bindListener(Matchers.any(), new ProvisionListener() {
          public <T> void onProvision(ProvisionInvocation<T> provision) {
System.out.println("Provisioning: " + provision.getKey() + ", chain: " + provision.getDependencyChain() + "\n");
          }
        });
      }
    });
    injector.getInstance(Key.get(A1.class, named("start")));
  }

What's printed out is:
Provisioning: Key[type=com.google.inject.ProvisionListenerTest$A1, annotation=[none]], chain: [Dependency: Key[type=com.google.inject.ProvisionListenerTest$A1, [email protected](value=start)], source: com.google.inject.ProvisionListenerTest$16.configure(ProvisionListenerTest.java:484), Dependency: Key[type=com.google.inject.ProvisionListenerTest$A1, annotation=[none]], source: com.google.inject.ProvisionListenerTest$16.configure(ProvisionListenerTest.java:484)]

Provisioning: Key[type=com.google.inject.ProvisionListenerTest$B1, annotation=[none]], chain: [Dependency: Key[type=com.google.inject.ProvisionListenerTest$A1, [email protected](value=start)], source: com.google.inject.ProvisionListenerTest$16.configure(ProvisionListenerTest.java:484), Dependency: Key[type=com.google.inject.ProvisionListenerTest$A1, annotation=[none]], source: com.google.inject.ProvisionListenerTest$16.configure(ProvisionListenerTest.java:484), Dependency: Key[type=com.google.inject.ProvisionListenerTest$B1, [email protected](value=foo)]@com.google.inject.ProvisionListenerTest$A1.b, source: com.google.inject.ProvisionListenerTest$16.configure(ProvisionListenerTest.java:485), Dependency: Key[type=com.google.inject.ProvisionListenerTest$B1, annotation=[none]], source: com.google.inject.ProvisionListenerTest$16.configure(ProvisionListenerTest.java:485)]

Provisioning: Key[type=com.google.inject.ProvisionListenerTest$B1, annotation=[none]], chain: [Dependency: Key[type=com.google.inject.ProvisionListenerTest$A1, [email protected](value=start)], source: com.google.inject.ProvisionListenerTest$16.configure(ProvisionListenerTest.java:484), Dependency: Key[type=com.google.inject.ProvisionListenerTest$A1, annotation=[none]], source: com.google.inject.ProvisionListenerTest$16.configure(ProvisionListenerTest.java:484), Dependency: Key[type=com.google.inject.ProvisionListenerTest$B1, [email protected](value=unknown)]@com.google.inject.ProvisionListenerTest$A1.b1, source: com.google.inject.ProvisionListenerTest$16.configure(ProvisionListenerTest.java:486), Dependency: Key[type=com.google.inject.ProvisionListenerTest$B1, annotation=[none]], source: com.google.inject.ProvisionListenerTest$16.configure(ProvisionListenerTest.java:486)]

The first line is saying "I am creating a new unannotated A1", because @Named("start") A1 is linked to that. The dependency hierarchy tells you that you're coming to A1 through @Named("start") A1. The second line is basically the same, except for an unanottated B1 coming from @Named("start") A1 -> A1 -> @Named("foo") B1 -> B1

The third line is more the case you're looking for here. It's saying "I am creating a new unannotated B1", the chain is:
  @Named("start") A1 -> A1 -> @Named("unknown") B1 -> B1

As near as I can tell, the only time the annotation in Provision.getKey() will be something other than 'none' is for Provider bindings, because all other bindings must ultimately link to an unannotated class or typeliteral.

--
You received this message because you are subscribed to the Google Groups 
"google-guice-dev" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-guice-dev?hl=en.

Reply via email to