public interface AppliesToFilter
AppliesTo filters are one of the driving technologies in Polygene. They allow you to apply fragments (Mixins, Concerns, SideEffects), often generic ones, depending on the context that they are evaluated under. This mechanism is heavily used internally in Polygene to achieve many other features.
The starting point is the basic use of AppliesToFilter, where the @AppliesTo annotation is given an AppliesToFilter implementation as an argument, for instance at a Mixin implementation;
@AppliesTo( MyAppliesToFilter.class )
public class SomeMixin
implements InvocationHandler
{
}
public class MyAppliesToFilter
implements AppliesToFilter
{
public boolean appliesTo( Method method, Class<?> mixin, Class<?> compositeType, Class<?> fragmentClass )
{
return method.getName().startsWith( "my" );
}
}
In the case above, the generic mixin will only be applied to the methods that that is defined by the AppliesToFilter. This is the primary way to define limits on the application of generic fragments, since especially mixins are rarely applied to all methods.
Modifier and Type | Field and Description |
---|---|
static AppliesToFilter |
ALWAYS
This is an internal AppliesToFilter which is assigned if no other AppliesToFilters are found for a given
fragment.
|
Modifier and Type | Method and Description |
---|---|
boolean |
appliesTo(Method method,
Class<?> mixin,
Class<?> compositeType,
Class<?> fragmentClass)
Check if the Fragment should be applied or not.
|
static final AppliesToFilter ALWAYS
There is no reason for user code to use this AppliesToFilter directly, and should be perceived as an internal class in Polygene.
boolean appliesTo(Method method, Class<?> mixin, Class<?> compositeType, Class<?> fragmentClass)
method
- method that is invokedmixin
- mixin implementation for the methodcompositeType
- composite typefragmentClass
- fragment that is being applies