Java Code Examples for com.google.inject.Binding#acceptScopingVisitor()

The following examples show how to use com.google.inject.Binding#acceptScopingVisitor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MultipleSingletonPluginUITest.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
private boolean isSingleton(Binding<?> b) {
	return b.acceptScopingVisitor(new DefaultBindingScopingVisitor<Boolean>() {
		@Override
		public Boolean visitEagerSingleton() {
			return Boolean.TRUE;
		}

		@Override
		public Boolean visitScope(Scope scope) {
			return Scopes.SINGLETON.equals(scope);
		}

		@Override
		protected Boolean visitOther() {
			return Boolean.FALSE;
		}
	});
}
 
Example 2
Source File: EagerSingletonInstaller.java    From dropwizard-guicey with MIT License 5 votes vote down vote up
@Override
public <T> void manualBinding(final Binder binder, final Class<T> type, final Binding<T> binding) {
    // we can only validate existing binding here (actually entire extension is pretty useless in case of manual
    // binding)
    final Class<? extends Annotation> scope = binding.acceptScopingVisitor(VISITOR);
    // in production all services will work as eager singletons, for report (TOOL stage) consider also valid
    Preconditions.checkArgument(scope.equals(EagerSingleton.class)
                    || (!binder.currentStage().equals(Stage.DEVELOPMENT)
                    && scope.equals(Singleton.class)),
            // intentially no "at" before stacktrtace because idea may hide error in some cases
            "Eager bean, declared manually is not marked .asEagerSingleton(): %s (%s)",
            type.getName(), BindingUtils.getDeclarationSource(binding));
}
 
Example 3
Source File: LifecycleMatcher.java    From seed with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public boolean matches(Binding<?> binding) {
    Class<?> rawType = binding.getKey().getTypeLiteral().getRawType();
    return binding.acceptScopingVisitor(preDestroyScopingVisitor) &&
            (isAutoCloseable(rawType) || hasJsr250Methods(rawType));
}