Package io.jmix.flowui.sys.autowire
Class ReflectionCacheManager
java.lang.Object
io.jmix.flowui.sys.autowire.ReflectionCacheManager
Loads and caches data for a fields and methods that are used for autowiring.
Introspects the passed component for methods and fields that are annotated with UI system annotations. Also analyzes target classes for injection, collecting and caching data for methods-candidates for autowiring.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
static class
static class
static class
static class
static class
-
Field Summary
Modifier and TypeFieldDescriptionprotected final com.google.common.cache.LoadingCache<Class<?>,
ReflectionCacheManager.ComponentIntrospectionData> protected final Function<Class<?>,
MethodHandles.Lookup> protected final com.google.common.cache.Cache<MethodHandle,
MethodHandle> protected final com.google.common.cache.LoadingCache<Class<?>,
ReflectionCacheManager.TargetIntrospectionData> -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Clear underlying reflection caches.protected Class<?>
getActualTypeArgument
(Method targetTypedMethod) getAddListenerMethodsNotCached
(Method[] uniqueDeclaredMethods) getAllFields
(List<Class<?>> classes) protected List<ReflectionCacheManager.AutowireElement>
getAnnotatedAutowireElementsNotCached
(Class<?> componentClass, Method[] methods) protected List<ReflectionCacheManager.AnnotatedMethod<Install>>
getAnnotatedInstallMethodsNotCached
(Method[] uniqueDeclaredMethods) getAnnotatedListenerMethodsNotCached
(Method[] uniqueDeclaredMethods) protected <T extends Annotation>
List<ReflectionCacheManager.AnnotatedMethod<T>>getAnnotatedMethodsNotCached
(Class<T> annotationClass, Method[] uniqueDeclaredMethods, Predicate<Method> filter) protected List<ReflectionCacheManager.AnnotatedMethod<Subscribe>>
getAnnotatedSubscribeMethodsNotCached
(Method[] uniqueDeclaredMethods) protected List<ReflectionCacheManager.AnnotatedMethod<Supply>>
getAnnotatedSupplyMethodsNotCached
(Method[] uniqueDeclaredMethods) getAutowireElements
(Class<?> componentClass) Introspects component class if it has never introspected before and finds fields annotated byViewComponent
for autowiring.protected Class<?>
getComponentEventListenerMethodFactory
(Class<?> ownerClass, ReflectionCacheManager.AnnotatedMethod<Subscribe> annotatedMethod, Class<?> eventClass) Creates or gets from cache a method factory for component event listener methods.getComponentIntrospectionDataNotCached
(Class<?> viewClass) getConsumerMethodFactory
(Class<?> ownerClass, ReflectionCacheManager.AnnotatedMethod<Subscribe> annotatedMethod, Class<?> eventClass) Creates or gets from cache a method factory for consumer methods.getEventListenerMethodFactory
(Class<?> ownerClass, ReflectionCacheManager.AnnotatedMethod<Subscribe> annotatedMethod, String interfaceMethodName, Class<?> listenerClass, Class<?> eventClass) Creates or gets from cache a method factory for any event listener methods.getEventListenerMethods
(Class<?> componentClass) Introspects component class if it has never introspected before and finds methods annotated byEventListener
for autowiring.getInstallMethods
(Class<?> componentClass) Introspects component class if it has never introspected before and finds methods annotated byInstall
for autowiring.protected Map<String,
MethodHandle> getInstallTargetMethodsNotCached
(Method[] uniqueDeclaredMethods) getSubscribeMethods
(Class<?> componentClass) Introspects component class if it has never introspected before and finds methods annotated bySubscribe
for autowiring.getSupplyMethods
(Class<?> componentClass) Introspects component class if it has never introspected before and finds methods annotated bySupply
for autowiring.getSupplyTargetMethodsNotCached
(Method[] uniqueDeclaredMethods) getTargetAddListenerMethod
(Class<?> targetClass, Class<?> eventType, String methodName) Introspects target class if it has never introspected before and finds method suitable for adding an event handler of a specific type for autowiring.getTargetInstallMethod
(Class<?> targetClass, String methodName) Introspects target class if it has never introspected before and finds method with passed name which suitable for setting a handler for autowiring.getTargetIntrospectionDataNotCached
(Class<?> targetClass) getTargetSupplyMethod
(Class<?> targetClass, String methodName, Class<?> parameterType) Introspects target class if it has never introspected before and finds method with passed name and parameter type which suitable for setting a handler for autowiring.getValueChangeEventMethodFactory
(Class<?> ownerClass, ReflectionCacheManager.AnnotatedMethod<Subscribe> annotatedMethod, Class<?> eventClass) Creates or gets from cache a method factory for value change event methods.
-
Field Details
-
componentIntrospectionCache
protected final com.google.common.cache.LoadingCache<Class<?>,ReflectionCacheManager.ComponentIntrospectionData> componentIntrospectionCache -
targetIntrospectionCache
protected final com.google.common.cache.LoadingCache<Class<?>,ReflectionCacheManager.TargetIntrospectionData> targetIntrospectionCache -
lambdaMethodsCache
-
lambdaLookupProvider
-
-
Constructor Details
-
ReflectionCacheManager
public ReflectionCacheManager()
-
-
Method Details
-
getAutowireElements
Introspects component class if it has never introspected before and finds fields annotated byViewComponent
for autowiring.- Parameters:
componentClass
- component class to introspect- Returns:
- list of
ReflectionCacheManager.AutowireElement
-
getSubscribeMethods
public List<ReflectionCacheManager.AnnotatedMethod<Subscribe>> getSubscribeMethods(Class<?> componentClass) Introspects component class if it has never introspected before and finds methods annotated bySubscribe
for autowiring.- Parameters:
componentClass
- component class to introspect- Returns:
- list of
ReflectionCacheManager.AnnotatedMethod
-
getInstallMethods
public List<ReflectionCacheManager.AnnotatedMethod<Install>> getInstallMethods(Class<?> componentClass) Introspects component class if it has never introspected before and finds methods annotated byInstall
for autowiring.- Parameters:
componentClass
- composite class to introspect- Returns:
- list of
ReflectionCacheManager.AnnotatedMethod
-
getSupplyMethods
public List<ReflectionCacheManager.AnnotatedMethod<Supply>> getSupplyMethods(Class<?> componentClass) Introspects component class if it has never introspected before and finds methods annotated bySupply
for autowiring.- Parameters:
componentClass
- composite class to introspect- Returns:
- list of
ReflectionCacheManager.AnnotatedMethod
-
getEventListenerMethods
Introspects component class if it has never introspected before and finds methods annotated byEventListener
for autowiring.- Parameters:
componentClass
- composite class to introspect- Returns:
- list of
Method
-
getTargetAddListenerMethod
@Nullable public MethodHandle getTargetAddListenerMethod(Class<?> targetClass, Class<?> eventType, @Nullable String methodName) Introspects target class if it has never introspected before and finds method suitable for adding an event handler of a specific type for autowiring.- Parameters:
targetClass
- class to search for methodeventType
- type of the target event parametermethodName
- name of the target method- Returns:
- the found
MethodHandle
ornull
if the method is not found
-
getTargetInstallMethod
Introspects target class if it has never introspected before and finds method with passed name which suitable for setting a handler for autowiring.- Parameters:
targetClass
- class to search for methodmethodName
- name of the method- Returns:
- the found
MethodHandle
ornull
if the method is not found
-
getTargetSupplyMethod
@Nullable public MethodHandle getTargetSupplyMethod(Class<?> targetClass, String methodName, Class<?> parameterType) Introspects target class if it has never introspected before and finds method with passed name and parameter type which suitable for setting a handler for autowiring.- Parameters:
targetClass
- class to search for methodmethodName
- name of the methodparameterType
- parameter type of the parameter- Returns:
- the found
MethodHandle
ornull
if the method is not found
-
getConsumerMethodFactory
public MethodHandle getConsumerMethodFactory(Class<?> ownerClass, ReflectionCacheManager.AnnotatedMethod<Subscribe> annotatedMethod, Class<?> eventClass) Creates or gets from cache a method factory for consumer methods.- Parameters:
ownerClass
- owner class for target consumerannotatedMethod
- annotated methodeventClass
- event class- Returns:
- a factory to create consumer methods
-
getValueChangeEventMethodFactory
public MethodHandle getValueChangeEventMethodFactory(Class<?> ownerClass, ReflectionCacheManager.AnnotatedMethod<Subscribe> annotatedMethod, Class<?> eventClass) Creates or gets from cache a method factory for value change event methods.- Parameters:
ownerClass
- owner class for target value change event method handleannotatedMethod
- annotated methodeventClass
- event class- Returns:
- a factory to create value change event method handle
-
getComponentEventListenerMethodFactory
public MethodHandle getComponentEventListenerMethodFactory(Class<?> ownerClass, ReflectionCacheManager.AnnotatedMethod<Subscribe> annotatedMethod, Class<?> eventClass) Creates or gets from cache a method factory for component event listener methods.- Parameters:
ownerClass
- owner class for target component event listener method handleannotatedMethod
- annotated methodeventClass
- event class- Returns:
- a factory to create component event listener method handle
-
getEventListenerMethodFactory
public MethodHandle getEventListenerMethodFactory(Class<?> ownerClass, ReflectionCacheManager.AnnotatedMethod<Subscribe> annotatedMethod, String interfaceMethodName, Class<?> listenerClass, Class<?> eventClass) Creates or gets from cache a method factory for any event listener methods.- Parameters:
ownerClass
- owner class for target event listener method handleannotatedMethod
- annotated methodinterfaceMethodName
- name of the target interface methodlistenerClass
- listener classeventClass
- event class- Returns:
- a factory to create event listener method handle
-
clearCache
public void clearCache()Clear underlying reflection caches. -
getComponentIntrospectionDataNotCached
protected ReflectionCacheManager.ComponentIntrospectionData getComponentIntrospectionDataNotCached(Class<?> viewClass) -
getTargetIntrospectionDataNotCached
protected ReflectionCacheManager.TargetIntrospectionData getTargetIntrospectionDataNotCached(Class<?> targetClass) -
getAnnotatedAutowireElementsNotCached
protected List<ReflectionCacheManager.AutowireElement> getAnnotatedAutowireElementsNotCached(Class<?> componentClass, Method[] methods) -
getAnnotatedSubscribeMethodsNotCached
protected List<ReflectionCacheManager.AnnotatedMethod<Subscribe>> getAnnotatedSubscribeMethodsNotCached(Method[] uniqueDeclaredMethods) -
getAnnotatedInstallMethodsNotCached
protected List<ReflectionCacheManager.AnnotatedMethod<Install>> getAnnotatedInstallMethodsNotCached(Method[] uniqueDeclaredMethods) -
getAnnotatedSupplyMethodsNotCached
protected List<ReflectionCacheManager.AnnotatedMethod<Supply>> getAnnotatedSupplyMethodsNotCached(Method[] uniqueDeclaredMethods) -
getAnnotatedListenerMethodsNotCached
-
getAnnotatedMethodsNotCached
protected <T extends Annotation> List<ReflectionCacheManager.AnnotatedMethod<T>> getAnnotatedMethodsNotCached(Class<T> annotationClass, Method[] uniqueDeclaredMethods, Predicate<Method> filter) -
getAddListenerMethodsNotCached
protected Map<ReflectionCacheManager.SubscribeMethodSignature,MethodHandle> getAddListenerMethodsNotCached(Method[] uniqueDeclaredMethods) -
getInstallTargetMethodsNotCached
-
getSupplyTargetMethodsNotCached
protected Map<ReflectionCacheManager.SupplyMethodSignature,MethodHandle> getSupplyTargetMethodsNotCached(Method[] uniqueDeclaredMethods) -
getAutowiringAnnotationClass
-
getAllFields
-
getActualTypeArgument
-