Java Code Examples for com.google.inject.spi.ScopeBinding

The following are top voted examples for showing how to use com.google.inject.spi.ScopeBinding. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: guice-old   File: ScopeBindingProcessor.java   Source Code and License 6 votes vote down vote up
@Override public Boolean visit(ScopeBinding command) {
  Scope scope = command.getScope();
  Class<? extends Annotation> annotationType = command.getAnnotationType();

  if (!Annotations.isScopeAnnotation(annotationType)) {
    errors.missingScopeAnnotation(annotationType);
    // Go ahead and bind anyway so we don't get collateral errors.
  }

  if (!Annotations.isRetainedAtRuntime(annotationType)) {
    errors.missingRuntimeRetention(annotationType);
    // Go ahead and bind anyway so we don't get collateral errors.
  }

  ScopeBinding existing = injector.state.getScopeBinding(checkNotNull(annotationType, "annotation type"));
  if (existing != null) {
    errors.duplicateScopes(existing, annotationType, scope);
  } else {
    checkNotNull(scope, "scope");
    injector.state.putScopeBinding(annotationType, command);
  }

  return true;
}
 
Example 2
Project: google-guice   File: ScopeBindingProcessor.java   Source Code and License 6 votes vote down vote up
@Override public Boolean visit(ScopeBinding command) {
  Scope scope = command.getScope();
  Class<? extends Annotation> annotationType = command.getAnnotationType();

  if (!Annotations.isScopeAnnotation(annotationType)) {
    errors.withSource(annotationType).missingScopeAnnotation();
    // Go ahead and bind anyway so we don't get collateral errors.
  }

  if (!Annotations.isRetainedAtRuntime(annotationType)) {
    errors.withSource(annotationType)
        .missingRuntimeRetention(command.getSource());
    // Go ahead and bind anyway so we don't get collateral errors.
  }

  Scope existing = injector.state.getScope(checkNotNull(annotationType, "annotation type"));
  if (existing != null) {
    errors.duplicateScopes(existing, annotationType, scope);
  } else {
    injector.state.putAnnotation(annotationType, checkNotNull(scope, "scope"));
  }

  return true;
}
 
Example 3
Project: guice   File: ScopeBindingProcessor.java   Source Code and License 5 votes vote down vote up
@Override
public Boolean visit(ScopeBinding command) {
  Scope scope = checkNotNull(command.getScope(), "scope");
  Class<? extends Annotation> annotationType =
      checkNotNull(command.getAnnotationType(), "annotation type");

  if (!Annotations.isScopeAnnotation(annotationType)) {
    errors.missingScopeAnnotation(annotationType);
    // Go ahead and bind anyway so we don't get collateral errors.
  }

  if (!Annotations.isRetainedAtRuntime(annotationType)) {
    errors.missingRuntimeRetention(annotationType);
    // Go ahead and bind anyway so we don't get collateral errors.
  }

  ScopeBinding existing = injector.state.getScopeBinding(annotationType);
  if (existing != null) {
    if (!scope.equals(existing.getScope())) {
      errors.duplicateScopes(existing, annotationType, scope);
    }
  } else {
    injector.state.putScopeBinding(annotationType, command);
  }

  return true;
}
 
Example 4
Project: guice   File: InheritingState.java   Source Code and License 5 votes vote down vote up
@Override
public Map<Class<? extends Annotation>, Scope> getScopes() {
  ImmutableMap.Builder<Class<? extends Annotation>, Scope> builder = ImmutableMap.builder();
  for (Map.Entry<Class<? extends Annotation>, ScopeBinding> entry : scopes.entrySet()) {
    builder.put(entry.getKey(), entry.getValue().getScope());
  }
  return builder.build();
}
 
Example 5
Project: guice   File: Scoping.java   Source Code and License 5 votes vote down vote up
/**
 * Replaces annotation scopes with instance scopes using the Injector's annotation-to-instance
 * map. If the scope annotation has no corresponding instance, an error will be added and unscoped
 * will be retuned.
 */
static Scoping makeInjectable(Scoping scoping, InjectorImpl injector, Errors errors) {
  Class<? extends Annotation> scopeAnnotation = scoping.getScopeAnnotation();
  if (scopeAnnotation == null) {
    return scoping;
  }

  ScopeBinding scope = injector.state.getScopeBinding(scopeAnnotation);
  if (scope != null) {
    return forInstance(scope.getScope());
  }

  errors.scopeNotFound(scopeAnnotation);
  return UNSCOPED;
}
 
Example 6
Project: guice-old   File: InheritingState.java   Source Code and License 5 votes vote down vote up
public Map<Class<? extends Annotation>, Scope> getScopes() {
  ImmutableMap.Builder<Class<? extends Annotation>, Scope> builder = ImmutableMap.builder();
  for (Map.Entry<Class<? extends Annotation>, ScopeBinding> entry : scopes.entrySet()) {
    builder.put(entry.getKey(), entry.getValue().getScope());
  }
  return builder.build();
}
 
Example 7
Project: guice-old   File: Scoping.java   Source Code and License 5 votes vote down vote up
/**
 * Replaces annotation scopes with instance scopes using the Injector's annotation-to-instance
 * map. If the scope annotation has no corresponding instance, an error will be added and unscoped
 * will be retuned.
 */
static Scoping makeInjectable(Scoping scoping, InjectorImpl injector, Errors errors) {
  Class<? extends Annotation> scopeAnnotation = scoping.getScopeAnnotation();
  if (scopeAnnotation == null) {
    return scoping;
  }

  ScopeBinding scope = injector.state.getScopeBinding(scopeAnnotation);
  if (scope != null) {
    return forInstance(scope.getScope());
  }

  errors.scopeNotFound(scopeAnnotation);
  return UNSCOPED;
}
 
Example 8
Project: ProjectAres   File: ElementInspector.java   Source Code and License 4 votes vote down vote up
@Override
public V visit(ScopeBinding binding) {
    return message(binding,
                   "Binding scope annotation " + binding.getAnnotationType() +
                   " to scope " + binding.getScope());
}
 
Example 9
Project: guice   File: InheritingState.java   Source Code and License 4 votes vote down vote up
@Override
public ScopeBinding getScopeBinding(Class<? extends Annotation> annotationType) {
  ScopeBinding scopeBinding = scopes.get(annotationType);
  return scopeBinding != null ? scopeBinding : parent.getScopeBinding(annotationType);
}
 
Example 10
Project: guice   File: InheritingState.java   Source Code and License 4 votes vote down vote up
@Override
public void putScopeBinding(Class<? extends Annotation> annotationType, ScopeBinding scope) {
  scopes.put(annotationType, scope);
}
 
Example 11
Project: guice   File: State.java   Source Code and License 4 votes vote down vote up
@Override
public ScopeBinding getScopeBinding(Class<? extends Annotation> scopingAnnotation) {
  return null;
}
 
Example 12
Project: guice   File: State.java   Source Code and License 4 votes vote down vote up
@Override
public void putScopeBinding(
    Class<? extends Annotation> annotationType, ScopeBinding scope) {
  throw new UnsupportedOperationException();
}
 
Example 13
Project: guice   File: Errors.java   Source Code and License 4 votes vote down vote up
public Errors duplicateScopes(
    ScopeBinding existing, Class<? extends Annotation> annotationType, Scope scope) {
  return addMessage(
      "Scope %s is already bound to %s at %s.%n Cannot bind %s.",
      existing.getScope(), annotationType, existing.getSource(), scope);
}
 
Example 14
Project: guice   File: WeakKeySetTest.java   Source Code and License 4 votes vote down vote up
@Override
public ScopeBinding getScopeBinding(Class<? extends Annotation> scopingAnnotation) {
  return null;
}
 
Example 15
Project: guice   File: WeakKeySetTest.java   Source Code and License 4 votes vote down vote up
@Override
public void putScopeBinding(Class<? extends Annotation> annotationType, ScopeBinding scope) {
  throw new UnsupportedOperationException();
}
 
Example 16
Project: guice-old   File: InheritingState.java   Source Code and License 4 votes vote down vote up
public ScopeBinding getScopeBinding(Class<? extends Annotation> annotationType) {
  ScopeBinding scopeBinding = scopes.get(annotationType);
  return scopeBinding != null ? scopeBinding : parent.getScopeBinding(annotationType);
}
 
Example 17
Project: guice-old   File: InheritingState.java   Source Code and License 4 votes vote down vote up
public void putScopeBinding(Class<? extends Annotation> annotationType, ScopeBinding scope) {
  scopes.put(annotationType, scope);
}
 
Example 18
Project: guice-old   File: State.java   Source Code and License 4 votes vote down vote up
public ScopeBinding getScopeBinding(Class<? extends Annotation> scopingAnnotation) {
  return null;
}
 
Example 19
Project: guice-old   File: State.java   Source Code and License 4 votes vote down vote up
public void putScopeBinding(Class<? extends Annotation> annotationType, ScopeBinding scope) {
  throw new UnsupportedOperationException();
}
 
Example 20
Project: guice-old   File: Errors.java   Source Code and License 4 votes vote down vote up
public Errors duplicateScopes(ScopeBinding existing,
    Class<? extends Annotation> annotationType, Scope scope) {
  return addMessage("Scope %s is already bound to %s at %s.%n Cannot bind %s.",
      existing.getScope(), annotationType, existing.getSource(), scope);
}
 
Example 21
Project: guice-old   File: WeakKeySetTest.java   Source Code and License 4 votes vote down vote up
public ScopeBinding getScopeBinding(Class<? extends Annotation> scopingAnnotation) {
  return null;
}
 
Example 22
Project: guice-old   File: WeakKeySetTest.java   Source Code and License 4 votes vote down vote up
public void putScopeBinding(Class<? extends Annotation> annotationType, ScopeBinding scope) {
  throw new UnsupportedOperationException();
}
 
Example 23
Project: guice   File: State.java   Source Code and License votes vote down vote up
ScopeBinding getScopeBinding(Class<? extends Annotation> scopingAnnotation); 
Example 24
Project: guice   File: State.java   Source Code and License votes vote down vote up
void putScopeBinding(Class<? extends Annotation> annotationType, ScopeBinding scope); 
Example 25
Project: guice-old   File: State.java   Source Code and License votes vote down vote up
ScopeBinding getScopeBinding(Class<? extends Annotation> scopingAnnotation); 
Example 26
Project: guice-old   File: State.java   Source Code and License votes vote down vote up
void putScopeBinding(Class<? extends Annotation> annotationType, ScopeBinding scope);