Java Code Examples for net.bytebuddy.dynamic.scaffold.MethodGraph#Compiler

The following examples show how to use net.bytebuddy.dynamic.scaffold.MethodGraph#Compiler . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MemberSubstitution.java    From byte-buddy with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new substituting method visitor.
 *
 * @param methodVisitor         The method visitor to delegate to.
 * @param instrumentedType      The instrumented type.
 * @param instrumentedMethod    The instrumented method.
 * @param methodGraphCompiler   The method graph compiler to use.
 * @param strict                {@code true} if the method processing should be strict where an exception is raised if a member cannot be found.
 * @param replacement           The replacement to use for creating substitutions.
 * @param implementationContext The implementation context to use.
 * @param typePool              The type pool to use.
 * @param virtualPrivateCalls   {@code true}, virtual method calls might target private methods in accordance to the nest mate specification.
 */
protected SubstitutingMethodVisitor(MethodVisitor methodVisitor,
                                    TypeDescription instrumentedType,
                                    MethodDescription instrumentedMethod,
                                    MethodGraph.Compiler methodGraphCompiler,
                                    boolean strict,
                                    Replacement replacement,
                                    Implementation.Context implementationContext,
                                    TypePool typePool,
                                    boolean virtualPrivateCalls) {
    super(methodVisitor, instrumentedMethod);
    this.instrumentedType = instrumentedType;
    this.instrumentedMethod = instrumentedMethod;
    this.methodGraphCompiler = methodGraphCompiler;
    this.strict = strict;
    this.replacement = replacement;
    this.implementationContext = implementationContext;
    this.typePool = typePool;
    this.virtualPrivateCalls = virtualPrivateCalls;
    stackSizeBuffer = 0;
    localVariableExtension = 0;
}
 
Example 2
Source File: MethodDelegation.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new implementation delegate for invoking methods on a supplied instance.
 *
 * @param fieldName           The name of the field that is target of the delegation.
 * @param methodGraphCompiler The method graph compiler to use.
 * @param parameterBinders    The parameter binders to use.
 * @param matcher             The matcher to use for filtering methods.
 * @param target              The target instance.
 * @param fieldType           The field's type.
 */
protected WithInstance(String fieldName,
                       MethodGraph.Compiler methodGraphCompiler,
                       List<? extends TargetMethodAnnotationDrivenBinder.ParameterBinder<?>> parameterBinders,
                       ElementMatcher<? super MethodDescription> matcher,
                       Object target,
                       TypeDescription.Generic fieldType) {
    super(fieldName, methodGraphCompiler, parameterBinders, matcher);
    this.target = target;
    this.fieldType = fieldType;
}
 
Example 3
Source File: DecoratingDynamicTypeBuilder.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new decorating dynamic type builder.
 *
 * @param instrumentedType             The instrumented type to decorate.
 * @param typeAttributeAppender        The type attribute appender to apply onto the instrumented type.
 * @param asmVisitorWrapper            The ASM visitor wrapper to apply onto the class writer.
 * @param classFileVersion             The class file version to define auxiliary types in.
 * @param auxiliaryTypeNamingStrategy  The naming strategy for auxiliary types to apply.
 * @param annotationValueFilterFactory The annotation value filter factory to apply.
 * @param annotationRetention          The annotation retention to apply.
 * @param implementationContextFactory The implementation context factory to apply.
 * @param methodGraphCompiler          The method graph compiler to use.
 * @param typeValidation               Determines if a type should be explicitly validated.
 * @param classWriterStrategy          The class writer strategy to use.
 * @param ignoredMethods               A matcher for identifying methods that should be excluded from instrumentation.
 * @param auxiliaryTypes               A list of explicitly required auxiliary types.
 * @param classFileLocator             The class file locator for locating the original type's class file.
 */
protected DecoratingDynamicTypeBuilder(TypeDescription instrumentedType,
                                       TypeAttributeAppender typeAttributeAppender,
                                       AsmVisitorWrapper asmVisitorWrapper,
                                       ClassFileVersion classFileVersion,
                                       AuxiliaryType.NamingStrategy auxiliaryTypeNamingStrategy,
                                       AnnotationValueFilter.Factory annotationValueFilterFactory,
                                       AnnotationRetention annotationRetention,
                                       Implementation.Context.Factory implementationContextFactory,
                                       MethodGraph.Compiler methodGraphCompiler,
                                       TypeValidation typeValidation,
                                       ClassWriterStrategy classWriterStrategy,
                                       LatentMatcher<? super MethodDescription> ignoredMethods,
                                       List<DynamicType> auxiliaryTypes,
                                       ClassFileLocator classFileLocator) {
    this.instrumentedType = instrumentedType;
    this.typeAttributeAppender = typeAttributeAppender;
    this.asmVisitorWrapper = asmVisitorWrapper;
    this.classFileVersion = classFileVersion;
    this.auxiliaryTypeNamingStrategy = auxiliaryTypeNamingStrategy;
    this.annotationValueFilterFactory = annotationValueFilterFactory;
    this.annotationRetention = annotationRetention;
    this.implementationContextFactory = implementationContextFactory;
    this.methodGraphCompiler = methodGraphCompiler;
    this.typeValidation = typeValidation;
    this.classWriterStrategy = classWriterStrategy;
    this.ignoredMethods = ignoredMethods;
    this.auxiliaryTypes = auxiliaryTypes;
    this.classFileLocator = classFileLocator;
}
 
Example 4
Source File: MemberSubstitution.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new member substitution for a matched method that requires a specification for how to perform a substitution.
 *
 * @param methodGraphCompiler The method graph compiler to use.
 * @param typePoolResolver    The type pool resolver to use.
 * @param strict              {@code true} if the method processing should be strict where an exception is raised if a member cannot be found.
 * @param replacementFactory  The replacement factory to use.
 * @param matcher             A matcher for any method or constructor that should be substituted.
 * @param includeVirtualCalls {@code true} if this specification includes virtual invocations.
 * @param includeSuperCalls   {@code true} if this specification includes {@code super} invocations.
 */
protected ForMatchedMethod(MethodGraph.Compiler methodGraphCompiler,
                           TypePoolResolver typePoolResolver,
                           boolean strict,
                           Replacement.Factory replacementFactory,
                           ElementMatcher<? super MethodDescription> matcher,
                           boolean includeVirtualCalls,
                           boolean includeSuperCalls) {
    super(methodGraphCompiler, typePoolResolver, strict, replacementFactory);
    this.matcher = matcher;
    this.includeVirtualCalls = includeVirtualCalls;
    this.includeSuperCalls = includeSuperCalls;
}
 
Example 5
Source File: MethodDelegation.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new implementation delegate for a field delegation.
 *
 * @param fieldName           The name of the field that is target of the delegation.
 * @param methodGraphCompiler The method graph compiler to use.
 * @param parameterBinders    The parameter binders to use.
 * @param matcher             The matcher to use for filtering methods.
 */
protected ForField(String fieldName,
                   MethodGraph.Compiler methodGraphCompiler,
                   List<? extends TargetMethodAnnotationDrivenBinder.ParameterBinder<?>> parameterBinders,
                   ElementMatcher<? super MethodDescription> matcher) {
    this.fieldName = fieldName;
    this.methodGraphCompiler = methodGraphCompiler;
    this.parameterBinders = parameterBinders;
    this.matcher = matcher;
}
 
Example 6
Source File: MethodDelegation.java    From byte-buddy with Apache License 2.0 3 votes vote down vote up
/**
 * Delegates any intercepted method to invoke a non-{@code static} method on the instance of the supplied field. To be
 * considered a valid delegation target, a method must be visible and accessible to the instrumented type. This is the
 * case if the method's declaring type is either public or in the same package as the instrumented type and if the method
 * is either public or non-private and in the same package as the instrumented type. Private methods can only be used as
 * a delegation target if the delegation is targeting the instrumented type.
 *
 * @param name                The field's name.
 * @param fieldLocatorFactory The field locator factory to use.
 * @param methodGraphCompiler The method graph compiler to use.
 * @return A delegation that redirects invocations to a method of the specified field's instance.
 */
public MethodDelegation toField(String name, FieldLocator.Factory fieldLocatorFactory, MethodGraph.Compiler methodGraphCompiler) {
    return new MethodDelegation(new ImplementationDelegate.ForField.WithLookup(name,
            methodGraphCompiler,
            parameterBinders,
            matcher,
            fieldLocatorFactory), parameterBinders, ambiguityResolver, bindingResolver);
}
 
Example 7
Source File: MemberSubstitution.java    From byte-buddy with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a new member substitution for a matched byte code element that requires a specification for how to perform a substitution.
 *
 * @param methodGraphCompiler The method graph compiler to use.
 * @param typePoolResolver    The type pool resolver to use.
 * @param strict              {@code true} if the method processing should be strict where an exception is raised if a member cannot be found.
 * @param replacementFactory  The replacement factory to use.
 * @param matcher             A matcher for any byte code elements that should be substituted.
 */
protected ForMatchedByteCodeElement(MethodGraph.Compiler methodGraphCompiler,
                                    TypePoolResolver typePoolResolver,
                                    boolean strict,
                                    Replacement.Factory replacementFactory,
                                    ElementMatcher<? super ByteCodeElement> matcher) {
    super(methodGraphCompiler, typePoolResolver, strict, replacementFactory);
    this.matcher = matcher;
}
 
Example 8
Source File: MemberSubstitution.java    From byte-buddy with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a new member substitution for a matched field that requires a specification for how to perform a substitution.
 *
 * @param methodGraphCompiler The method graph compiler to use.
 * @param typePoolResolver    The type pool resolver to use.
 * @param strict              {@code true} if the method processing should be strict where an exception is raised if a member cannot be found.
 * @param replacementFactory  The replacement factory to use.
 * @param matcher             A matcher for any field that should be substituted.
 */
protected ForMatchedField(MethodGraph.Compiler methodGraphCompiler,
                          TypePoolResolver typePoolResolver,
                          boolean strict,
                          Replacement.Factory replacementFactory,
                          ElementMatcher<? super FieldDescription.InDefinedShape> matcher) {
    this(methodGraphCompiler, typePoolResolver, strict, replacementFactory, matcher, true, true);
}
 
Example 9
Source File: MemberSubstitution.java    From byte-buddy with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a new member substitution for a matched method that requires a specification for how to perform a substitution.
 *
 * @param methodGraphCompiler The method graph compiler to use.
 * @param typePoolResolver    The type pool resolver to use.
 * @param strict              {@code true} if the method processing should be strict where an exception is raised if a member cannot be found.
 * @param replacementFactory  The replacement factory to use.
 * @param matcher             A matcher for any method or constructor that should be substituted.
 */
protected ForMatchedMethod(MethodGraph.Compiler methodGraphCompiler,
                           TypePoolResolver typePoolResolver,
                           boolean strict,
                           Replacement.Factory replacementFactory,
                           ElementMatcher<? super MethodDescription> matcher) {
    this(methodGraphCompiler, typePoolResolver, strict, replacementFactory, matcher, true, true);
}
 
Example 10
Source File: MethodDelegation.java    From byte-buddy with Apache License 2.0 2 votes vote down vote up
/**
 * Delegates any intercepted method to invoke a non-{@code static} method that is declared by the supplied type's instance or any
 * of its super types. To be considered a valid delegation target, a method must be visible and accessible to the instrumented type.
 * This is the case if the method's declaring type is either public or in the same package as the instrumented type and if the method
 * is either public or non-private and in the same package as the instrumented type. Private methods can only be used as
 * a delegation target if the delegation is targeting the instrumented type.
 *
 * @param target              The target instance for the delegation.
 * @param methodGraphCompiler The method graph compiler to use.
 * @return A method delegation that redirects method calls to a static method of the supplied type.
 */
public MethodDelegation to(Object target, MethodGraph.Compiler methodGraphCompiler) {
    return to(target, target.getClass(), methodGraphCompiler);
}
 
Example 11
Source File: MethodCall.java    From byte-buddy with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new method locator for an element matcher.
 *
 * @param instrumentedType    The instrumented type.
 * @param matcher             The matcher to use.
 * @param methodGraphCompiler The method graph compiler to use.
 */
protected ForElementMatcher(TypeDescription instrumentedType, ElementMatcher<? super MethodDescription> matcher, MethodGraph.Compiler methodGraphCompiler) {
    this.instrumentedType = instrumentedType;
    this.matcher = matcher;
    this.methodGraphCompiler = methodGraphCompiler;
}
 
Example 12
Source File: MethodDelegation.java    From byte-buddy with Apache License 2.0 2 votes vote down vote up
/**
 * Delegates any intercepted method to invoke a non-{@code static} method that is declared by the supplied type's instance or any
 * of its super types. To be considered a valid delegation target, a method must be visible and accessible to the instrumented type.
 * This is the case if the method's declaring type is either public or in the same package as the instrumented type and if the method
 * is either public or non-private and in the same package as the instrumented type. Private methods can only be used as
 * a delegation target if the delegation is targeting the instrumented type.
 *
 * @param target              The target instance for the delegation.
 * @param typeDefinition      The most specific type of which {@code target} should be considered. Must be a super type of the target's actual type.
 * @param methodGraphCompiler The method graph compiler to use.
 * @return A method delegation that redirects method calls to a static method of the supplied type.
 */
public static MethodDelegation to(Object target, TypeDefinition typeDefinition, MethodGraph.Compiler methodGraphCompiler) {
    return withDefaultConfiguration().to(target, typeDefinition, methodGraphCompiler);
}
 
Example 13
Source File: InvokeDynamic.java    From byte-buddy with Apache License 2.0 2 votes vote down vote up
/**
 * <p>
 * Creates a lambda expression using the JVM's lambda meta factory. The method that is implementing the lambda expression is provided
 * the explicit arguments first and the functional interface's method second.
 * </p>
 * <p>
 * <b>Important</b>: Byte Buddy does not validate that the provided arguments are correct considering the required arguments of the bound
 * functional interface. Binding an incorrect number of arguments or arguments of incompatible types does not create illegal byte code
 * but yields a runtime error when the call site is first used. This is done to support future extensions or alternative implementations
 * of the Java virtual machine.
 * </p>
 *
 * @param method              The method that implements the lambda expression.
 * @param functionalInterface The functional interface that is an instance of the lambda expression.
 * @param methodGraphCompiler The method graph compiler to use.
 * @return A builder for creating a lambda expression.
 */
public static WithImplicitArguments lambda(Method method, Class<?> functionalInterface, MethodGraph.Compiler methodGraphCompiler) {
    return lambda(new MethodDescription.ForLoadedMethod(method), TypeDescription.ForLoadedType.of(functionalInterface), methodGraphCompiler);
}
 
Example 14
Source File: MethodDelegation.java    From byte-buddy with Apache License 2.0 2 votes vote down vote up
/**
 * Delegates any intercepted method to invoke a non-{@code static} method that is declared by the supplied type's instance or any
 * of its super types. To be considered a valid delegation target, a method must be visible and accessible to the instrumented type.
 * This is the case if the method's declaring type is either public or in the same package as the instrumented type and if the method
 * is either public or non-private and in the same package as the instrumented type. Private methods can only be used as
 * a delegation target if the delegation is targeting the instrumented type.
 *
 * @param target              The target instance for the delegation.
 * @param type                The most specific type of which {@code target} should be considered. Must be a super type of the target's actual type.
 * @param methodGraphCompiler The method graph compiler to use.
 * @return A method delegation that redirects method calls to a static method of the supplied type.
 */
public static MethodDelegation to(Object target, Type type, MethodGraph.Compiler methodGraphCompiler) {
    return withDefaultConfiguration().to(target, type, methodGraphCompiler);
}
 
Example 15
Source File: MethodDelegation.java    From byte-buddy with Apache License 2.0 2 votes vote down vote up
/**
 * Delegates any intercepted method to invoke a method on an instance that is returned by a parameterless method of the
 * given name. To be considered a valid delegation target, a method must be visible and accessible to the instrumented type.
 * This is the case if the method's declaring type is either public or in the same package as the instrumented type and if
 * the method is either public or non-private and in the same package as the instrumented type. Private methods can only
 * be used as a delegation target if the delegation is targeting the instrumented type.
 *
 * @param name                The name of the method that returns the delegation target.
 * @param methodGraphCompiler The method graph compiler to use.
 * @return A delegation that redirects invocations to the return value of a method that is declared by the instrumented type.
 */
public static MethodDelegation toMethodReturnOf(String name, MethodGraph.Compiler methodGraphCompiler) {
    return withDefaultConfiguration().toMethodReturnOf(name, methodGraphCompiler);
}
 
Example 16
Source File: MemberSubstitution.java    From byte-buddy with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a factory for a substitution that locates a method on the receiver type.
 *
 * @param matcher             The matcher for locating the method to substitute with.
 * @param methodGraphCompiler The method graph compiler to use.
 */
public OfMatchedMethod(ElementMatcher<? super MethodDescription> matcher, MethodGraph.Compiler methodGraphCompiler) {
    this.matcher = matcher;
    this.methodGraphCompiler = methodGraphCompiler;
}
 
Example 17
Source File: MethodDelegation.java    From byte-buddy with Apache License 2.0 2 votes vote down vote up
/**
 * Delegates any intercepted method to invoke a non-{@code static} method on the instance of the supplied field. To be
 * considered a valid delegation target, a method must be visible and accessible to the instrumented type. This is the
 * case if the method's declaring type is either public or in the same package as the instrumented type and if the method
 * is either public or non-private and in the same package as the instrumented type. Private methods can only be used as
 * a delegation target if the delegation is targeting the instrumented type.
 *
 * @param name                The field's name.
 * @param methodGraphCompiler The method graph compiler to use.
 * @return A delegation that redirects invocations to a method of the specified field's instance.
 */
public MethodDelegation toField(String name, MethodGraph.Compiler methodGraphCompiler) {
    return toField(name, FieldLocator.ForClassHierarchy.Factory.INSTANCE, methodGraphCompiler);
}
 
Example 18
Source File: MethodCall.java    From byte-buddy with Apache License 2.0 2 votes vote down vote up
/**
 * Invokes a unique virtual method or constructor of the instrumented type that is matched by the specified matcher.
 *
 * @param matcher             The matcher to identify the method to invoke.
 * @param methodGraphCompiler The method graph compiler to use.
 * @return A method call for the uniquely identified method.
 */
public static WithoutSpecifiedTarget invoke(ElementMatcher<? super MethodDescription> matcher, MethodGraph.Compiler methodGraphCompiler) {
    return invoke(new MethodLocator.ForElementMatcher.Factory(matcher, methodGraphCompiler));
}
 
Example 19
Source File: MemberSubstitution.java    From byte-buddy with Apache License 2.0 2 votes vote down vote up
/**
 * Replaces any interaction with a matched byte code element with a non-static method access on the first
 * parameter of the matched element. When matching a non-static field access or method invocation, the
 * substituted method is located on the same receiver type as the original access. For static access, the
 * first argument is used as a receiver.
 *
 * @param matcher             A matcher for locating a method on the original interaction's receiver type.
 * @param methodGraphCompiler The method graph compiler to use for locating a method.
 * @return A member substitution that replaces any matched byte code element with an access of the matched method.
 */
public MemberSubstitution replaceWithMethod(ElementMatcher<? super MethodDescription> matcher, MethodGraph.Compiler methodGraphCompiler) {
    return replaceWith(new Substitution.ForMethodInvocation.OfMatchedMethod(matcher, methodGraphCompiler));
}
 
Example 20
Source File: MethodDelegation.java    From byte-buddy with Apache License 2.0 2 votes vote down vote up
/**
 * Delegates any intercepted method to invoke a non-{@code static} method that is declared by the supplied type's instance or any
 * of its super types. To be considered a valid delegation target, a method must be visible and accessible to the instrumented type.
 * This is the case if the method's declaring type is either public or in the same package as the instrumented type and if the method
 * is either public or non-private and in the same package as the instrumented type. Private methods can only be used as
 * a delegation target if the delegation is targeting the instrumented type.
 *
 * @param target              The target instance for the delegation.
 * @param fieldName           The name of the field that is holding the {@code target} instance.
 * @param methodGraphCompiler The method graph compiler to use.
 * @return A method delegation that redirects method calls to a static method of the supplied type.
 */
public MethodDelegation to(Object target, String fieldName, MethodGraph.Compiler methodGraphCompiler) {
    return to(target, target.getClass(), fieldName, methodGraphCompiler);
}