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 voidassignValue(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.AnnotatedMethodby class name,Orderannotation value, and method name.static <A extends Annotation>
ReflectionCacheManager.AnnotatedMethod<A>createAnnotatedMethod(Class<A> annotationClass, Method method) CreatesReflectionCacheManager.AnnotatedMethodinstance based on the passedannotationClassandMethodinstance.static ObjectcreateInstallHandler(Class<?> callerClass, Class<?> targetObjectType, com.vaadin.flow.component.Component component, Method method) Created proxy instance for install method handler.static ObjectfindMethodTarget(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 StringgetAutowiringName(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 theMethodHandlestatic 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 theMethodHandlestatic <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 MethodHandlegetInstallTargetSetterMethod(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 theMethodHandlestatic <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
nullif 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
nullif target not found - Throws:
UnsupportedOperationException- if the targetId isnulland the targetType is notTarget.COMPONENT,Target.CONTROLLERorTarget.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.AnnotatedMethodinstance based on the passedannotationClassandMethodinstance.- 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.AnnotatedMethodinstance ornullif 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.AnnotatedMethodby class name,Orderannotation value, and method name. Can be used as a sort comparator.- Type Parameters:
A- type of the annotation- Parameters:
am1- firstReflectionCacheManager.AnnotatedMethodfor comparisonam2- secondReflectionCacheManager.AnnotatedMethodfor comparison- Returns:
- the value
0if the first annotated method is equal to the second one; a value less than0if the first annotated method is less by comparison logic; and a value greater than0if 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
-