check that a binding's target annotation scope, if present, is supported
by the scope {@code scope}.
@param binding the binding being installed.
@param scope the scope where the binding is installed.
339103
@Override
  public void checkIllegalBinding(Binding binding, Scope scope) {
    Class<?> clazz;
    switch (binding.getMode()) {
      case SIMPLE:
        clazz = binding.getKey();
        break;
      case CLASS:
        clazz = binding.getImplementationClass();
        break;
      case PROVIDER_CLASS:
        clazz = binding.getProviderClass();
        break;
      default:
        return;
    }

    for (Annotation annotation : clazz.getAnnotations()) {
      Class<? extends Annotation> annotationType = annotation.annotationType();
      if (annotationType.isAnnotationPresent(javax.inject.Scope.class)) {
        if (!scope.isBoundToScopeAnnotation(annotationType)) {
          throw new IllegalBindingException(format("Class %s cannot be bound."
                  + " It has a scope annotation: %s that is not supported by current scope: %s",
              clazz.getName(), annotationType.getName(), scope.getName()));
        }
      }
    }
  }
478455
public void setScope(java.util.Collection<String> scope) {
        if (scope == null) {
            this.scope = null;
            return;
        }

        this.scope = new java.util.ArrayList<String>(scope);
    }
1042435
def on_bind_target(self, target, ctx=None):
        

        _on_bind_target = getattr(self, Annotation._ON_BIND_TARGET, None)

        if _on_bind_target is not None:
            _on_bind_target(self, target=target, ctx=ctx)
1369561
public static boolean isAnnotationPresent(Class<?> target, Class<? extends Annotation> annotation) {
        Class<?> clazz = target;
        if (clazz.isAnnotationPresent(annotation)) {
            return true;
        }
        while((clazz = clazz.getSuperclass()) != null) {
            if (clazz.isAnnotationPresent(annotation)) {
                return true;
            }
        }
        return false;
    }
494503
public void set(Class<? extends Annotation> scope, String key, String value) {
		Preconditions.checkNotNull(scope, "Parameter 'scope' must not be [" + scope + "]");
		Preconditions.checkNotNull(key, "Parameter 'key' must not be [" + key + "]");
		Preconditions.checkNotNull(value, "Parameter 'value' must not be [" + value + "]");
		Preconditions.checkArgument(scope.isAnnotationPresent(Scope.class), 
				"Parameter 'scope' must be annotated with @Scope");
		store(scope).set(key, value);
	}
251270
private void bindScopeAnnotationIfNameIsScopeAnnotation() {
    if (name.getClass() == Class.class //
            && Annotation.class.isAssignableFrom((Class) name) //
            && isScopeAnnotationClass((Class<? extends Annotation>) name)) {
      bindScopeAnnotation((Class<? extends Annotation>) name);
    }
  }
201637
public void setScopes(Set<ApiAppOauthScopeType> scopes) {
        if (oauth == null) {
            oauth = new ApiAppOauth();
        }
        oauth.setScopes(scopes);
    }
462519
private void bindAttribute(Annotation annotation)
    {
        String fieldname = ((AttributeOverride) annotation).name();
        Column column = ((AttributeOverride) annotation).column();
        ((AbstractManagedType) this.superClazzType).columnBindings.put(fieldname, column);
    }
609472
private <T> Class<? extends Annotation> matchAnnotationToScope(Annotation[] annotations) {

        for (Annotation next : annotations) {
            Class<? extends Annotation> nextType = next.annotationType();
            if (nextType.getAnnotation(BindingScope.class) != null) {
                return nextType;
            }
        }
        return DefaultBinding.class;
    }
767493
public void setScope(String scope) throws ApplicationException {
	scope = scope.toLowerCase().trim();

	if (scope.equals("server")) this.scope = SCOPE_SERVER;
	else if (scope.equals("application")) this.scope = SCOPE_APPLICATION;
	else if (scope.equals("session")) this.scope = SCOPE_SESSION;
	else if (scope.equals("request")) this.scope = SCOPE_REQUEST;
	else throw new ApplicationException("invalid value [" + scope + "] for attribute [scope] from tag [lock]", "valid values are [server,application,session]");
    }
1261094
@Override
    public void addScope(String scope, int maxItemsInMemory) throws Exception {
        CacheConfiguration scopeConfig = new CacheConfiguration(scope, maxItemsInMemory);

        scopeManager.addCache(new Cache(scopeConfig));
    }
451310
public DelegationRequest<T> setScope(String scope) {
        request.addParameter(ParameterBuilder.SCOPE_KEY, scope);
        return this;
    }
452081
private void addBinding(Binding<?, ?, V> binding)
	{
		bindings.add(binding);
		
		// prevent infinite loop when binder bound by itself
		if (binding.getSource() != this)
		{
			updateViolations();
			
			// TODO: aggregate violations better; ideally provide a live view
			binding.addObservableListener(new ObservableListener<Collection<V>>()
			{
				public void valueChanged(ObservableEvent<Collection<V>> event)
				{
					updateViolations();
				}
			});
		}
	}
775813
public void setScope(ProcScope scope) {
        this.scope = scope;

        // Scope false memo
        scopeFalseMemo = falseMemo.get(scope);
        if (scopeFalseMemo == null) {
            scopeFalseMemo = new IntSet();
            falseMemo.put(scope, scopeFalseMemo);
        }
    }
1004282
public void setBinding(String binding) 
        throws JspException {
        if (binding!= null && !UIComponentTag.isValueReference(binding)) {
            // PENDING i18n
            throw new JspException("Invalid Expression:"+binding);
        }
        this.binding = binding;
    }
602911
function setHostBindings(bindings) {
    if (bindings != null) {
        var defs = tView.directives;
        for (var i = 0; i < bindings.length; i += 2) {
            var dirIndex = bindings[i];
            var def = defs[dirIndex];
            def.hostBindings && def.hostBindings(dirIndex, bindings[i + 1]);
        }
    }
}
268303
<T> InternalProviderImpl<? extends T> lookupProvider(Class<T> clazz, String bindingName) {
    if (clazz == null) {
      throw new IllegalArgumentException("TP can't get an instance of a null class.");
    }
    InternalProviderImpl<? extends T> scopedProvider = getBoundProvider(clazz, bindingName);
    if (scopedProvider != null) {
      return scopedProvider;
    }
    Iterator<ScopeNode> iterator = parentScopes.iterator();
    while (iterator.hasNext()) {
      Scope parentScope = iterator.next();
      ScopeImpl parentScopeImpl = (ScopeImpl) parentScope;
      InternalProviderImpl<? extends T> parentScopedProvider = parentScopeImpl.getBoundProvider(clazz, bindingName);
      if (parentScopedProvider != null) {
        return parentScopedProvider;
      }
    }

    //if the binding is named
    //we couldn't find it in any scope, we must fail
    //as only unnamed bindings can be created dynamically
    if (bindingName != null) {
      throw new RuntimeException(format("No binding was defined for class %s and name %s " //
          + "in scope %s and its parents %s", clazz.getName(), bindingName, getName(), getParentScopesNames()));
    }

    //we now look for an unnamed binding
    //bindingName = null;  <-- valid but fails checkstyle as we use null directly

    //check if we have a cached un-scoped provider
    InternalProviderImpl unScopedProviderInPool = getUnBoundProvider(clazz, null);
    if (unScopedProviderInPool != null) {
      return unScopedProviderInPool;
    }

    //classes discovered at runtime, not bound by any module
    //they will be a bit slower as we need to get the factory first
    //we need to know whether they are scoped or not, if so we scope them
    //if not, they are place in the pool
    Factory<T> factory = FactoryLocator.getFactory(clazz);

    if (factory.hasScopeAnnotation()) {
      //the new provider will have to work in the current scope
      Scope targetScope = factory.getTargetScope(this);
      ScopedProviderImpl<? extends T> newProvider = new ScopedProviderImpl<>(targetScope, factory, false);
      //it is bound to its target scope only if it has a scope annotation.
      //lock free installing a provider means there could have been one set concurrently since last testing
      //its value. We allow to return it here
      ScopeImpl targetScopeImpl = (ScopeImpl) targetScope;
      return targetScopeImpl.installScopedProvider(clazz, null, newProvider, false);
    } else {
      //the provider is but in a pool of unbound providers for later reuse
      final InternalProviderImpl<T> newProvider = new InternalProviderImpl<>(factory,
          false);
      //the pool is static as it is accessible from all scopes
      //lock free installing a provider means there could have been one set concurrently since last testing
      //its value. We allow to return it here
      return installUnBoundProvider(clazz, null, newProvider);
    }
  }