Skip to content

Commit fe29e73

Browse files
committed
Revise documentation for @AspectJ argument name resolution algorithm
Closes gh-30026
1 parent 50c3a62 commit fe29e73

File tree

1 file changed

+31
-27
lines changed

1 file changed

+31
-27
lines changed

framework-docs/src/docs/asciidoc/core/core-aop.adoc

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,31 +1535,31 @@ AspectJ APIs refer to parameter names as argument names.
15351535
Spring AOP uses the following `ParameterNameDiscoverer` implementations to determine
15361536
parameter names. Each discoverer will be given a chance to discover parameter names, and
15371537
the first successful discoverer wins. If none of the registered discoverers is capable
1538-
of determining parameter names, an `IllegalArgumentException` is thrown.
1538+
of determining parameter names, an exception will be thrown.
15391539

1540-
1541-
`KotlinReflectionParameterNameDiscoverer` :: Uses Kotlin reflection APIs if such APIs are
1542-
present on the classpath.
1543-
`StandardReflectionParameterNameDiscoverer` :: Uses the `java.lang.reflect.Parameter` API
1544-
available since Java 8. Requires that code be compiled with the `-parameters` flag for
1545-
`javac`. Recommended approach on Java 8+.
1546-
`LocalVariableTableParameterNameDiscoverer` :: Analyzes the local variable table available
1547-
in the byte code to determine parameter names from debug information. Requires that
1548-
code be compiled with debug symbols (`-g:vars` at a minimum). Deprecated as of Spring
1549-
Framework 6.0 for removal in Spring Framework 6.1 in favor of compiling code with
1550-
`-parameters`. Not supported in a GraalVM native image.
1551-
`AspectJAdviceParameterNameDiscoverer` :: Uses parameter names that have been explicitly
1540+
`AspectJAnnotationParameterNameDiscoverer` :: Uses parameter names that have been explicitly
15521541
specified by the user via the `argNames` attribute in the corresponding advice or
1553-
pointcut annotation. See the following section for details.
1542+
pointcut annotation. See <<aop-ataspectj-advice-params-names-explicit>> for details.
1543+
`KotlinReflectionParameterNameDiscoverer` :: Uses Kotlin reflection APIs to determine
1544+
parameter names. This discoverer is only used if such APIs are present on the classpath.
1545+
`StandardReflectionParameterNameDiscoverer` :: Uses the standard `java.lang.reflect.Parameter`
1546+
API to determine parameter names. Requires that code be compiled with the `-parameters`
1547+
flag for `javac`. Recommended approach on Java 8+.
1548+
`LocalVariableTableParameterNameDiscoverer` :: Analyzes the local variable table available
1549+
in the byte code of the advice class to determine parameter names from debug information.
1550+
Requires that code be compiled with debug symbols (`-g:vars` at a minimum). Deprecated
1551+
as of Spring Framework 6.0 for removal in Spring Framework 6.1 in favor of compiling
1552+
code with `-parameters`. Not supported in a GraalVM native image.
1553+
`AspectJAdviceParameterNameDiscoverer` :: Deduces parameter names from the pointcut
1554+
expression, `returning`, and `throwing` clauses. See the
1555+
{api-spring-framework}/aop/aspectj/AspectJAdviceParameterNameDiscoverer.html[javadoc]
1556+
for details on the algorithm used.
15541557

15551558
[[aop-ataspectj-advice-params-names-explicit]]
15561559
===== Explicit Argument Names
15571560

15581561
@AspectJ advice and pointcut annotations have an optional `argNames` attribute that you
1559-
can use to specify the argument names of the annotated method. Note, however, that
1560-
explicit `argNames` will only be used by Spring as a fallback if none of the other
1561-
`ParameterNameDiscoverer` implementations is able to determine parameter names (see the
1562-
previous section for details).
1562+
can use to specify the argument names of the annotated method.
15631563

15641564
[TIP]
15651565
====
@@ -1579,26 +1579,28 @@ The following example shows how to use the `argNames` attribute:
15791579
----
15801580
@Before(
15811581
value = "com.xyz.Pointcuts.publicMethod() && target(bean) && @annotation(auditable)", // <1>
1582-
argNames = "bean,auditable")
1582+
argNames = "bean,auditable") // <2>
15831583
public void audit(Object bean, Auditable auditable) {
15841584
AuditCode code = auditable.value();
15851585
// ... use code and bean
15861586
}
15871587
----
15881588
<1> References the `publicMethod` named pointcut defined in <<aop-pointcuts-combining>>.
1589+
<2> Declares `bean` and `auditable` as the argument names.
15891590

15901591
[source,kotlin,indent=0,subs="verbatim",role="secondary"]
15911592
.Kotlin
15921593
----
15931594
@Before(
15941595
value = "com.xyz.Pointcuts.publicMethod() && target(bean) && @annotation(auditable)", // <1>
1595-
argNames = "bean,auditable")
1596+
argNames = "bean,auditable") // <2>
15961597
fun audit(bean: Any, auditable: Auditable) {
15971598
val code = auditable.value()
15981599
// ... use code and bean
15991600
}
16001601
----
16011602
<1> References the `publicMethod` named pointcut defined in <<aop-pointcuts-combining>>.
1603+
<2> Declares `bean` and `auditable` as the argument names.
16021604

16031605
If the first parameter is of type `JoinPoint`, `ProceedingJoinPoint`, or
16041606
`JoinPoint.StaticPart`, you can omit the name of the parameter from the value of the
@@ -1610,32 +1612,34 @@ point object, the `argNames` attribute does not need to include it:
16101612
----
16111613
@Before(
16121614
value = "com.xyz.Pointcuts.publicMethod() && target(bean) && @annotation(auditable)", // <1>
1613-
argNames = "bean,auditable")
1615+
argNames = "bean,auditable") // <2>
16141616
public void audit(JoinPoint jp, Object bean, Auditable auditable) {
16151617
AuditCode code = auditable.value();
16161618
// ... use code, bean, and jp
16171619
}
16181620
----
16191621
<1> References the `publicMethod` named pointcut defined in <<aop-pointcuts-combining>>.
1622+
<2> Declares `bean` and `auditable` as the argument names.
16201623

16211624
[source,kotlin,indent=0,subs="verbatim",role="secondary"]
16221625
.Kotlin
16231626
----
16241627
@Before(
16251628
value = "com.xyz.Pointcuts.publicMethod() && target(bean) && @annotation(auditable)", // <1>
1626-
argNames = "bean,auditable")
1629+
argNames = "bean,auditable") // <2>
16271630
fun audit(jp: JoinPoint, bean: Any, auditable: Auditable) {
16281631
val code = auditable.value()
16291632
// ... use code, bean, and jp
16301633
}
16311634
----
16321635
<1> References the `publicMethod` named pointcut defined in <<aop-pointcuts-combining>>.
1636+
<2> Declares `bean` and `auditable` as the argument names.
16331637

1634-
The special treatment given to the first parameter of the `JoinPoint`,
1635-
`ProceedingJoinPoint`, and `JoinPoint.StaticPart` types is particularly convenient for
1636-
advice instances that do not collect any other join point context. In such situations,
1637-
you may omit the `argNames` attribute. For example, the following advice does not need to
1638-
declare the `argNames` attribute:
1638+
The special treatment given to the first parameter of type `JoinPoint`,
1639+
`ProceedingJoinPoint`, or `JoinPoint.StaticPart` is particularly convenient for advice
1640+
methods that do not collect any other join point context. In such situations, you may
1641+
omit the `argNames` attribute. For example, the following advice does not need to declare
1642+
the `argNames` attribute:
16391643

16401644
[source,java,indent=0,subs="verbatim",role="primary"]
16411645
.Java

0 commit comments

Comments
 (0)