Package org.spincast.core.guice
Class GuiceModuleUtils
java.lang.Object
org.spincast.core.guice.GuiceModuleUtils
Utilities to inspect/manipulate
Guice modules.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionGuiceModuleUtils(com.google.inject.Module module) GuiceModuleUtils(com.google.inject.Module... modules) GuiceModuleUtils(Set<com.google.inject.Module> modules) -
Method Summary
Modifier and TypeMethodDescriptionstatic SpincastGuiceModuleBasecreateInterceptorModule(Class<?> toIntercept, Class<?> implementationClass, boolean ignoreMethodsAnnotatedWithInject) Creates a module that is going to intercept the calls to all methods defined in an object implementingtoInterceptand will call those ofimplementationClassinstead, if available.protected static StringcreateMethodeSignatureKey(Method method) <T> Class<? extends T>getBindingTarget(com.google.inject.Key<T> specificKey) Returns the target of the binding with the specified key.<T> Class<? extends T>getBindingTarget(Class<T> specificClass) Returns the target of the binding with the specified class/interface.getBoundClasses(Class<? extends T> parentType, com.google.inject.Key<?> specificKey) getBoundClassesExtending(Class<? extends T> parentType) Returns the bound classes that extend or implement the specifiedparentType.protected List<com.google.inject.spi.Element>protected com.google.inject.ModulebooleanisKeyBound(com.google.inject.Key<?> keyToCheck) Checks if a key is bound in the ModulebooleanisKeyBound(Class<?> clazz) Checks if a class is bound in the Modulestatic com.google.inject.ModuleremoveBindings(com.google.inject.Module module, Set<com.google.inject.Key<?>> keysToRemove) Remove bindings from a Module.
-
Field Details
-
logger
protected static final org.slf4j.Logger logger
-
-
Constructor Details
-
GuiceModuleUtils
public GuiceModuleUtils(com.google.inject.Module module) -
GuiceModuleUtils
-
GuiceModuleUtils
public GuiceModuleUtils(com.google.inject.Module... modules)
-
-
Method Details
-
getModule
protected com.google.inject.Module getModule() -
getElements
-
isKeyBound
Checks if a class is bound in the Module -
isKeyBound
public boolean isKeyBound(com.google.inject.Key<?> keyToCheck) Checks if a key is bound in the Module -
getBindingTarget
Returns the target of the binding with the specified key. This won't work if aProvideris used!- Returns:
- the class or
nullif not found.
-
getBindingTarget
Returns the target of the binding with the specified class/interface. This won't work if aProvideris used!- Returns:
- the class or
nullif not found.
-
getBoundClassesExtending
Returns the bound classes that extend or implement the specifiedparentType.IMPORTANT : This doesn't mean that the
parentTypeis actually used as a key in a binding, but that there is a binding for an class that extends/implementsparentType.This won't work if a
Provideris used! -
getBoundClasses
-
createInterceptorModule
public static SpincastGuiceModuleBase createInterceptorModule(Class<?> toIntercept, Class<?> implementationClass, boolean ignoreMethodsAnnotatedWithInject) Creates a module that is going to intercept the calls to all methods defined in an object implementingtoInterceptand will call those ofimplementationClassinstead, if available.This allows you, for example, to use a specific implementation for a
toInterceptbinding, even if an existing binding is done for a class extendingtoIntercept. This existing binding will still continue to use its original implementation for the methods that are not defined ontoInterceptbut will use the implementation speficied here for those that are.You can annotate a method with
DontInterceptto prevent it to be intercepted.Note that the
implementationClassbinding must have been done in other module.- Parameters:
ignoreMethodsAnnotatedWithInject- iftrue, methods from the intercepted class annotated withInjector withInjectwill be ignored (they won't be intercepted).
-
createMethodeSignatureKey
-
removeBindings
public static com.google.inject.Module removeBindings(com.google.inject.Module module, Set<com.google.inject.Key<?>> keysToRemove) Remove bindings from a Module.
-