Package io.jmix.flowui.sys.autowire
Class AutowireUtils
java.lang.Object
io.jmix.flowui.sys.autowire.AutowireUtils
Helper class for component dependencies autowiring.
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
assignValue
(AnnotatedElement element, Object value, com.vaadin.flow.component.Component component) Assigns the passed value to a component field or method.static <A extends Annotation>
intcompareMethods
(ReflectionCacheManager.AnnotatedMethod<A> am1, ReflectionCacheManager.AnnotatedMethod<A> am2) Compares twoReflectionCacheManager.AnnotatedMethod
by class name,Order
annotation value, and method name.static <A extends Annotation>
ReflectionCacheManager.AnnotatedMethod<A>createAnnotatedMethod
(Class<A> annotationClass, Method method) CreatesReflectionCacheManager.AnnotatedMethod
instance based on the passedannotationClass
andMethod
instance.static Object
createInstallHandler
(Class<?> callerClass, Class<?> targetObjectType, com.vaadin.flow.component.Component component, Method method) Created proxy instance for install method handler.static Object
findMethodTarget
(com.vaadin.flow.component.Composite<?> composite, String targetId, BiFunction<com.vaadin.flow.component.Component, String, Optional<com.vaadin.flow.component.Component>> componentFinder) Finds the target of the annotated method in passed composite by ID.static String
getAutowiringName
(ReflectionCacheManager.AutowireElement autowireElement) Gets the name of the field or setter method for the autowire element.static Class<?>
getAutowiringType
(ReflectionCacheManager.AutowireElement autowireElement) Gets the type of the field or setter method for the autowire element.static com.vaadin.flow.component.ComponentEventListener<?>
getComponentEventListener
(Class<?> callerClass, com.vaadin.flow.component.Component component, ReflectionCacheManager.AnnotatedMethod<Subscribe> annotatedMethod, Class<?> eventType, ReflectionCacheManager reflectionCacheManager) Creates a component event listener method using the factory if the component class has not been reloaded by hot-deploy, otherwise uses theMethodHandle
static Consumer<?>
getConsumerListener
(Class<?> callerClass, com.vaadin.flow.component.Component component, ReflectionCacheManager.AnnotatedMethod<Subscribe> annotatedMethod, Class<?> eventType, ReflectionCacheManager reflectionCacheManager) Creates a consumer listener method using the factory if the component class has not been reloaded by hot-deploy, otherwise uses theMethodHandle
static <A extends Annotation>
ObjectgetFragmentTargetInstance
(A annotation, Fragment<?> fragment, String targetId, Target targetType) Find the target for the annotated method is passed fragment component by targetType and targetId.static MethodHandle
getInstallTargetSetterMethod
(Install annotation, com.vaadin.flow.component.Component component, Class<?> instanceClass, Method provideMethod, ReflectionCacheManager reflectionCacheManager) Finds a corresponding setter method for install annotation.getOverrideHierarchy
(Method method) Returns the override hierarchy of the passed method.static com.vaadin.flow.component.HasValue.ValueChangeListener<?>
getValueChangeEventListener
(Class<?> callerClass, com.vaadin.flow.component.Component component, ReflectionCacheManager.AnnotatedMethod<Subscribe> annotatedMethod, Class<?> eventType, ReflectionCacheManager reflectionCacheManager) Creates a component value change listener method using the factory if the component class has not been reloaded by hot-deploy, otherwise uses theMethodHandle
static Object
getViewSubscribeTargetInstance
(View<?> view, String targetId, Target targetType) Find the target fot theSubscribe
annotated method in passed view by targetType and targetId.static <A extends Annotation>
ObjectgetViewTargetInstance
(A annotation, View<?> view, String targetId, Target targetType) Finds the target for the annotated method in passed view by targetType and targetId.
-
Method Details
-
findMethodTarget
@Nullable public static Object findMethodTarget(com.vaadin.flow.component.Composite<?> composite, String targetId, BiFunction<com.vaadin.flow.component.Component, String, Optional<com.vaadin.flow.component.Component>> componentFinder) Finds the target of the annotated method in passed composite by ID.- Parameters:
composite
- composite for searchtargetId
- target IDcomponentFinder
- hook to find components in the composite- Returns:
- found target object or
null
if target no found - Throws:
IllegalStateException
- if the view content is not a container
-
getViewTargetInstance
@Nullable public static <A extends Annotation> Object getViewTargetInstance(A annotation, View<?> view, @Nullable String targetId, Target targetType) Finds the target for the annotated method in passed view by targetType and targetId.- Type Parameters:
A
- type of the annotation- Parameters:
annotation
- annotation of the method for which target will be foundview
- view for searchtargetId
- target IDtargetType
- type of the target- Returns:
- found target object or
null
if target not found - Throws:
UnsupportedOperationException
- if the targetId isnull
and the targetType is notTarget.COMPONENT
,Target.CONTROLLER
orTarget.DATA_CONTEXT
-
getViewSubscribeTargetInstance
@Nullable public static Object getViewSubscribeTargetInstance(View<?> view, @Nullable String targetId, Target targetType) Find the target fot theSubscribe
annotated method in passed view by targetType and targetId.- Parameters:
view
- view for searchtargetId
- target IDtargetType
- type of the target- Returns:
- found target object or
null
if target not found - Throws:
UnsupportedOperationException
- if the targetId isnull
and the targetType is notTarget.COMPONENT
,Target.CONTROLLER
orTarget.DATA_CONTEXT
-
getFragmentTargetInstance
@Nullable public static <A extends Annotation> Object getFragmentTargetInstance(A annotation, Fragment<?> fragment, @Nullable String targetId, Target targetType) Find the target for the annotated method is passed fragment component by targetType and targetId.- Type Parameters:
A
- type of the annotation- Parameters:
annotation
- annotation of the method for which target will be foundfragment
- fragment for searchtargetId
- target IDtargetType
- type of the target- Returns:
- found target object or null if target not found
- Throws:
UnsupportedOperationException
- if the target is not supported
-
createAnnotatedMethod
@Nullable public static <A extends Annotation> ReflectionCacheManager.AnnotatedMethod<A> createAnnotatedMethod(Class<A> annotationClass, Method method) CreatesReflectionCacheManager.AnnotatedMethod
instance based on the passedannotationClass
andMethod
instance.- Type Parameters:
A
- type of the annotation- Parameters:
annotationClass
- the annotation class with which the method should be annotatedmethod
- the method to search for annotation- Returns:
ReflectionCacheManager.AnnotatedMethod
instance ornull
if the passed method doesn't have required annotation- Throws:
RuntimeException
- if it fails to create a method handle
-
compareMethods
public static <A extends Annotation> int compareMethods(ReflectionCacheManager.AnnotatedMethod<A> am1, ReflectionCacheManager.AnnotatedMethod<A> am2) Compares twoReflectionCacheManager.AnnotatedMethod
by class name,Order
annotation value, and method name. Can be used as a sort comparator.- Type Parameters:
A
- type of the annotation- Parameters:
am1
- firstReflectionCacheManager.AnnotatedMethod
for comparisonam2
- secondReflectionCacheManager.AnnotatedMethod
for comparison- Returns:
- the value
0
if the first annotated method is equal to the second one; a value less than0
if the first annotated method is less by comparison logic; and a value greater than0
if the first annotated method is greater by comparison logic
-
getOverrideHierarchy
Returns the override hierarchy of the passed method.- Parameters:
method
- method to introspect its hierarchy- Returns:
- set of overridden methods
-
getAutowiringName
Gets the name of the field or setter method for the autowire element.- Parameters:
autowireElement
- the element to find for a name for autowiring- Returns:
- the name for autowiring
- Throws:
IllegalStateException
- if the search target is not a field or setter method
-
getAutowiringType
Gets the type of the field or setter method for the autowire element.- Parameters:
autowireElement
- the element to find for a type for autowiring- Returns:
- the type for autowiring
- Throws:
IllegalStateException
- if the target method doesn't have only a parameter or the autowire element is not a field or setter method
-
assignValue
public static void assignValue(AnnotatedElement element, Object value, com.vaadin.flow.component.Component component) Assigns the passed value to a component field or method.- Parameters:
element
- annotated element that should be autowired, can be a field or setter methodvalue
- value to be setcomponent
- the component for which it is necessary to assign a value to the element- Throws:
RuntimeException
- if it is not possible to assign value to a field or setter method
-
getComponentEventListener
public static com.vaadin.flow.component.ComponentEventListener<?> getComponentEventListener(Class<?> callerClass, com.vaadin.flow.component.Component component, ReflectionCacheManager.AnnotatedMethod<Subscribe> annotatedMethod, Class<?> eventType, ReflectionCacheManager reflectionCacheManager) Creates a component event listener method using the factory if the component class has not been reloaded by hot-deploy, otherwise uses theMethodHandle
- Parameters:
callerClass
- caller classcomponent
- owner class for target component event listener method handleannotatedMethod
- annotated methodeventType
- event classreflectionCacheManager
- reflection cache manager to get a method factory- Returns:
- lambda-proxy for listener
- See Also:
-
getValueChangeEventListener
public static com.vaadin.flow.component.HasValue.ValueChangeListener<?> getValueChangeEventListener(Class<?> callerClass, com.vaadin.flow.component.Component component, ReflectionCacheManager.AnnotatedMethod<Subscribe> annotatedMethod, Class<?> eventType, ReflectionCacheManager reflectionCacheManager) Creates a component value change listener method using the factory if the component class has not been reloaded by hot-deploy, otherwise uses theMethodHandle
- Parameters:
callerClass
- caller classcomponent
- owner class for target component value change event listener method handleannotatedMethod
- annotated methodeventType
- event classreflectionCacheManager
- reflection cache manager to get a method factory- Returns:
- lambda-proxy for listener
- See Also:
-
getConsumerListener
public static Consumer<?> getConsumerListener(Class<?> callerClass, com.vaadin.flow.component.Component component, ReflectionCacheManager.AnnotatedMethod<Subscribe> annotatedMethod, Class<?> eventType, ReflectionCacheManager reflectionCacheManager) Creates a consumer listener method using the factory if the component class has not been reloaded by hot-deploy, otherwise uses theMethodHandle
- Parameters:
callerClass
- caller classcomponent
- owner class for target consumer listener method handleannotatedMethod
- annotated methodeventType
- event classreflectionCacheManager
- reflection cache manager to get a method factory- Returns:
- lambda-proxy for listener
- See Also:
-
getInstallTargetSetterMethod
public static MethodHandle getInstallTargetSetterMethod(Install annotation, com.vaadin.flow.component.Component component, Class<?> instanceClass, Method provideMethod, ReflectionCacheManager reflectionCacheManager) Finds a corresponding setter method for install annotation.- Parameters:
annotation
- annotation for searchcomponent
- origin componentinstanceClass
- class to search annotationprovideMethod
- provideMethodreflectionCacheManager
- reflection cache manager to get target install method- Returns:
- setter method handle
-
createInstallHandler
public static Object createInstallHandler(Class<?> callerClass, Class<?> targetObjectType, com.vaadin.flow.component.Component component, Method method) Created proxy instance for install method handler.- Parameters:
callerClass
- caller classtargetObjectType
- target object typecomponent
- component to be passedmethod
- method to be invoked- Returns:
- proxy instance for install handler
-