Java 类com.google.inject.binder.ScopedBindingBuilder 实例源码

项目:ProjectAres    文件:InjectableMethod.java   
public Module bindingModule() {
    return new KeyedManifest.Impl(method) {
        @Override
        public void configure() {
            final Binder binder = binder().withSource(method);
            if(!hasReturnValue()) {
                binder.addError("Cannot bind this method as a provider because it does not return a value");
                return;
            }

            install(InjectableMethod.this);

            final ScopedBindingBuilder builder = binder.bind(providedKey).toProvider(asProvider());
            if(scope != null) builder.in(scope);
        }
    };
}
项目:salta    文件:LinkedBindingBuilderImpl.java   
@Override
public ScopedBindingBuilder toProvider(Provider<? extends T> provider) {

    return new ScopedBindingBuilderImpl(
            delegate.toProvider(new Supplier<T>() {
                @Override
                public T get() {
                    return provider.get();
                }

                @Inject
                public void init(Injector injector) {
                    injector.injectMembers(provider);
                }
            }));
}
项目:miscellaneous    文件:Providers.java   
void bindFutureProvider(PrivateBinder binder) {
  binder = binder.withSource(source);

  ScopedBindingBuilder scoper = binder.bind(bindingKey).toProvider(this);

  if (isVoid(method)) {
    scoper.asEagerSingleton();
  } else {
    if (scopeAnnotation != null) {
      scoper.in(scopeAnnotation);
    }
    if (exposedBinding) {
      binder.expose(bindingKey);
    }
  }
}
项目:guiceberry    文件:ModuleWriter.java   
protected void applyScoping(Binding<?> binding, final ScopedBindingBuilder scopedBindingBuilder) {
  binding.acceptScopingVisitor(new BindingScopingVisitor<Void>() {
    public Void visitEagerSingleton() {
      if (scopedBindingBuilder != null) {
        scopedBindingBuilder.asEagerSingleton();
      }
      return null;
    }

    public Void visitScope(Scope scope) {
      scopedBindingBuilder.in(scope);
      return null;
    }

    public Void visitScopeAnnotation(Class<? extends Annotation> scopeAnnotation) {
      scopedBindingBuilder.in(scopeAnnotation);
      return null;
    }

    public Void visitNoScoping() {
      // do nothing
      return null;
    }
  });
}
项目:guiceberry    文件:ModuleWriter.java   
protected void applyScoping(Binding<?> binding, final ScopedBindingBuilder scopedBindingBuilder) {
  binding.acceptScopingVisitor(new BindingScopingVisitor<Void>() {
    public Void visitEagerSingleton() {
      if (scopedBindingBuilder != null) {
        scopedBindingBuilder.asEagerSingleton();
      }
      return null;
    }

    public Void visitScope(Scope scope) {
      scopedBindingBuilder.in(scope);
      return null;
    }

    public Void visitScopeAnnotation(Class<? extends Annotation> scopeAnnotation) {
      scopedBindingBuilder.in(scopeAnnotation);
      return null;
    }

    public Void visitNoScoping() {
      // do nothing
      return null;
    }
  });
}
项目:guice    文件:CheckedProviderMethod.java   
void configure(Binder binder) {
  binder = binder.withSource(method);

  SecondaryBinder<?, ?> sbinder =
      ThrowingProviderBinder.create(binder).bind(checkedProvider, key.getTypeLiteral());
  if (key.getAnnotation() != null) {
    sbinder = sbinder.annotatedWith(key.getAnnotation());
  } else if (key.getAnnotationType() != null) {
    sbinder = sbinder.annotatedWith(key.getAnnotationType());
  }
  sbinder.scopeExceptions(scopeExceptions);
  ScopedBindingBuilder sbbuilder = sbinder.toProviderMethod(this);
  if (scopeAnnotation != null) {
    sbbuilder.in(scopeAnnotation);
  }

  if (exposed) {
    // the cast is safe 'cause the only binder we have implements PrivateBinder. If there's a
    // misplaced @Exposed, calling this will add an error to the binder's error queue
    ((PrivateBinder) binder).expose(sbinder.getKey());
  }

  CheckedProvideUtils.validateExceptions(
      binder, exceptionTypes, sbinder.getExceptionTypes(), checkedProvider);
}
项目:guice-old    文件:CheckedProviderMethod.java   
void configure(Binder binder) {
  binder = binder.withSource(method);

  SecondaryBinder<?, ?> sbinder = 
    ThrowingProviderBinder.create(binder)
      .bind(checkedProvider, key.getTypeLiteral());
  if(key.getAnnotation() != null) {
    sbinder = sbinder.annotatedWith(key.getAnnotation());
  } else if(key.getAnnotationType() != null) {
    sbinder = sbinder.annotatedWith(key.getAnnotationType());
  } 
  ScopedBindingBuilder sbbuilder = sbinder.toProviderMethod(this);
  if(scopeAnnotation != null) {
    sbbuilder.in(scopeAnnotation);
  }

  if (exposed) {
    // the cast is safe 'cause the only binder we have implements PrivateBinder. If there's a
    // misplaced @Exposed, calling this will add an error to the binder's error queue
    ((PrivateBinder) binder).expose(sbinder.getKey());
  }

  CheckedProvideUtils.validateExceptions(
      binder, exceptionTypes, sbinder.getExceptionTypes(), checkedProvider);
}
项目:guice-old    文件:Scoping.java   
public static Scoping forAnnotation(final Class<? extends Annotation> scopingAnnotation) {
  if (scopingAnnotation == Singleton.class
      || scopingAnnotation == javax.inject.Singleton.class) {
    return SINGLETON_ANNOTATION;
  }

  return new Scoping() {
    @Override public <V> V acceptVisitor(BindingScopingVisitor<V> visitor) {
      return visitor.visitScopeAnnotation(scopingAnnotation);
    }

    @Override public Class<? extends Annotation> getScopeAnnotation() {
      return scopingAnnotation;
    }

    @Override public String toString() {
      return scopingAnnotation.getName();
    }

    @Override public void applyTo(ScopedBindingBuilder scopedBindingBuilder) {
      scopedBindingBuilder.in(scopingAnnotation);
    }
  };
}
项目:guice-old    文件:Scoping.java   
public static Scoping forInstance(final Scope scope) {
  if (scope == Scopes.SINGLETON) {
    return SINGLETON_INSTANCE;
  }

  return new Scoping() {
    @Override public <V> V acceptVisitor(BindingScopingVisitor<V> visitor) {
      return visitor.visitScope(scope);
    }

    @Override public Scope getScopeInstance() {
      return scope;
    }

    @Override public String toString() {
      return scope.toString();
    }

    @Override public void applyTo(ScopedBindingBuilder scopedBindingBuilder) {
      scopedBindingBuilder.in(scope);
    }
  };
}
项目:jooby    文件:ApiTool.java   
@Override public void configure(final Env env, final Config conf, final Binder binder)
    throws Exception {
  boolean dev = env.name().equals("dev");
  ScopedBindingBuilder provider = binder.bind(M)
      .toProvider(APIProvider.class);
  if (!dev) {
    provider.asEagerSingleton();
  }
  Path dir = Optional.ofNullable(basedir).orElse(Paths.get(conf.getString("user.dir")));

  ApiParser parser = new ApiParser(dir, filter);
  customizer.forEach(parser::modify);

  binder.bind(ApiParser.class).toInstance(parser);

  String contextPath = conf.getString("application.path");
  if (swaggerOptions != null) {
    swagger(contextPath, env.router(), swaggerOptions, swagger);
  }
  if (ramlOptions != null) {
    raml(contextPath, env.router(), ramlOptions, raml);
  }
}
项目:google-guice    文件:CheckedProviderMethod.java   
void configure(Binder binder) {
  binder = binder.withSource(method);

  SecondaryBinder<?, ?> sbinder = 
    ThrowingProviderBinder.create(binder)
      .bind(checkedProvider, key.getTypeLiteral());
  if(key.getAnnotation() != null) {
    sbinder = sbinder.annotatedWith(key.getAnnotation());
  } else if(key.getAnnotationType() != null) {
    sbinder = sbinder.annotatedWith(key.getAnnotationType());
  } 
  ScopedBindingBuilder sbbuilder = sbinder.toProviderMethod(this);
  if(scopeAnnotation != null) {
    sbbuilder.in(scopeAnnotation);
  }

  if (exposed) {
    // the cast is safe 'cause the only binder we have implements PrivateBinder. If there's a
    // misplaced @Exposed, calling this will add an error to the binder's error queue
    ((PrivateBinder) binder).expose(sbinder.getKey());
  }

  CheckedProvideUtils.validateExceptions(
      binder, exceptionTypes, sbinder.getExceptionTypes(), checkedProvider);
}
项目:google-guice    文件:Scoping.java   
public static Scoping forAnnotation(final Class<? extends Annotation> scopingAnnotation) {
  if (scopingAnnotation == Singleton.class
      || scopingAnnotation == javax.inject.Singleton.class) {
    return SINGLETON_ANNOTATION;
  }

  return new Scoping() {
    public <V> V acceptVisitor(BindingScopingVisitor<V> visitor) {
      return visitor.visitScopeAnnotation(scopingAnnotation);
    }

    @Override public Class<? extends Annotation> getScopeAnnotation() {
      return scopingAnnotation;
    }

    @Override public String toString() {
      return scopingAnnotation.getName();
    }

    public void applyTo(ScopedBindingBuilder scopedBindingBuilder) {
      scopedBindingBuilder.in(scopingAnnotation);
    }
  };
}
项目:google-guice    文件:Scoping.java   
public static Scoping forInstance(final Scope scope) {
  if (scope == Scopes.SINGLETON) {
    return SINGLETON_INSTANCE;
  }

  return new Scoping() {
    public <V> V acceptVisitor(BindingScopingVisitor<V> visitor) {
      return visitor.visitScope(scope);
    }

    @Override public Scope getScopeInstance() {
      return scope;
    }

    @Override public String toString() {
      return scope.toString();
    }

    public void applyTo(ScopedBindingBuilder scopedBindingBuilder) {
      scopedBindingBuilder.in(scope);
    }
  };
}
项目:miscellaneous    文件:Providers.java   
private void bindProvidersInScope(PrivateBinder privateBinder) {
  ScopedBindingBuilder scoper = privateBinder.bind(providersClass);

  if (scopeAnnotation != null) {
    scoper.in(scopeAnnotation);
  }

  for (EventualProvider<?> p : providers) {
    p.bindFutureProvider(privateBinder);
  }
}
项目:guiceberry    文件:InterceptingBindingsBuilder.java   
@Override
public <T> Void visit(Binding<T> binding) {
  final Key<T> key = binding.getKey();

  if (!keysToIntercept.contains(key)) {
    return super.visit(binding);
  }

  binding.acceptTargetVisitor(new DefaultBindingTargetVisitor<T, Void>() {
    @Override
    public Void visit(UntargettedBinding<? extends T> untargettedBinding) {
      binder.addError("Cannot intercept bare binding of %s. " +
                "You may only intercept bindings that bind a class to something.", key);
      return null;
    }
  });

  Key<T> anonymousKey = Key.get(key.getTypeLiteral(), UniqueAnnotations.create());
  binder.bind(key).toProvider(new InterceptingProvider<T>(key, binder.getProvider(anonymousKey)));

  ScopedBindingBuilder scopedBindingBuilder = bindKeyToTarget(binding, binder, anonymousKey);

  // we scope the user's provider, not the interceptor. This is dangerous,
  // but convenient. It means that although the user's provider will live
  // in its proper scope, the intereptor gets invoked without a scope
  applyScoping(binding, scopedBindingBuilder);

  keysIntercepted.add(key);
  return null;
}
项目:guiceberry    文件:InterceptingBindingsBuilder.java   
@Override
public <T> Void visit(Binding<T> binding) {
  final Key<T> key = binding.getKey();

  if (!keysToIntercept.contains(key)) {
    return super.visit(binding);
  }

  binding.acceptTargetVisitor(new DefaultBindingTargetVisitor<T, Void>() {
    @Override
    public Void visit(UntargettedBinding<? extends T> untargettedBinding) {
      binder.addError("Cannot intercept bare binding of %s. " +
                "You may only intercept bindings that bind a class to something.", key);
      return null;
    }
  });

  Key<T> anonymousKey = Key.get(key.getTypeLiteral(), UniqueAnnotations.create());
  binder.bind(key).toProvider(new InterceptingProvider<T>(key, binder.getProvider(anonymousKey)));

  ScopedBindingBuilder scopedBindingBuilder = bindKeyToTarget(binding, binder, anonymousKey);

  // we scope the user's provider, not the interceptor. This is dangerous,
  // but convenient. It means that although the user's provider will live
  // in its proper scope, the interceptor gets invoked without a scope
  applyScoping(binding, scopedBindingBuilder);

  keysIntercepted.add(key);
  return null;
}
项目:solrmeter    文件:StatisticsModule.java   
/**
 * Bind also the concrete model class, this binding is necesary to add the scope also to the concrete class.
 * @param description
 */
private void bindModelClass(StatisticDescriptor description) {
    Class<?> statisticModelClass = description.getModelClass();
    ScopedBindingBuilder binderBuilder = bind(statisticModelClass);
    applyScope(description, binderBuilder);

}
项目:guice    文件:ThrowingProviderBinder.java   
ScopedBindingBuilder toProviderMethod(CheckedProviderMethod<?> target) {
  Key<CheckedProviderMethod<?>> targetKey =
      Key.get(CHECKED_PROVIDER_METHOD_TYPE, UniqueAnnotations.create());
  binder.bind(targetKey).toInstance(target);

  return toInternal(targetKey);
}
项目:guice    文件:Scoping.java   
public static Scoping forAnnotation(final Class<? extends Annotation> scopingAnnotation) {
  if (scopingAnnotation == Singleton.class || scopingAnnotation == javax.inject.Singleton.class) {
    return SINGLETON_ANNOTATION;
  }

  return new Scoping() {
    @Override
    public <V> V acceptVisitor(BindingScopingVisitor<V> visitor) {
      return visitor.visitScopeAnnotation(scopingAnnotation);
    }

    @Override
    public Class<? extends Annotation> getScopeAnnotation() {
      return scopingAnnotation;
    }

    @Override
    public String toString() {
      return scopingAnnotation.getName();
    }

    @Override
    public void applyTo(ScopedBindingBuilder scopedBindingBuilder) {
      scopedBindingBuilder.in(scopingAnnotation);
    }
  };
}
项目:guice    文件:Scoping.java   
public static Scoping forInstance(final Scope scope) {
  if (scope == Scopes.SINGLETON) {
    return SINGLETON_INSTANCE;
  } else if (scope == Scopes.NO_SCOPE) {
    return EXPLICITLY_UNSCOPED;
  }

  return new Scoping() {
    @Override
    public <V> V acceptVisitor(BindingScopingVisitor<V> visitor) {
      return visitor.visitScope(scope);
    }

    @Override
    public Scope getScopeInstance() {
      return scope;
    }

    @Override
    public String toString() {
      return scope.toString();
    }

    @Override
    public void applyTo(ScopedBindingBuilder scopedBindingBuilder) {
      scopedBindingBuilder.in(scope);
    }
  };
}
项目:guice-old    文件:ThrowingProviderBinder.java   
ScopedBindingBuilder toProviderMethod(CheckedProviderMethod<?> target) {
  Key<CheckedProviderMethod> targetKey =
      Key.get(CheckedProviderMethod.class, UniqueAnnotations.create());
  binder.bind(targetKey).toInstance(target);

  return toInternal(targetKey);
}
项目:guice-old    文件:RealElement.java   
public ScopedBindingBuilder toProvider(
    Key<? extends javax.inject.Provider<? extends T>> providerKey) {
  delegate.toProvider(providerKey);
  annotation.targetType = TargetType.PROVIDER_KEY;
  annotation.target = providerKey;
  return this;
}
项目:guice-old    文件:RealElement.java   
public <S extends T> ScopedBindingBuilder toConstructor(
    Constructor<S> constructor, TypeLiteral<? extends S> type) {
  delegate.toConstructor(constructor, type);
  annotation.targetType = TargetType.CONSTRUCTOR;
  annotation.target = InjectionPoint.forConstructor(constructor, type);
  return this;
}
项目:google-guice    文件:ThrowingProviderBinder.java   
ScopedBindingBuilder toProviderMethod(CheckedProviderMethod<?> target) {
  Key<CheckedProviderMethod> targetKey =
      Key.get(CheckedProviderMethod.class, UniqueAnnotations.create());
  binder.bind(targetKey).toInstance(target);

  return toInternal(targetKey);
}
项目:empiria.player    文件:AbstractTestModule.java   
@Override
public ScopedBindingBuilder to(final Class<? extends T> arg0) {// NOPMD
    return new NullScopedBindingBuilder();
}
项目:empiria.player    文件:AbstractTestModule.java   
@Override
public ScopedBindingBuilder to(final TypeLiteral<? extends T> arg0) {// NOPMD
    return new NullScopedBindingBuilder();
}
项目:empiria.player    文件:AbstractTestModule.java   
@Override
public ScopedBindingBuilder to(final Key<? extends T> arg0) {// NOPMD
    return new NullScopedBindingBuilder();
}
项目:empiria.player    文件:AbstractTestModule.java   
@Override
public ScopedBindingBuilder toProvider(final Provider<? extends T> arg0) {
    return null;
}
项目:empiria.player    文件:AbstractTestModule.java   
@Override
public ScopedBindingBuilder toProvider(TypeLiteral<? extends javax.inject.Provider<? extends T>> providerType) {
    return new NullScopedBindingBuilder();
}
项目:empiria.player    文件:AbstractTestModule.java   
@Override
public <S extends T> ScopedBindingBuilder toConstructor(Constructor<S> constructor) {
    return new NullScopedBindingBuilder();
}
项目:empiria.player    文件:AbstractTestModule.java   
@Override
public <S extends T> ScopedBindingBuilder toConstructor(Constructor<S> constructor, TypeLiteral<? extends S> type) {
    return new NullScopedBindingBuilder();
}
项目:empiria.player    文件:AbstractTestModule.java   
@Override
public ScopedBindingBuilder toProvider(Class<? extends javax.inject.Provider<? extends T>> providerType) {
    return new NullScopedBindingBuilder();
}
项目:empiria.player    文件:AbstractTestModule.java   
@Override
public ScopedBindingBuilder toProvider(Key<? extends javax.inject.Provider<? extends T>> providerKey) {
    return new NullScopedBindingBuilder();
}
项目:empiria.player    文件:AbstractTestModule.java   
@Override
public ScopedBindingBuilder to(Class<? extends T> arg0) {
    return new NullScopedBindingBuilder();
}
项目:empiria.player    文件:AbstractTestModule.java   
@Override
public ScopedBindingBuilder to(TypeLiteral<? extends T> arg0) {
    return new NullScopedBindingBuilder();
}
项目:empiria.player    文件:AbstractTestModule.java   
@Override
public ScopedBindingBuilder to(Key<? extends T> arg0) {
    return new NullScopedBindingBuilder();
}
项目:empiria.player    文件:AbstractTestModule.java   
@Override
public <S extends T> ScopedBindingBuilder toConstructor(Constructor<S> arg0) {
    return new NullScopedBindingBuilder();
}
项目:empiria.player    文件:AbstractTestModule.java   
@Override
public <S extends T> ScopedBindingBuilder toConstructor(Constructor<S> arg0, TypeLiteral<? extends S> arg1) {
    return new NullScopedBindingBuilder();
}
项目:empiria.player    文件:AbstractTestModule.java   
@Override
public ScopedBindingBuilder toProvider(Provider<? extends T> arg0) {
    return new NullScopedBindingBuilder();
}
项目:empiria.player    文件:AbstractTestModule.java   
@Override
public ScopedBindingBuilder toProvider(Class<? extends javax.inject.Provider<? extends T>> arg0) {
    return new NullScopedBindingBuilder();
}