Class AgentBuilder.Transformer.ForAdvice

  • All Implemented Interfaces:
    AgentBuilder.Transformer
    Enclosing interface:
    AgentBuilder.Transformer

    @Enhance
    public static class AgentBuilder.Transformer.ForAdvice
    extends java.lang.Object
    implements AgentBuilder.Transformer
    A transformer for applying an Advice where this advice class might reference types of both the agent's and the user's class loader. Using this transformer, it is possible to apply advice without including any library dependencies of this advice class which are then rather looked up from the transformed class's class loader. For this to work, it is required to register the advice class's class loader manually via the include methods and to reference the advice class by its fully-qualified name. The advice class is then never loaded by rather described by a TypePool.
    • Constructor Detail

      • ForAdvice

        public ForAdvice()
        Creates a new advice transformer with a default setup.
      • ForAdvice

        public ForAdvice​(Advice.WithCustomMapping advice)
        Creates a new advice transformer which applies the given advice.
        Parameters:
        advice - The configured advice to use.
    • Method Detail

      • transform

        public DynamicType.Builder<?> transform​(DynamicType.Builder<?> builder,
                                                TypeDescription typeDescription,
                                                java.lang.ClassLoader classLoader,
                                                JavaModule module)
        Allows for a transformation of a DynamicType.Builder.
        Specified by:
        transform in interface AgentBuilder.Transformer
        Parameters:
        builder - The dynamic builder to transform.
        typeDescription - The description of the type currently being instrumented.
        classLoader - The class loader of the instrumented class. Might be null to represent the bootstrap class loader.
        module - The class's module or null if the current VM does not support modules.
        Returns:
        A transformed version of the supplied builder.
      • with

        public AgentBuilder.Transformer.ForAdvice with​(AgentBuilder.PoolStrategy poolStrategy)
        Registers a pool strategy for creating a TypePool that should be used for creating the advice class.
        Parameters:
        poolStrategy - The pool strategy to use.
        Returns:
        A new instance of this advice transformer that applies the supplied pool strategy.
      • with

        public AgentBuilder.Transformer.ForAdvice with​(AgentBuilder.LocationStrategy locationStrategy)
        Registers a location strategy for creating a ClassFileLocator from the class loader that is supplied during transformation that should be used for looking up advice-relevant classes.
        Parameters:
        locationStrategy - The location strategy to use.
        Returns:
        A new instance of this advice transformer that applies the supplied location strategy.
      • include

        public AgentBuilder.Transformer.ForAdvice include​(java.lang.ClassLoader... classLoader)
        Includes the supplied class loaders as a source for looking up an advice class or its dependencies. Note that the supplied class loaders are queried for types before the class loader of the instrumented class.
        Parameters:
        classLoader - The class loaders to include when looking up classes in their order. Duplicates are filtered.
        Returns:
        A new instance of this advice transformer that considers the supplied class loaders as a lookup source.
      • include

        public AgentBuilder.Transformer.ForAdvice include​(ClassFileLocator... classFileLocator)
        Includes the supplied class file locators as a source for looking up an advice class or its dependencies. Note that the supplied class loaders are queried for types before the class loader of the instrumented class.
        Parameters:
        classFileLocator - The class file locators to include when looking up classes in their order. Duplicates are filtered.
        Returns:
        A new instance of this advice transformer that considers the supplied class file locators as a lookup source.
      • include

        public AgentBuilder.Transformer.ForAdvice include​(java.util.List<? extends ClassFileLocator> classFileLocators)
        Includes the supplied class file locators as a source for looking up an advice class or its dependencies. Note that the supplied class loaders are queried for types before the class loader of the instrumented class.
        Parameters:
        classFileLocators - The class file locators to include when looking up classes in their order. Duplicates are filtered.
        Returns:
        A new instance of this advice transformer that considers the supplied class file locators as a lookup source.
      • advice

        public AgentBuilder.Transformer.ForAdvice advice​(ElementMatcher<? super MethodDescription> matcher,
                                                         java.lang.String name)
        Applies the given advice class onto all methods that satisfy the supplied matcher.
        Parameters:
        matcher - The matcher to determine what methods the advice should be applied to.
        name - The fully-qualified, binary name of the advice class.
        Returns:
        A new instance of this advice transformer that applies the given advice to all matched methods of an instrumented type.
      • advice

        public AgentBuilder.Transformer.ForAdvice advice​(LatentMatcher<? super MethodDescription> matcher,
                                                         java.lang.String name)
        Applies the given advice class onto all methods that satisfy the supplied matcher.
        Parameters:
        matcher - The matcher to determine what methods the advice should be applied to.
        name - The fully-qualified, binary name of the advice class.
        Returns:
        A new instance of this advice transformer that applies the given advice to all matched methods of an instrumented type.
      • advice

        public AgentBuilder.Transformer.ForAdvice advice​(ElementMatcher<? super MethodDescription> matcher,
                                                         java.lang.String enter,
                                                         java.lang.String exit)
        Applies the given advice class onto all methods that satisfy the supplied matcher.
        Parameters:
        matcher - The matcher to determine what methods the advice should be applied to.
        enter - The fully-qualified, binary name of the enter advice class.
        exit - The fully-qualified, binary name of the exit advice class.
        Returns:
        A new instance of this advice transformer that applies the given advice to all matched methods of an instrumented type.
      • advice

        public AgentBuilder.Transformer.ForAdvice advice​(LatentMatcher<? super MethodDescription> matcher,
                                                         java.lang.String enter,
                                                         java.lang.String exit)
        Applies the given advice class onto all methods that satisfy the supplied matcher.
        Parameters:
        matcher - The matcher to determine what methods the advice should be applied to.
        enter - The fully-qualified, binary name of the enter advice class.
        exit - The fully-qualified, binary name of the exit advice class.
        Returns:
        A new instance of this advice transformer that applies the given advice to all matched methods of an instrumented type.