ExpressionPointcut class final

A pointcut written as an AspectJ-style expression, the syntax of the @Before / @Around / ... annotations.

Aspects use it behind the scenes: each advice annotation's string becomes one. Create one yourself for a DefaultPointcutAdvisor bean, to select members by name, type, annotation or bean name without writing an AopPointcut class. The expression is parsed at once; an invalid one throws a FormatException with the reason.

Type and name patterns use simple names: Dart has libraries, not Java packages, so com.x.Service means Service, and a package wildcard such as com.x..* is rejected rather than matching everything. * matches any characters in a name, Type+ means the type and its subtypes, and type arguments and ? are ignored (Future<int> matches Future). The designators:

  • execution([modifiers] ret [Type.]name(params)) selects methods (not getters or setters) by return type, declaring type, name and parameters. In the parameters, .. stands for any number and * for exactly one. The modifiers are public, protected (members marked @protected) and private (never matches), each optionally negated with !. A throws clause is rejected, since Dart methods declare no exceptions.
  • within(TypePattern) selects every member whose body is in a matching class: the bean class, or the superclass or mixin it inherits the member from.
  • target(Type) and this(Type) select every member of beans whose class is that type or a subtype.
  • args(types) selects members by their parameters (.. for any number): the declared type, or the runtime type of the argument when typeTests knows the type.
  • @args(Annotation, ..) selects calls whose arguments' runtime classes carry the annotations (through argumentAnnotations).
  • bean(namePattern) selects every member of beans with that name, an alias or a qualifier value.
  • @annotation(Name) selects members carrying the annotation; @within(Name) members whose body is in a class carrying it; @target(Name) members of beans whose class carries it.
  • name() refers to a named pointcut of the same aspect (or of owner), Type.name() to one of another class.

Designators combine with && / and, || / or, ! / not and parentheses.

With bindings (written by the generator for advice parameters), a lowercase identifier in @annotation(x), @within(x), @target(x), this(x), target(x), args(...) or @args(...) names an advice parameter, which receives the annotation, the proxy, the target or the argument (bind). Such an expression is also checked on every call.

// Logs the calls of the services, except their slow* methods.
final pointcut = ExpressionPointcut(
  'service() && !execution(* *.slow*(..))',
  namedPointcuts: {'service': 'within(*Service) || @within(Service)'},
);
DefaultPointcutAdvisor(pointcut, LoggingInterceptor());

// Other expressions.
ExpressionPointcut('execution(Future<int> Calculator.slowAdd(int, *))');
ExpressionPointcut('bean(echoShouter) or @annotation(Timed)');
ExpressionPointcut('within(Repository+)');

Spring (Java):

AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
pointcut.setExpression(
    "within(com.example..*Service) && !execution(* *.slow*(..))");
new DefaultPointcutAdvisor(pointcut, new LoggingInterceptor());
Implemented types

Constructors

ExpressionPointcut(String expression, {Map<String, String> namedPointcuts = const {}, Map<String, AdviceBinding> bindings = const {}, Map<String, bool Function(Object? value)> typeTests = const {}, Map<String, Object? Function(Object? value)> argumentAnnotations = const {}, String? owner})
Parses expression; throws a FormatException when it is invalid, or when a binding is not used by it.

Properties

bindings → Map<String, AdviceBinding>
The advice parameters this expression binds, by name; empty for an expression written in code.
final
expression → String
The expression as written.
final
hashCode → int
The hash code for this object.
no setterinherited
isRuntime → bool
Whether the expression binds advice parameters or tests arguments, so the startup match is not enough and every call is checked too (bind).
no setter
owner → String?
The class (aspect or pointcut holder) whose named pointcuts an unqualified name() refers to; null outside an aspect.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

bind(MethodInvocation invocation, {String beanName = '', List<String> beanAliases = const [], List<String> introducedTypes = const []}) → Map<String, Object?>?
Checks one call against the expression and returns the values of the bound advice parameters (empty when nothing is bound), or null when the call does not match, such as args(id) with an argument of another type. beanName, beanAliases and introducedTypes are as in matchesBean.
matches(MethodSignature signature, String beanName) → bool
Whether the member can match, decided once at startup; false only when no call of the member can match. Parts that depend on the arguments are assumed to match.
override
matchesBean(MethodSignature signature, String beanName, List<String> beanAliases, {List<String> introducedTypes = const []}) → bool
Like matches, with the bean's aliases and qualifier values for bean(...) (Spring's BeanFactoryAnnotationUtils.isQualifierMatch) and the interfaces @DeclareParents adds to the bean's proxy (introducedTypes) for this(...).
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
override

Operators

operator ==(Object other) → bool
The equality operator.
inherited