Package com.google.inject.spi
Class BindingSourceRestriction
java.lang.Object
com.google.inject.spi.BindingSourceRestriction
Contains abstractions for enforcing
RestrictedBindingSource
.
Enforcement happens in two phases:
- Data structures for enforcement are built during Binder configuration.
BindingSourceRestriction.PermitMapConstruction
encapsulates this process, and theBindingSourceRestriction.PermitMap
is the end result. - Restrictions are enforced by checking each binding for violations with
check(com.google.inject.internal.GuiceInternal, java.util.List<com.google.inject.spi.Element>)
, which uses theBindingSourceRestriction.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.
- Since:
- 5.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static interface
Mapping between an element source and its permit annotations.(package private) static final class
Builds the map from each module to all the permit annotations on its module stack. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic com.google.common.collect.ImmutableList<Message>
check
(GuiceInternal guiceInternal, 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>
private static com.google.common.collect.ImmutableList<Message>
private static void
private static void
clear
(ElementSource elementSource) getAllModules
(ElementSource elementSource) private static com.google.common.collect.ImmutableSet<Class<? extends Annotation>>
getAllPermits
(ElementSource elementSource) Get all permits on the element source chain.getMissingImplementationSuggestion
(GuiceInternal guiceInternal, Key<?> key) Returns a suggestion for how a restricted binding should be created in case it's missing.private static Stream<Class<? extends Annotation>>
getPermits
(Class<?> clazz) private static RestrictedBindingSource
getRestriction
(Key<?> key) private static String
getViolationMessage
(Key<?> key, String explanation, com.google.common.collect.ImmutableSet<Class<? extends Annotation>> acceptablePermits, boolean annotationRestricted) private static boolean
isExempt
(ElementSource elementSource, String exemptModulesRegex)
-
Field Details
-
logger
-
-
Constructor Details
-
BindingSourceRestriction
private BindingSourceRestriction()
-
-
Method Details
-
getMissingImplementationSuggestion
public static Optional<String> getMissingImplementationSuggestion(GuiceInternal guiceInternal, Key<?> key) Returns a suggestion for how a restricted binding should be created in case it's missing. -
check
public static com.google.common.collect.ImmutableList<Message> check(GuiceInternal guiceInternal, List<Element> elements) Returns all the restriction violations found on the given Module Elements, as error messages.Note: Intended to be used on Module Elements, not Injector Elements, ie. the result of
Elements.getElements(com.google.inject.Module...)
notInjector.getElements
. The Module Elements this check cares about are:- Module Bindings, which are always explicit and always have an
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.
- Module Bindings, which are always explicit and always have an
-
check
-
check
-
check
-
getViolationMessage
private static String getViolationMessage(Key<?> key, String explanation, com.google.common.collect.ImmutableSet<Class<? extends Annotation>> acceptablePermits, boolean annotationRestricted) -
getAllPermits
private static com.google.common.collect.ImmutableSet<Class<? extends Annotation>> getAllPermits(ElementSource elementSource) Get all permits on the element source chain. -
isExempt
-
getAllModules
-
clear
-
clear
-
getRestriction
-
getPermits
-