001package sting.processor;
002
003import javax.annotation.Nonnull;
004
005/**
006 * Processor-path plugin extension point for direct interceptor code generation.
007 */
008public interface InterceptorCodeGenerator
009{
010  /**
011   * Return true if this generator claims the effective interceptor binding.
012   *
013   * @param binding the effective interceptor binding.
014   * @return true if this generator claims the effective interceptor binding.
015   */
016  boolean supports( @Nonnull InterceptorBindingModel binding );
017
018  /**
019   * Emit code that runs before the target method invocation.
020   *
021   * @param method the intercepted method metadata.
022   * @param binding the effective interceptor binding.
023   * @param emitter the lifecycle code emitter.
024   */
025  void emitBefore( @Nonnull InterceptedMethodModel method,
026                   @Nonnull InterceptorBindingModel binding,
027                   @Nonnull LifecycleCodeEmitter emitter );
028
029  /**
030   * Emit code that runs after a successful target method invocation.
031   *
032   * @param method the intercepted method metadata.
033   * @param binding the effective interceptor binding.
034   * @param emitter the lifecycle code emitter.
035   */
036  void emitAfter( @Nonnull InterceptedMethodModel method,
037                  @Nonnull InterceptorBindingModel binding,
038                  @Nonnull LifecycleCodeEmitter emitter );
039
040  /**
041   * Emit code that runs when the target method invocation or an inner interceptor fails.
042   *
043   * @param method the intercepted method metadata.
044   * @param binding the effective interceptor binding.
045   * @param emitter the lifecycle code emitter.
046   */
047  void emitAfterException( @Nonnull InterceptedMethodModel method,
048                           @Nonnull InterceptorBindingModel binding,
049                           @Nonnull LifecycleCodeEmitter emitter );
050}