/** * Binds a {@code scopeAnnotationClass}, to the current scope. The current scope will accept all classes * that are scoped using this {@code scopeAnnotationClass}. * * @param scopeAnnotationClass an annotation that should be qualified by {@link javax.inject.Scope}. If not, * an exception is thrown. * Note that the {@link Singleton} scope annotation class doesn't need to be bound, it's built-in. * @see #getParentScope(Class) */ @Override public void bindScopeAnnotation(Class<? extends Annotation> scopeAnnotationClass) { checkIsAnnotationScope(scopeAnnotationClass); if (scopeAnnotationClass == Singleton.class) { throw new IllegalArgumentException(format("The annotation @Singleton is already bound " + "to the root scope of any scope. It can't be bound dynamically.")); } scopeAnnotationClasses.add(scopeAnnotationClass); }
/** * @param scopeAnnotationClass an annotation that should be qualified by {@link javax.inject.Scope}. If not, * an exception is thrown. * @return the parent {@link ScopeNode} of this scope that is bound to {@code scopeAnnotationClass}. * The current {@code scope} (this) can be returned if it is bound to {@code scopeAnnotationClass}. * If no such parent exists, it throws an exception. This later case means that something scoped * is using a lower scoped dependency, which is conceptually flawed and not allowed in Toothpick. * Note that is {@code scopeAnnotationClass} is {@link Singleton}, the root scope is always returned. * Thus the {@link Singleton} scope annotation class doesn't need to be bound, it's built-in. */ @SuppressWarnings({ "unused", "used by generated code" }) @Override public ScopeNode getParentScope(Class scopeAnnotationClass) { checkIsAnnotationScope(scopeAnnotationClass); if (scopeAnnotationClass == Singleton.class) { return getRootScope(); } ScopeNode currentScope = this; while (currentScope != null) { if (currentScope.isBoundToScopeAnnotation(scopeAnnotationClass)) { return currentScope; } currentScope = currentScope.getParentScope(); } throw new IllegalStateException(format("There is no parent scope of %s bound to scope scopeAnnotationClass %s", // this.name, // scopeAnnotationClass.getName())); }
/** * Binds a {@code scopeAnnotationClass}, to the current scope. The current scope will accept all classes * that are scoped using this {@code scopeAnnotationClass}. * * @param scopeAnnotationClass an annotation that should be qualified by {@link javax.inject.Scope}. If not, * an exception is thrown. * Note that the {@link Singleton} scope annotation class doesn't need to be bound, it's built-in. * @see #getParentScope(Class) */ @Override public void bindScopeAnnotation(Class<? extends Annotation> scopeAnnotationClass) { checkIsAnnotationScope(scopeAnnotationClass); if (scopeAnnotationClass == Singleton.class) { throw new IllegalArgumentException(format("The annotation @Singleton is already bound " + "to the root scope of any scope. It can't be bound dynamically.")); } scopeAnnotationClasses.add(scopeAnnotationClass); }
/** * Binds a {@code scopeAnnotationClass}, to the current scope. The current scope will accept all classes * that are scoped using this {@code scopeAnnotationClass}. * * @param scopeAnnotationClass an annotation that should be qualified by {@link javax.inject.Scope}. If not, * an exception is thrown. * Note that the {@link Singleton} scope annotation class doesn't need to be bound, it's built-in. * @see #getParentScope(Class) */ @Override public void bindScopeAnnotation(Class<? extends Annotation> scopeAnnotationClass) { checkIsAnnotationScope(scopeAnnotationClass); if (scopeAnnotationClass == Singleton.class) { throw new IllegalArgumentException(format("The annotation @Singleton is already bound " + "to the root scope of any scope. It can't be bound dynamically.")); } scopeAnnotationClasses.add(scopeAnnotationClass); }
/** * @param scopeAnnotationClass an annotation that should be qualified by {@link javax.inject.Scope}. If not, * an exception is thrown. * @return the parent {@link ScopeNode} of this scope that is bound to {@code scopeAnnotationClass}. * The current {@code scope} (this) can be returned if it is bound to {@code scopeAnnotationClass}. * If no such parent exists, it throws an exception. This later case means that something scoped * is using a lower scoped dependency, which is conceptually flawed and not allowed in Toothpick. * Note that is {@code scopeAnnotationClass} is {@link Singleton}, the root scope is always returned. * Thus the {@link Singleton} scope annotation class doesn't need to be bound, it's built-in. */ @SuppressWarnings({ "unused", "used by generated code" }) @Override public ScopeNode getParentScope(Class scopeAnnotationClass) { checkIsAnnotationScope(scopeAnnotationClass); if (scopeAnnotationClass == Singleton.class) { return getRootScope(); } ScopeNode currentScope = this; while (currentScope != null) { if (currentScope.isBoundToScopeAnnotation(scopeAnnotationClass)) { return currentScope; } currentScope = currentScope.getParentScope(); } throw new IllegalStateException(format("There is no parent scope of %s bound to scope scopeAnnotationClass %s", // this.name, // scopeAnnotationClass.getName())); }
/** * @param scopeAnnotationClass an annotation that should be qualified by {@link javax.inject.Scope}. If not, * an exception is thrown. * @return the parent {@link ScopeNode} of this scope that is bound to {@code scopeAnnotationClass}. * The current {@code scope} (this) can be returned if it is bound to {@code scopeAnnotationClass}. * If no such parent exists, it throws an exception. This later case means that something scoped * is using a lower scoped dependency, which is conceptually flawed and not allowed in Toothpick. * Note that is {@code scopeAnnotationClass} is {@link Singleton}, the root scope is always returned. * Thus the {@link Singleton} scope annotation class doesn't need to be bound, it's built-in. */ @SuppressWarnings({ "unused", "used by generated code" }) @Override public ScopeNode getParentScope(Class scopeAnnotationClass) { checkIsAnnotationScope(scopeAnnotationClass); if (scopeAnnotationClass == Singleton.class) { return getRootScope(); } ScopeNode currentScope = this; while (currentScope != null) { if (currentScope.isBoundToScopeAnnotation(scopeAnnotationClass)) { return currentScope; } currentScope = currentScope.getParentScope(); } throw new IllegalStateException(format("There is no parent scope of %s bound to scope scopeAnnotationClass %s", // this.name, // scopeAnnotationClass.getName())); }