Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Aspect Provider instead of Concrete Aspect Target #268

Merged
merged 3 commits into from Jan 31, 2023

Conversation

SentryMan
Copy link
Collaborator

@SentryMan SentryMan commented Jan 31, 2023

  • Changed generated aspect proxy class to use AspectProvider Interface
  • Changed Aspect Annotation to only accept types extending AspectProvider.
  • Removed unused fields in generated proxy class

Example generated proxy class:

Before:

@Proxy
@Generated("io.avaje.inject.generator")
public final class ServiceClass$Proxy extends ServiceClass {

  private final TimedAspect timedAspect;

  private Method callDownStream0;
  private MethodInterceptor callDownStream0Timed;

  public ServiceClass$Proxy(TimedAspect timedAspect, ApiClient api) {
    super(api);
    this.timedAspect = timedAspect;
    try {
      callDownStream0 = ServiceClass.class.getDeclaredMethod("callDownStream");
      callDownStream0Timed = timedAspect.interceptor(callDownStream0, callDownStream0.getAnnotation(Timed.class));

    } catch (Exception e) {
      throw new IllegalStateException(e);
    }
  }

  @Override
  public byte[] callDownStream() {
    var call = new Invocation.Call<>(() -> super.callDownStream())
      .with(this, callDownStream0);
    try {
      callDownStream0Timed.invoke(call);
      return call.finalResult();
    } catch (InvocationException e) {
      throw e;
    } catch (Throwable e) {
      throw new InvocationException(e);
    }
  }
}

After:

@Proxy
@Generated("io.avaje.inject.generator")
public final class ServiceClass$Proxy extends ServiceClass {

  private Method callDownStream0;
  private MethodInterceptor callDownStream0Timed;

  public ServiceClass$Proxy(AspectProvider<Timed> timed, ApiClient api) {
    super(api);
    try {
      callDownStream0 = ServiceClass.class.getDeclaredMethod("callDownStream");
      callDownStream0Timed = timed.interceptor(callDownStream0, callDownStream0.getAnnotation(Timed.class));
    } catch (Exception e) {
      throw new IllegalStateException(e);
    }
  }

  @Override
  public byte[] callDownStream() {
    var call = new Invocation.Call<>(() -> super.callDownStream())
      .with(this, callDownStream0);
    try {
      callDownStream0Timed.invoke(call);
      return call.finalResult();
    } catch (InvocationException e) {
      throw e;
    } catch (Throwable e) {
      throw new InvocationException(e);
    }
  }
}

@rbygrave rbygrave added this to the 8.12 milestone Jan 31, 2023
@rbygrave rbygrave merged commit 391e4cc into avaje:master Jan 31, 2023
@SentryMan SentryMan deleted the aspect2 branch January 31, 2023 03:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants