Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support pattern matching for method names in ControlFlowPointcut #31435

Closed
sbrannen opened this issue Oct 15, 2023 · 1 comment
Closed

Support pattern matching for method names in ControlFlowPointcut #31435

sbrannen opened this issue Oct 15, 2023 · 1 comment
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@sbrannen
Copy link
Member

Overview

To address the lack of support for pattern matching for methods names in ControlFlowPointcut as discussed in #27187, we have decided to introduce such support in ControlFlowPointcut analogous to the support already available in NameMatchMethodPointcut.

Specifically, we intend to introduce a protected method along the lines of NameMatchMethodPointcut#isMatch(String, String) which by default delegates to PatternMatchUtils.simpleMatch(String, String).

That will likely cover the most common use cases for pattern matching; however, users will still be able to extend ControlFlowPointcut and override isMatch(...) in order to support different styles of pattern matching such as regular expressions.

Related Issues

@sbrannen sbrannen added in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement labels Oct 15, 2023
@sbrannen sbrannen added this to the 6.1.0-RC2 milestone Oct 15, 2023
@sbrannen sbrannen self-assigned this Oct 15, 2023
@sbrannen sbrannen modified the milestones: 6.1.0-RC2, 6.1.x Oct 15, 2023
@sbrannen sbrannen modified the milestones: 6.1.x, 6.1.0 Oct 25, 2023
@sbrannen
Copy link
Member Author

Current work on this issue can be viewed in the following feature branch: main...sbrannen:spring-framework:issues/gh-31435-ControlFlowPointcut-pattern-matching

sbrannen added a commit to sbrannen/spring-framework that referenced this issue Oct 27, 2023
Prior to this commit, ControlFlowPointcut supported a single method
name which was matched exactly. Although it was possible to extend
ControlFlowPointcut to add support for pattern matching, it was a bit
cumbersome.

To address that, this commit introduces built-in pattern matching
support for method names in ControlFlowPointcut, analogous to the
pattern matching support in NameMatchMethodPointcut.

Specifically, a user can provide one or more method name patterns, and
the patterns will be matched against candidate method names using OR
semantics.

By default, the matching algorithm delegates to
PatternMatchUtils.simpleMatch(), but this can be overridden in
subclasses by overriding the new protected isMatch() method.

Closes spring-projectsgh-31435
sbrannen added a commit that referenced this issue Oct 28, 2023
Commit d3fba6d introduced built-in pattern matching support for
method names in ControlFlowPointcut; however, it was still cumbersome
to extend ControlFlowPointcut with support for regular expressions
instead of simple pattern matching.

To address that, this commit introduces a variant of isMatch() that
accepts the pattern index instead of the pre-resolved method name
pattern. The default implementation retrieves the method name pattern
from the methodNamePatterns field and delegates to isMatch(String, String).

Subclasses can override the new isMatch(String, int) method to support
regular expressions, as can be seen in the example
RegExControlFlowPointcut class in ControlFlowPointcutTests.

See gh-31435
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

1 participant