All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.google.inject.internal.ScopeBindingProcessor Maven / Gradle / Ivy

package com.google.inject.internal;

import com.google.inject.Scope;
import com.google.inject.spi.ScopeBinding;

import java.lang.annotation.Annotation;

import static com.google.common.base.Preconditions.checkNotNull;

/**
 * Handles {@code Binder.bindScope} commands.
 *
 */
final class ScopeBindingProcessor extends AbstractProcessor {

    ScopeBindingProcessor(Errors errors) {
        super(errors);
    }

    @Override
    public Boolean visit(ScopeBinding command) {
        Scope scope = checkNotNull(command.getScope(), "scope");
        Class 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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy