SuspendProceedingJoinPoint

The suspend counterpart of ProceedingJoinPoint.

When an Around-annotated advice targets a suspend function, the advice must itself be declared suspend and accept a SuspendProceedingJoinPoint instead of a ProceedingJoinPoint, because proceed resumes the original suspending body and therefore has to suspend too.

Usage

@Around(target = [Timed::class])
suspend fun measureTime(jp: SuspendProceedingJoinPoint): Any? {
val start = currentTimeMillis()
val result = jp.proceed()
println("Elapsed: ${currentTimeMillis() - start} ms")
return result
}

A non-suspending target still uses ProceedingJoinPoint; the AspectK compiler plugin picks the right join point type based on whether the intercepted function is suspend.

See also

DefaultSuspendProceedingJoinPoint

Types

Link copied to clipboard

SAM interface used by the AspectK compiler plugin to bridge the wrapper lambda generated at each intercepted call site with proceed.

Properties

Link copied to clipboard
abstract val args: List<Any?>

The runtime arguments passed to the intercepted function, in declaration order.

Link copied to clipboard

Compile-time metadata describing the intercepted function, including its name, annotations, and parameter list.

Link copied to clipboard
abstract val target: Any?

The receiver object on which the intercepted function is called, or null for top-level functions and functions called on companion objects.

Functions

Link copied to clipboard

Returns the AnnotationInfo for annotation T present on the intercepted function, or null if no such annotation is present.

Link copied to clipboard
inline fun <T> JoinPoint.getArg(name: String): T

Returns the argument value for the parameter named name, cast to T.

Link copied to clipboard
inline fun <T> JoinPoint.getArgOrNull(name: String): T?

Returns the argument value for the parameter named name, cast to T, or null if no such parameter exists or the value cannot be cast to T.

Link copied to clipboard
inline fun <T> JoinPoint.getTarget(): T

Returns JoinPoint.target cast to T.

Link copied to clipboard
inline fun <T> JoinPoint.getTargetOrNull(): T?

Returns JoinPoint.target cast to T, or null if the target is null or cannot be cast to T.

Link copied to clipboard
abstract suspend fun proceed(): Any?

Proceeds to the intercepted function body with the original arguments.

abstract suspend fun proceed(vararg args: Any?): Any?

Proceeds to the intercepted function body with substituted arguments.