@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; }
@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; }
@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; }
@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(); }
/** * 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; }
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(); }
@Override public V visit(ScopeBinding binding) { return message(binding, "Binding scope annotation " + binding.getAnnotationType() + " to scope " + binding.getScope()); }
@Override public ScopeBinding getScopeBinding(Class<? extends Annotation> annotationType) { ScopeBinding scopeBinding = scopes.get(annotationType); return scopeBinding != null ? scopeBinding : parent.getScopeBinding(annotationType); }
@Override public void putScopeBinding(Class<? extends Annotation> annotationType, ScopeBinding scope) { scopes.put(annotationType, scope); }
@Override public ScopeBinding getScopeBinding(Class<? extends Annotation> scopingAnnotation) { return null; }
@Override public void putScopeBinding( Class<? extends Annotation> annotationType, ScopeBinding scope) { throw new UnsupportedOperationException(); }
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); }
@Override public void putScopeBinding(Class<? extends Annotation> annotationType, ScopeBinding scope) { throw new UnsupportedOperationException(); }
public ScopeBinding getScopeBinding(Class<? extends Annotation> annotationType) { ScopeBinding scopeBinding = scopes.get(annotationType); return scopeBinding != null ? scopeBinding : parent.getScopeBinding(annotationType); }
public void putScopeBinding(Class<? extends Annotation> annotationType, ScopeBinding scope) { scopes.put(annotationType, scope); }
public ScopeBinding getScopeBinding(Class<? extends Annotation> scopingAnnotation) { return null; }
public void putScopeBinding(Class<? extends Annotation> annotationType, ScopeBinding scope) { throw new UnsupportedOperationException(); }
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); }
ScopeBinding getScopeBinding(Class<? extends Annotation> scopingAnnotation);
void putScopeBinding(Class<? extends Annotation> annotationType, ScopeBinding scope);