java.lang.Object
it.rebirthproject.ufoeb.services.ListenerMethodFinder
The
ListenerMethodFinder
is a service used to retrieve registered
listeners methods annotated with Listen
and to store them inside the
MemoryState
-
Field Summary
Modifier and TypeFieldDescriptionprivate static final int
In newer class files, compilers may add methods.private static final String
A default empty inheritance package frontier pathprivate final String
Sets the package used to stop the iteration over classes while using event inheritance.private final boolean
This parameter should be used when you want to use inheritance over a listener and all its superclasses.private static final int
In newer class files, compilers may add methods.private static final int
In newer class files, compilers may add methods.private final boolean
If a registering listener does not have anyListen
annotated method or, in case of event inheritance enabled, also its super classes or interfaces does not have anyListen
annotated method, then anEventBusException
is thrown.private final boolean
if set then anEventBusException
is thrown when an invalidListen
annotated method is found in a Listener.private final boolean
This set the usage of Lambdafactory instead of standard java reflection -
Constructor Summary
ConstructorDescriptionListenerMethodFinder
(boolean listenerSuperclassInheritance, boolean throwNotValidMethodException, boolean throwNoListenerAnnotationException, boolean useLambdaFactoryInsteadOfStandardReflection, String inheritancePackageFrontierPath) Class constructor used to build a ListenerMethodFinder -
Method Summary
Modifier and TypeMethodDescriptionprivate Method[]
findAllMethods
(Class<?> clazz) This method finds all methods defined in a given class.void
findListenerMethods
(Object listenerToRegister, MemoryState memoryState) Method used to retrieve all the listener's methods annotated with theListen
annotation and to update theMemoryState
accordingly.private boolean
isClassProcessableByPackage
(String className) This method is used to check if the listener class is processable analyzing its package.
-
Field Details
-
BRIDGE
private static final int BRIDGEIn newer class files, compilers may add methods. Those are called bridge or synthetic methods. UfoEventBus must ignore both. There modifiers are not public but defined in the Java class file format:- See Also:
-
SYNTHETIC
private static final int SYNTHETICIn newer class files, compilers may add methods. Those are called bridge or synthetic methods. UfoEventBus must ignore both. There modifiers are not public but defined in the Java class file format:- See Also:
-
MODIFIERS_IGNORE
private static final int MODIFIERS_IGNOREIn newer class files, compilers may add methods. Those are called bridge or synthetic methods. UfoEventBus must ignore both. There modifiers are not public but defined in the Java class file format:- See Also:
-
EMPTY_INHERITANCE_PACKAGE_FRONTIER_PATH
A default empty inheritance package frontier path- See Also:
-
listenerSuperclassInheritance
private final boolean listenerSuperclassInheritanceThis parameter should be used when you want to use inheritance over a listener and all its superclasses. Enabling it will let the bus look for all listeners' methods considering also all their superclasses methods. The default value is to look for only the listener's class methods. -
throwNotValidMethodException
private final boolean throwNotValidMethodExceptionif set then anEventBusException
is thrown when an invalidListen
annotated method is found in a Listener. -
throwNoListenerAnnotationException
private final boolean throwNoListenerAnnotationExceptionIf a registering listener does not have anyListen
annotated method or, in case of event inheritance enabled, also its super classes or interfaces does not have anyListen
annotated method, then anEventBusException
is thrown. -
useLambdaFactoryInsteadOfStandardReflection
private final boolean useLambdaFactoryInsteadOfStandardReflectionThis set the usage of Lambdafactory instead of standard java reflection -
inheritancePackageFrontierPath
Sets the package used to stop the iteration over classes while using event inheritance. If a class belongs to the set package then the iteration stops. This parameter must be used only when event inheritance policy is enabled otherwise it is useless even if set.
-
-
Constructor Details
-
ListenerMethodFinder
public ListenerMethodFinder(boolean listenerSuperclassInheritance, boolean throwNotValidMethodException, boolean throwNoListenerAnnotationException, boolean useLambdaFactoryInsteadOfStandardReflection, String inheritancePackageFrontierPath) Class constructor used to build a ListenerMethodFinder- Parameters:
listenerSuperclassInheritance
- Parameter used to initialize the attributelistenerSuperclassInheritance
throwNotValidMethodException
- Parameter used to initialize the attributethrowNotValidMethodException
throwNoListenerAnnotationException
- Parameter used to initialize the attributethrowNoListenerAnnotationException
useLambdaFactoryInsteadOfStandardReflection
- Parameter used to initialize the attributeuseLambdaFactoryInsteadOfStandardReflection
inheritancePackageFrontierPath
- Parameter used to initialize the attributeinheritancePackageFrontierPath
-
-
Method Details
-
findListenerMethods
public void findListenerMethods(Object listenerToRegister, MemoryState memoryState) throws EventBusException Method used to retrieve all the listener's methods annotated with theListen
annotation and to update theMemoryState
accordingly.- Parameters:
listenerToRegister
- TheListen
annotated methods' listener.memoryState
- The eventbusMemoryState
- Throws:
EventBusException
- is thrown if some exception occurs during the execution of this method
-
isClassProcessableByPackage
This method is used to check if the listener class is processable analyzing its package. There are two methods: - the check over a given inheritance frontier path package (for example the package of the application that uses theEventBus
). - the check over hardcoded basic java packages (that can depends even on Android platform). This method is used only when the frontier path is not specified.- Parameters:
className
- The listener class- Returns:
- A boolean that states if the loop must continue or not.
-
findAllMethods
This method finds all methods defined in a given class.- Parameters:
clazz
- The given class to search for methods.- Returns:
- The methods found in the given class.
- Throws:
EventBusException
- If the reflection raises an exception, this will be wrapped into anEventBusException
-