Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package com.ui4j.bytebuddy;
import com.ui4j.bytebuddy.asm.ClassVisitorWrapper;
import com.ui4j.bytebuddy.dynamic.ClassFileLocator;
import com.ui4j.bytebuddy.dynamic.DynamicType;
import com.ui4j.bytebuddy.dynamic.scaffold.BridgeMethodResolver;
import com.ui4j.bytebuddy.dynamic.scaffold.FieldRegistry;
import com.ui4j.bytebuddy.dynamic.scaffold.MethodRegistry;
import com.ui4j.bytebuddy.dynamic.scaffold.inline.InlineDynamicTypeBuilder;
import com.ui4j.bytebuddy.dynamic.scaffold.inline.MethodRebaseResolver;
import com.ui4j.bytebuddy.dynamic.scaffold.subclass.ConstructorStrategy;
import com.ui4j.bytebuddy.dynamic.scaffold.subclass.SubclassDynamicTypeBuilder;
import com.ui4j.bytebuddy.instrumentation.Instrumentation;
import com.ui4j.bytebuddy.instrumentation.ModifierContributor;
import com.ui4j.bytebuddy.instrumentation.attribute.FieldAttributeAppender;
import com.ui4j.bytebuddy.instrumentation.attribute.MethodAttributeAppender;
import com.ui4j.bytebuddy.instrumentation.attribute.TypeAttributeAppender;
import com.ui4j.bytebuddy.instrumentation.method.MethodDescription;
import com.ui4j.bytebuddy.instrumentation.method.MethodLookupEngine;
import com.ui4j.bytebuddy.instrumentation.type.TypeDescription;
import com.ui4j.bytebuddy.instrumentation.type.TypeList;
import com.ui4j.bytebuddy.matcher.ElementMatcher;
import com.ui4j.bytebuddy.modifier.TypeManifestation;
import com.ui4j.bytebuddy.jar.asm.Opcodes;
import java.lang.annotation.Annotation;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static com.ui4j.bytebuddy.matcher.ElementMatchers.*;
import static com.ui4j.bytebuddy.utility.ByteBuddyCommons.*;
/**
* {@code ByteBuddy} instances are configurable factories for creating new Java types at a JVM's runtime.
* Such types are represented by {@link com.ui4j.bytebuddy.dynamic.DynamicType}s which can be saved to disk or loaded into
* the Java virtual machine. Each instance of {@code ByteBuddy} is immutable where any of the factory methods returns
* a new instance that represents the altered configuration.
*
* Note that any configuration defines to ignore the instrumentation of any synthetic methods or the default finalizer
* method {@link Object#finalize()}. This behavior can be altered by
* {@link com.ui4j.bytebuddy.ByteBuddy#withIgnoredMethods(com.ui4j.bytebuddy.matcher.ElementMatcher)}.
*/
public class ByteBuddy {
/**
* The default prefix for the default {@link com.ui4j.bytebuddy.NamingStrategy}.
*/
public static final String BYTE_BUDDY_DEFAULT_PREFIX = "ByteBuddy";
/**
* The class file version of the current configuration.
*/
protected final ClassFileVersion classFileVersion;
/**
* The naming strategy of the current configuration.
*/
protected final NamingStrategy.Unbound namingStrategy;
/**
* A list of interface types to be implemented by any class that is implemented by the current configuration.
*/
protected final List interfaceTypes;
/**
* A matcher for identifying methods that should never be intercepted.
*/
protected final ElementMatcher super MethodDescription> ignoredMethods;
/**
* The factory for generating a bridge method resolver for the current configuration.
*/
protected final BridgeMethodResolver.Factory bridgeMethodResolverFactory;
/**
* The class visitor wrapper chain for the current configuration.
*/
protected final ClassVisitorWrapper.Chain classVisitorWrapperChain;
/**
* The method registry for the current configuration.
*/
protected final MethodRegistry methodRegistry;
/**
* The modifiers to apply to any type that is generated by this configuration.
*/
protected final Definable modifiers;
/**
* The method lookup engine factory to apply to any type that is generated by this configuration.
*/
protected final MethodLookupEngine.Factory methodLookupEngineFactory;
/**
* The type attribute appender factory to apply to any type that is generated by this configuration.
*/
protected final TypeAttributeAppender typeAttributeAppender;
/**
* The default field attribute appender factory which is applied to any field that is defined
* for instrumentations that are applied by this configuration.
*/
protected final FieldAttributeAppender.Factory defaultFieldAttributeAppenderFactory;
/**
* The default method attribute appender factory which is applied to any method that is defined
* or intercepted for instrumentations that are applied by this configuration.
*/
protected final MethodAttributeAppender.Factory defaultMethodAttributeAppenderFactory;
/**
* Defines a new {@code ByteBuddy} default configuration for the current Java virtual machine's
* class file version.
*/
public ByteBuddy() {
this(ClassFileVersion.forCurrentJavaVersion());
}
/**
* Defines a new {@code ByteBuddy} default configuration for the given class file version.
*
* @param classFileVersion The class file version to apply.
*/
public ByteBuddy(ClassFileVersion classFileVersion) {
this(nonNull(classFileVersion),
new NamingStrategy.Unbound.Default(BYTE_BUDDY_DEFAULT_PREFIX),
new TypeList.Empty(),
isDefaultFinalizer().or(isSynthetic().and(not(isVisibilityBridge()))),
BridgeMethodResolver.Simple.Factory.FAIL_ON_REQUEST,
new ClassVisitorWrapper.Chain(),
new MethodRegistry.Default(),
new Definable.Undefined(),
TypeAttributeAppender.NoOp.INSTANCE,
MethodLookupEngine.Default.Factory.INSTANCE,
FieldAttributeAppender.NoOp.INSTANCE,
MethodAttributeAppender.NoOp.INSTANCE);
}
/**
* Defines a new {@code ByteBuddy} configuration.
*
* @param classFileVersion The currently defined class file version.
* @param namingStrategy The currently defined naming strategy.
* @param interfaceTypes The currently defined collection of interfaces to be implemented
* by any dynamically created type.
* @param ignoredMethods The methods to always be ignored.
* @param bridgeMethodResolverFactory The bridge method resolver factory to be applied to any instrumentation
* process.
* @param classVisitorWrapperChain The class visitor wrapper chain to be applied to any instrumentation
* process.
* @param methodRegistry The currently valid method registry.
* @param modifiers The modifiers to define for any instrumentation process.
* @param typeAttributeAppender The type attribute appender to apply to any instrumentation process.
* @param methodLookupEngineFactory The method lookup engine factory to apply to this configuration.
* @param defaultFieldAttributeAppenderFactory The field attribute appender to apply as a default for any field
* definition.
* @param defaultMethodAttributeAppenderFactory The method attribute appender to apply as a default for any
* method definition or instrumentation.
*/
protected ByteBuddy(ClassFileVersion classFileVersion,
NamingStrategy.Unbound namingStrategy,
List interfaceTypes,
ElementMatcher super MethodDescription> ignoredMethods,
BridgeMethodResolver.Factory bridgeMethodResolverFactory,
ClassVisitorWrapper.Chain classVisitorWrapperChain,
MethodRegistry methodRegistry,
Definable modifiers,
TypeAttributeAppender typeAttributeAppender,
MethodLookupEngine.Factory methodLookupEngineFactory,
FieldAttributeAppender.Factory defaultFieldAttributeAppenderFactory,
MethodAttributeAppender.Factory defaultMethodAttributeAppenderFactory) {
this.classFileVersion = classFileVersion;
this.namingStrategy = namingStrategy;
this.interfaceTypes = interfaceTypes;
this.ignoredMethods = ignoredMethods;
this.bridgeMethodResolverFactory = bridgeMethodResolverFactory;
this.classVisitorWrapperChain = classVisitorWrapperChain;
this.methodRegistry = methodRegistry;
this.modifiers = modifiers;
this.typeAttributeAppender = typeAttributeAppender;
this.methodLookupEngineFactory = methodLookupEngineFactory;
this.defaultFieldAttributeAppenderFactory = defaultFieldAttributeAppenderFactory;
this.defaultMethodAttributeAppenderFactory = defaultMethodAttributeAppenderFactory;
}
/**
* Returns the class file version that is defined for the current configuration.
*
* @return The class file version that is defined for this configuration.
*/
public ClassFileVersion getClassFileVersion() {
return classFileVersion;
}
/**
* Returns the naming strategy for the current configuration.
*
* @return The naming strategy for the current configuration.
*/
public NamingStrategy.Unbound getNamingStrategy() {
return namingStrategy;
}
/**
* Returns the naming strategy for the current configuration.
*
* @return The naming strategy for the current configuration.
*/
public List getInterfaceTypes() {
return Collections.unmodifiableList(interfaceTypes);
}
/**
* Returns the matcher for the ignored methods for the current configuration.
*
* @return The matcher for the ignored methods for the current configuration.
*/
public ElementMatcher super MethodDescription> getIgnoredMethods() {
return ignoredMethods;
}
/**
* Returns the factory for the bridge method resolver for the current configuration.
*
* @return The factory for the bridge method resolver for the current configuration.
*/
public BridgeMethodResolver.Factory getBridgeMethodResolverFactory() {
return bridgeMethodResolverFactory;
}
/**
* Returns the class visitor wrapper chain for the current configuration.
*
* @return The class visitor wrapper chain for the current configuration.
*/
public ClassVisitorWrapper.Chain getClassVisitorWrapperChain() {
return classVisitorWrapperChain;
}
/**
* Returns the method registry for the current configuration.
*
* @return The method registry for the current configuration.
*/
public MethodRegistry getMethodRegistry() {
return methodRegistry;
}
/**
* Returns the modifiers to apply to any type that is generated by this configuration.
*
* @return The modifiers to apply to any type that is generated by this configuration.
*/
public Definable getModifiers() {
return modifiers;
}
/**
* Returns the method lookup engine factory to apply to any type that is generated by this configuration.
*
* @return The method lookup engine factory to apply to any type that is generated by this configuration.
*/
public MethodLookupEngine.Factory getMethodLookupEngineFactory() {
return methodLookupEngineFactory;
}
/**
* Returns the type attribute appender factory to apply to any type that is generated by this configuration.
*
* @return The type attribute appender factory to apply to any type that is generated by this configuration.
*/
public TypeAttributeAppender getTypeAttributeAppender() {
return typeAttributeAppender;
}
/**
* Returns the default field attribute appender factory which is applied to any field that is defined
* for instrumentations that are applied by this configuration.
*
* @return The default field attribute appender factory which is applied to any field that is defined
* for instrumentations that are applied by this configuration.
*/
public FieldAttributeAppender.Factory getDefaultFieldAttributeAppenderFactory() {
return defaultFieldAttributeAppenderFactory;
}
/**
* Returns the default method attribute appender factory which is applied to any method that is defined
* or intercepted for instrumentations that are applied by this configuration.
*
* @return The default method attribute appender factory which is applied to any method that is defined
* or intercepted for instrumentations that are applied by this configuration.
*/
public MethodAttributeAppender.Factory getDefaultMethodAttributeAppenderFactory() {
return defaultMethodAttributeAppenderFactory;
}
/**
* Creates a dynamic type builder that creates a subclass of a given loaded type where the subclass
* is created by the {@link com.ui4j.bytebuddy.dynamic.scaffold.subclass.ConstructorStrategy.Default#IMITATE_SUPER_TYPE}
* strategy.
*
* @param superType The type or interface to be extended or implemented by the dynamic type.
* @param The most specific known type that the created dynamic type represents.
* @return A dynamic type builder for this configuration that extends or implements the given loaded type.
*/
public DynamicType.Builder subclass(Class superType) {
return subclass(new TypeDescription.ForLoadedType(nonNull(superType)));
}
/**
* Creates a dynamic type builder that creates a subclass of a given loaded type.
*
* @param superType The type or interface to be extended or implemented by the dynamic type.
* @param constructorStrategy The constructor strategy to apply.
* @param The most specific known type that the created dynamic type represents.
* @return A dynamic type builder for this configuration that extends or implements the given loaded type.
*/
public DynamicType.Builder subclass(Class superType, ConstructorStrategy constructorStrategy) {
return subclass(new TypeDescription.ForLoadedType(nonNull(superType)), constructorStrategy);
}
/**
* Creates a dynamic type builder that creates a subclass of a given type description where the subclass
* is created by the {@link com.ui4j.bytebuddy.dynamic.scaffold.subclass.ConstructorStrategy.Default#IMITATE_SUPER_TYPE}
* strategy.
*
* @param superType The type or interface to be extended or implemented by the dynamic type.
* @param The most specific known type that the created dynamic type represents.
* @return A dynamic type builder for this configuration that extends or implements the given type description.
*/
public DynamicType.Builder subclass(TypeDescription superType) {
return subclass(superType, ConstructorStrategy.Default.IMITATE_SUPER_TYPE);
}
/**
* Creates a dynamic type builder that creates a subclass of a given type description.
*
* @param superType The type or interface to be extended or implemented by the dynamic type.
* @param constructorStrategy The constructor strategy to apply.
* @param The most specific known type that the created dynamic type represents.
* @return A dynamic type builder for this configuration that extends or implements the given type description.
*/
public DynamicType.Builder subclass(TypeDescription superType, ConstructorStrategy constructorStrategy) {
TypeDescription actualSuperType = isExtendable(superType);
List interfaceTypes = this.interfaceTypes;
if (nonNull(superType).isInterface()) {
actualSuperType = new TypeDescription.ForLoadedType(Object.class);
interfaceTypes = join(superType, interfaceTypes);
}
return new SubclassDynamicTypeBuilder(classFileVersion,
nonNull(namingStrategy.subclass(superType)),
actualSuperType,
interfaceTypes,
modifiers.resolve(superType.getModifiers() & ~TypeManifestation.INTERFACE.getMask()),
typeAttributeAppender,
ignoredMethods,
bridgeMethodResolverFactory,
classVisitorWrapperChain,
new FieldRegistry.Default(),
methodRegistry,
methodLookupEngineFactory,
defaultFieldAttributeAppenderFactory,
defaultMethodAttributeAppenderFactory,
nonNull(constructorStrategy));
}
/**
* Creates a dynamic type builder for an interface that extends the given interface.
*
* @param type The interface to extend.
* @param The most specific known type that the created dynamic type represents.
* @return A dynamic type builder for this configuration that defines an interface that extends the specified
* interface.
*/
@SuppressWarnings("unchecked")
public DynamicType.Builder makeInterface(Class type) {
return (DynamicType.Builder) makeInterface(new TypeDescription.ForLoadedType(nonNull(type)));
}
/**
* Creates a dynamic type builder for an interface that extends a number of given interfaces.
*
* @param type The interface types to extend.
* @return A dynamic type builder for this configuration that defines an interface that extends the specified
* interfaces.
*/
public DynamicType.Builder> makeInterface(Class>... type) {
return makeInterface(new TypeList.ForLoadedType(nonNull(type)));
}
/**
* Creates a dynamic type builder for an interface that extends a number of given interface.
*
* @param typeDescription The interface type to extend.
* @return A dynamic type builder for this configuration that defines an interface that extends the specified
* interface.
*/
public DynamicType.Builder> makeInterface(TypeDescription typeDescription) {
return makeInterface(Arrays.asList(nonNull(typeDescription)));
}
/**
* Creates a dynamic type builder for an interface that extends a number of given interfaces.
*
* @param typeDescriptions The interface types to extend.
* @return A dynamic type builder for this configuration that defines an interface that extends the specified
* interfaces.
*/
public DynamicType.Builder> makeInterface(List typeDescriptions) {
return new SubclassDynamicTypeBuilder