Skip to content

How to decorate a constructor? #1473

Closed Answered by ignasi35
ignasi35 asked this question in Q&A
Discussion options

You must be logged in to vote

Turns out that for my use-case I didn't need to decorate or replace code. Just using the .visit and the Advice APIs I could solve my problem:

    new AgentBuilder.Default()
        .with(AgentBuilder.Listener.StreamWriting.toSystemError().withTransformationsOnly())
        .with(AgentBuilder.InstallationListener.StreamWriting.toSystemError())
        .type(
            ElementMatchers.isAnnotatedWith(WithTracking.class)
        )
        .transform((builder, type, classLoader, module, protectionDomain) ->
            builder.method(ElementMatchers.named("copy"))
                .intercept(MethodDelegation.to(ContextualInterceptor.class))
        )
        .transform((builder, type, classL…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by ignasi35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
1 participant