Status: New
Owner: ----

New issue 360 by aleksey.didik: Wrong scope visiting for LinkedKeyBinding
http://code.google.com/p/google-guice/issues/detail?id=360

Hello all,
I have a filling, Guice have a bug in scope visiting for LinkedKeyBinding  
if target is scoped by annotation.

My steps:
1) create interface
2) create class and implement interface
3) annotate by @Singleton
4) bind interface to class
5) try to accept scoping visitor for LinkedKeyBinding
6) visitNoScoping method was called instead of visitScope.

If I bind only class, visitScope method is called correctly (see example).
If I bind interface to class and it's scoped by in(Scopes.SINGLETON)  
visitScope methods is called correctly.

Guice version - current trunk.

My test:

public class LinkedKeyVisiting {

   public static void main(String[] args) {
     Injector inj = Guice.createInjector(new AbstractModule() {
       @Override protected void configure() {
         bind(Interfaze.class).to(WithInterface.class);
         bind(WithoutInterface.class);
         bind(Visitor.class).asEagerSingleton();
       }
     });
   }

   static interface Interfaze {}

   @Singleton
   static class WithInterface implements Interfaze {}

   @Singleton
   static class WithoutInterface {}

   static class Visitor {

     @Inject
     public void visit(Injector inj) {


       final Binding<?> withoutInterfaceBinding =  
inj.getBinding(WithoutInterface.class);
       withoutInterfaceBinding.acceptScopingVisitor(new  
DefaultBindingScopingVisitor<Void>() {
         @Override public Void visitScope(Scope scope) {
           System.out.println(withoutInterfaceBinding.getKey() + " in  
scope " + scope);
           return null;
         }

         @Override public Void visitNoScoping() {
           System.out.println(withoutInterfaceBinding.getKey() + " without  
scope ");
           return null;
         }
       });

       final Binding<Interfaze> withInterfaceBinding =  
inj.getBinding(Interfaze.class);
       withInterfaceBinding.acceptTargetVisitor(new  
DefaultBindingTargetVisitor<Interfaze, Void>() {

         @Override
         public Void visit(final LinkedKeyBinding<? extends Interfaze>  
linkedKeyBinding) {
           linkedKeyBinding.acceptScopingVisitor(new  
DefaultBindingScopingVisitor<Void>() {
             public Void visitScope(Scope scope) {
               System.out.println(linkedKeyBinding.getKey() + " in scope " +  
scope);
               return null;
             }

             public Void visitNoScoping() {
               System.out.println(linkedKeyBinding.getKey() + " without  
scope ");
               return null;
             }
           });
           return null;
         }
       });

     }
   }
}

Class output:

Key[type=com.google.inject.LinkedKeyVisiting$WithoutInterface,  
annotation=[none]] in scope Scopes.SINGLETON
Key[type=com.google.inject.LinkedKeyVisiting$Interfaze, annotation=[none]]  
without scope

It's looks like a bug.



--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings

--~--~---------~--~----~------------~-------~--~----~
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