Search in sources :

Example 1 with ScopeBinding

use of com.google.inject.spi.ScopeBinding in project guice by google.

the class ScopeBindingProcessor method visit.

@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;
}
Also used : Scope(com.google.inject.Scope) ScopeBinding(com.google.inject.spi.ScopeBinding)

Example 2 with ScopeBinding

use of com.google.inject.spi.ScopeBinding in project guice by google.

the class Scoping method makeInjectable.

/**
   * 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;
}
Also used : ScopeBinding(com.google.inject.spi.ScopeBinding)

Example 3 with ScopeBinding

use of com.google.inject.spi.ScopeBinding in project roboguice by roboguice.

the class ScopeBindingProcessor method visit.

@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;
}
Also used : Scope(com.google.inject.Scope) ScopeBinding(com.google.inject.spi.ScopeBinding)

Example 4 with ScopeBinding

use of com.google.inject.spi.ScopeBinding in project roboguice by roboguice.

the class Scoping method makeInjectable.

/**
   * 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;
}
Also used : ScopeBinding(com.google.inject.spi.ScopeBinding)

Aggregations

ScopeBinding (com.google.inject.spi.ScopeBinding)4 Scope (com.google.inject.Scope)2