public final class BindingSourceRestriction
extends java.lang.Object
RestrictedBindingSource
.
Enforcement happens in two phases:
BindingSourceRestriction.PermitMapConstruction
encapsulates this process, and the BindingSourceRestriction.PermitMap
is the end
result.
check(com.google.inject.internal.GuiceInternal, java.util.List<com.google.inject.spi.Element>)
,
which uses the BindingSourceRestriction.PermitMap
(s) built during Binder configuration.
Note: None of this is thread-safe because it's only used while the Injector is being built, which happens on a single thread.
Modifier and Type | Class and Description |
---|---|
(package private) static interface |
BindingSourceRestriction.PermitMap
Mapping between an element source and its permit annotations.
|
(package private) static class |
BindingSourceRestriction.PermitMapConstruction
Builds the map from each module to all the permit annotations on its module stack.
|
Modifier and Type | Field and Description |
---|---|
private static java.util.logging.Logger |
logger |
Modifier | Constructor and Description |
---|---|
private |
BindingSourceRestriction() |
Modifier and Type | Method and Description |
---|---|
private static java.util.Optional<Message> |
check(Binding<?> binding) |
private static com.google.common.collect.ImmutableList<Message> |
check(Element element) |
static com.google.common.collect.ImmutableList<Message> |
check(GuiceInternal guiceInternal,
java.util.List<Element> elements)
Returns all the restriction violations found on the given Module Elements, as error messages.
|
private static com.google.common.collect.ImmutableList<Message> |
check(java.util.List<Element> elements) |
private static void |
clear(Element element) |
private static void |
clear(ElementSource elementSource) |
private static java.lang.Iterable<java.lang.String> |
getAllModules(ElementSource elementSource) |
private static com.google.common.collect.ImmutableSet<java.lang.Class<? extends java.lang.annotation.Annotation>> |
getAllPermits(ElementSource elementSource)
Get all permits on the element source chain.
|
static java.util.Optional<java.lang.String> |
getMissingImplementationSuggestion(GuiceInternal guiceInternal,
Key<?> key)
Returns a suggestion for how a restricted binding should be created in case it's missing.
|
private static java.util.stream.Stream<java.lang.Class<? extends java.lang.annotation.Annotation>> |
getPermits(java.lang.Class<?> clazz) |
private static RestrictedBindingSource |
getRestriction(Key<?> key) |
private static java.lang.String |
getViolationMessage(Key<?> key,
java.lang.String explanation,
com.google.common.collect.ImmutableSet<java.lang.Class<? extends java.lang.annotation.Annotation>> acceptablePermits,
boolean annotationRestricted) |
private static boolean |
isExempt(ElementSource elementSource,
java.lang.String exemptModulesRegex) |
public static java.util.Optional<java.lang.String> getMissingImplementationSuggestion(GuiceInternal guiceInternal, Key<?> key)
public static com.google.common.collect.ImmutableList<Message> check(GuiceInternal guiceInternal, java.util.List<Element> elements)
Note: Intended to be used on Module Elements, not Injector Elements, ie. the result of
Elements.getElements(com.google.inject.Module...)
not Injector.getElements
. The Module Elements this check
cares about are:
ElementSource
(with
a Module Stack), unlike Injector Bindings, which may be implicit and bereft of an
ElementSource.
PrivateElements
, which represent the recursive case of this check. They contain a
list of elements that this check is recursively called on.
private static com.google.common.collect.ImmutableList<Message> check(java.util.List<Element> elements)
private static java.lang.String getViolationMessage(Key<?> key, java.lang.String explanation, com.google.common.collect.ImmutableSet<java.lang.Class<? extends java.lang.annotation.Annotation>> acceptablePermits, boolean annotationRestricted)
private static com.google.common.collect.ImmutableSet<java.lang.Class<? extends java.lang.annotation.Annotation>> getAllPermits(ElementSource elementSource)
private static boolean isExempt(ElementSource elementSource, java.lang.String exemptModulesRegex)
private static java.lang.Iterable<java.lang.String> getAllModules(ElementSource elementSource)
private static void clear(Element element)
private static void clear(ElementSource elementSource)
private static RestrictedBindingSource getRestriction(Key<?> key)
private static java.util.stream.Stream<java.lang.Class<? extends java.lang.annotation.Annotation>> getPermits(java.lang.Class<?> clazz)