Annotation Interface Intercept


@Retention(RUNTIME) @Target(TYPE) public @interface Intercept
Declares a class as a handler for calls the scanned code makes to an API.

The handler mirrors the API it intercepts. Whenever the scanner finds a call to the target class, it reconstructs the arguments and invokes the handler's static method with the same name and number of parameters. For an instance method, the receiver is passed as the first argument.

@Intercept("com.example.api.ColorRegistry")
public class ColorRegistry {
    @Intercept.Capture
    public static CaptureChannel<Color> CAPTURE;

    public static void register(String name, Color color) {
        CAPTURE.emit(color);
    }
}

Each argument is converted to the handler's parameter type:

  • A Conduit interface wraps the reconstructed value.
  • A Supplier<T> evaluates the lambda or method reference that was passed, and only when get() is called. T may be a conduit, or Trace for the raw result.
  • Strings, numbers and booleans are passed through when they are compile-time constants, and are null otherwise.
  • Value receives the reconstructed value as is.

A matched call is not stepped into. If a handler intercepts both a wrapper API and the API it wraps, a registration through the wrapper is reported once, not twice.

See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static @interface 
    Marks a static CaptureChannel field on a handler to be created when the handler is registered.
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    The binary name of the class whose calls are intercepted.
  • Element Details

    • value

      String value
      The binary name of the class whose calls are intercepted.
      Returns:
      the target class name