or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

annotation-based-definition.mdaspect-management.mdindex.mdjoin-point-introspection.mdreflection-api.mdruntime-utilities.mdsignature-system.md
tile.json

tessl/maven-org-aspectj--aspectjrt

The AspectJ runtime is a small library necessary to run Java programs enhanced by AspectJ aspects during a previous compile-time or post-compile-time (binary weaving) build step.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/org.aspectj/aspectjrt@1.9.x

To install, run

npx @tessl/cli install tessl/maven-org-aspectj--aspectjrt@1.9.0

index.mddocs/

AspectJ Runtime (aspectjrt)

AspectJ Runtime provides the essential runtime infrastructure for aspect-oriented programming in Java. This small library is necessary to run Java programs enhanced by AspectJ aspects during a previous compile-time or post-compile-time (binary weaving) build step. It includes core classes for join point introspection, aspect management, annotation-based aspect definition, and runtime utilities that enable crosscutting concerns like logging, security, performance monitoring, and error handling to be cleanly modularized and applied to Java programs.

Package Information

  • Package Name: org.aspectj:aspectjrt
  • Package Type: Maven
  • Language: Java
  • Installation: Add to your Maven dependencies:
<dependency>
    <groupId>org.aspectj</groupId>
    <artifactId>aspectjrt</artifactId>
    <version>1.9.24</version>
</dependency>

For Gradle:

implementation 'org.aspectj:aspectjrt:1.9.24'

Core Imports

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Around;

Basic Usage

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;

@Aspect
public class LoggingAspect {
    
    @Before("execution(* com.example.service.*.*(..))")
    public void logMethodEntry(JoinPoint joinPoint) {
        System.out.println("Entering method: " + joinPoint.getSignature().getName());
        System.out.println("With args: " + Arrays.toString(joinPoint.getArgs()));
        System.out.println("At: " + joinPoint.getSourceLocation());
    }
}

Architecture

AspectJ Runtime is organized around several key components that enable aspect-oriented programming:

  • Join Point System: Core interfaces (JoinPoint, ProceedingJoinPoint) that provide reflective access to execution points in the program where aspects can be applied
  • Signature Framework: Rich type system for representing method, constructor, field, and advice signatures with full reflection capabilities
  • Aspect Management: Runtime support for aspect instantiation and lifecycle management across different instantiation models (singleton, per-object, per-type, etc.)
  • Annotation-Based Definition: Complete @AspectJ annotation set for defining aspects, pointcuts, advice, and inter-type declarations using Java annotations
  • Reflection API: Comprehensive type system (AjType, AjTypeSystem) for introspecting aspects, pointcuts, advice, and inter-type declarations at runtime

Capabilities

Join Point Introspection

Core runtime interfaces that provide reflective access to join points - the specific points in program execution where aspects can be applied. Includes access to execution context, arguments, target objects, and signature information.

public interface JoinPoint {
    Object getThis();
    Object getTarget();
    Object[] getArgs();
    Signature getSignature();
    SourceLocation getSourceLocation();
    String getKind();
    StaticPart getStaticPart();
    String toString();
    String toShortString();
    String toLongString();
}

public interface ProceedingJoinPoint extends JoinPoint {
    Object proceed() throws Throwable;
    Object proceed(Object[] args) throws Throwable;
}

Join Point Introspection

Aspect Management

Runtime support for aspect instantiation, lifecycle management, and access across different instantiation models. Provides programmatic access to aspect instances and binding status.

public class Aspects {
    public static <T> T aspectOf(Class<T> aspectClass);
    public static <T> T aspectOf(Class<T> aspectClass, Object perObject);
    public static <T> T aspectOf(Class<T> aspectClass, Class<?> perTypeWithin);
    public static <T> boolean hasAspect(Class<T> aspectClass);
    public static <T> boolean hasAspect(Class<T> aspectClass, Object perObject);
    public static <T> boolean hasAspect(Class<T> aspectClass, Class<?> perTypeWithin);
}

Aspect Management

Annotation-Based Aspect Definition

Complete set of annotations for defining aspects using the @AspectJ syntax. Supports all AspectJ language features including advice, pointcuts, inter-type declarations, and aspect instantiation models.

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Aspect {
    String value() default "";
}

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Pointcut {
    String value() default "";
    String argNames() default "";
}

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Before {
    String value();
    String argNames() default "";
}

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Around {
    String value();
    String argNames() default "";
}

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface After {
    String value();
    String argNames() default "";
}

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface AfterReturning {
    String value() default "";
    String pointcut() default "";
    String returning() default "";
    String argNames() default "";
}

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface AfterThrowing {
    String value() default "";
    String pointcut() default "";
    String throwing() default "";
    String argNames() default "";
}

Annotation-Based Definition

Signature System

Rich type system for representing signatures of methods, constructors, fields, advice, and other program elements. Provides complete reflection capabilities with access to modifiers, parameter types, return types, and exception specifications.

public interface Signature {
    String getName();
    int getModifiers();
    Class getDeclaringType();
    String toString();
    String toShortString();
    String toLongString();
}

public interface MethodSignature extends MemberSignature {
    Class getReturnType();
    Method getMethod();
    Class[] getParameterTypes();
    String[] getParameterNames();
    Class[] getExceptionTypes();
}

public interface ConstructorSignature extends CodeSignature {
    Constructor getConstructor();
}

public interface FieldSignature extends MemberSignature {
    Class getFieldType();
    Field getField();
}

Signature System

Reflection API

AspectJ-specific type system that extends Java reflection to provide access to aspect-oriented features like pointcuts, advice, inter-type declarations, and per-clauses.

public interface AjType<T> {
    String getName();
    Class<T> getJavaClass();
    AjType<?>[] getInterfaces();
    boolean isAspect();
    Aspect getAspectAnnotation();
    PerClause getPerClause();
    Pointcut[] getPointcuts();
    Advice[] getAdvice();
}

public class AjTypeSystem {
    public static AjType<?> getAjType(Class<?> clazz);
    public static AjType<?>[] getAjTypes(Class<?>[] classes);
}

Reflection API

Runtime Utilities

Supporting classes for control flow tracking, exception handling, and other runtime services that enable advanced AspectJ features.

public class CFlow {
    public CFlow();
    public CFlow(Object _aspect);
    public Object getAspect();
    public void setAspect(Object _aspect);
    public Object get(int index);
}

public class SoftException extends RuntimeException {
    public SoftException(Throwable inner);
    public Throwable getWrappedThrowable();
    public Throwable getCause();
}

public class NoAspectBoundException extends RuntimeException {
    public NoAspectBoundException(String aspectName, Throwable inner);
    public Throwable getCause();
}

Runtime Utilities

Types

Join Point Constants

public interface JoinPoint {
    String METHOD_EXECUTION = "method-execution";
    String METHOD_CALL = "method-call";
    String CONSTRUCTOR_EXECUTION = "constructor-execution";
    String CONSTRUCTOR_CALL = "constructor-call";
    String FIELD_GET = "field-get";
    String FIELD_SET = "field-set";
    String STATICINITIALIZATION = "staticinitialization";
    String PREINITIALIZATION = "preinitialization";
    String INITIALIZATION = "initialization";
    String EXCEPTION_HANDLER = "exception-handler";
    String SYNCHRONIZATION_LOCK = "lock";
    String SYNCHRONIZATION_UNLOCK = "unlock";
    String ADVICE_EXECUTION = "adviceexecution";
}

Source Location

public interface SourceLocation {
    Class getWithinType();
    String getFileName();
    int getLine();
    int getColumn();
}

Per Clause Types

public enum PerClauseKind {
    SINGLETON, PERCFLOW, PERCFLOWBELOW, PERTARGET, PERTHIS, PERTYPEWITHIN
}

public interface PerClause {
    PerClauseKind getKind();
}