Package com.google.inject.spi
Class BindingSourceRestriction
- java.lang.Object
-
- com.google.inject.spi.BindingSourceRestriction
-
public final class BindingSourceRestriction extends java.lang.ObjectContains abstractions for enforcingRestrictedBindingSource.Enforcement happens in two phases:
- Data structures for enforcement are built during Binder configuration.
BindingSourceRestriction.PermitMapConstructionencapsulates this process, and theBindingSourceRestriction.PermitMapis 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
- Data structures for enforcement are built during Binder configuration.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static interfaceBindingSourceRestriction.PermitMapMapping between an element source and its permit annotations.(package private) static classBindingSourceRestriction.PermitMapConstructionBuilds the map from each module to all the permit annotations on its module stack.
-
Field Summary
Fields Modifier and Type Field Description private static java.util.logging.Loggerlogger
-
Constructor Summary
Constructors Modifier Constructor Description privateBindingSourceRestriction()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static java.util.Optional<Message>check(Binding<?> binding)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(Element element)private static com.google.common.collect.ImmutableList<Message>check(java.util.List<Element> elements)private static voidclear(Element element)private static voidclear(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 RestrictedBindingSourcegetRestriction(Key<?> key)private static java.lang.StringgetViolationMessage(Key<?> key, java.lang.String explanation, com.google.common.collect.ImmutableSet<java.lang.Class<? extends java.lang.annotation.Annotation>> acceptablePermits, boolean annotationRestricted)private static booleanisExempt(ElementSource elementSource, java.lang.String exemptModulesRegex)
-
-
-
Method Detail
-
getMissingImplementationSuggestion
public 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.
-
check
public 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.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
private static com.google.common.collect.ImmutableList<Message> check(java.util.List<Element> elements)
-
getViolationMessage
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)
-
getAllPermits
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.
-
isExempt
private static boolean isExempt(ElementSource elementSource, java.lang.String exemptModulesRegex)
-
getAllModules
private static java.lang.Iterable<java.lang.String> getAllModules(ElementSource elementSource)
-
clear
private static void clear(Element element)
-
clear
private static void clear(ElementSource elementSource)
-
getRestriction
private static RestrictedBindingSource getRestriction(Key<?> key)
-
getPermits
private static java.util.stream.Stream<java.lang.Class<? extends java.lang.annotation.Annotation>> getPermits(java.lang.Class<?> clazz)
-
-