本文整理汇总了Java中net.bytebuddy.ClassFileVersion类的典型用法代码示例。如果您正苦于以下问题:Java ClassFileVersion类的具体用法?Java ClassFileVersion怎么用?Java ClassFileVersion使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ClassFileVersion类属于net.bytebuddy包,在下文中一共展示了ClassFileVersion类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: wrap
import net.bytebuddy.ClassFileVersion; //导入依赖的package包/类
@Override
public ClassVisitor wrap(TypeDescription typeDescription, ClassVisitor cv, Context context, TypePool typePool,
FieldList<FieldDescription.InDefinedShape> fieldList, MethodList<?> methodList, int i, int i1)
{
// public void visit(int version, int modifiers, String name, String signature, String superName, String[] interfaces) {
cv.visit(ClassFileVersion.JAVA_V9.getMinorMajorVersion(), typeDescription.getModifiers(), typeDescription.getInternalName(), null,
typeDescription.getSuperClass().asErasure().getInternalName(), typeDescription.getInterfaces().asErasures().toInternalNames());
TypeDescription clazz = this.clazz;
String internalName = clazz.getInternalName();
String descriptor = clazz.getDescriptor();
MethodList<InDefinedShape> declaredMethods = clazz.getDeclaredMethods();
int methodsSize = declaredMethods.size();
String implName = GENERATED_PREFIX + "." + clazz.getName();
String internalImplName = GENERATED_PREFIX.replace('.', '/') + "/" + internalName;
String descriptorImplName = "L" + GENERATED_PREFIX.replace('.', '/') + "/" + internalName + ";";
FieldVisitor fv;
MethodVisitor mv;
AnnotationVisitor av0;
cv.visitEnd();
return cv;
}
示例2: transform
import net.bytebuddy.ClassFileVersion; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Nullable
public static <T extends Annotation> Class<? extends T> transform(Class<T> clazz)
{
if (! clazz.isAnnotation() || ! (clazz.isAnnotationPresent(Qualifier.class) || clazz.isAnnotationPresent(Scope.class)))
{
return null;
}
try
{
String name = GENERATED_PREFIX + "." + clazz.getName();
Unloaded<Object> make = new ByteBuddy(ClassFileVersion.JAVA_V9).subclass(Object.class, ConstructorStrategy.Default.NO_CONSTRUCTORS)
.implement(Serializable.class, clazz).name(name)
.visit(new AnnotationImplementationVisitor(new ForLoadedType(clazz))).make();
Loaded<Object> load = make.load(ClassLoader.getSystemClassLoader(), Default.INJECTION);
return (Class<? extends T>) load.getLoaded();
}
catch (Throwable e)
{
throw new RuntimeException(e);
}
}
示例3: Default
import net.bytebuddy.ClassFileVersion; //导入依赖的package包/类
/**
* Creates a new default implementation context.
*
* @param instrumentedType The description of the type that is currently subject of creation.
* @param classFileVersion The class file version of the created class.
* @param auxiliaryTypeNamingStrategy The naming strategy for naming an auxiliary type.
* @param typeInitializer The type initializer of the created instrumented type.
* @param auxiliaryClassFileVersion The class file version to use for auxiliary classes.
*/
protected Default(TypeDescription instrumentedType,
ClassFileVersion classFileVersion,
AuxiliaryType.NamingStrategy auxiliaryTypeNamingStrategy,
TypeInitializer typeInitializer,
ClassFileVersion auxiliaryClassFileVersion) {
super(instrumentedType, classFileVersion);
this.auxiliaryTypeNamingStrategy = auxiliaryTypeNamingStrategy;
this.typeInitializer = typeInitializer;
this.auxiliaryClassFileVersion = auxiliaryClassFileVersion;
registeredAccessorMethods = new HashMap<SpecialMethodInvocation, DelegationRecord>();
registeredGetters = new HashMap<FieldDescription, DelegationRecord>();
registeredSetters = new HashMap<FieldDescription, DelegationRecord>();
auxiliaryTypes = new HashMap<AuxiliaryType, DynamicType>();
registeredFieldCacheEntries = new HashMap<FieldCacheEntry, FieldDescription.InDefinedShape>();
suffix = RandomString.make();
fieldCacheCanAppendEntries = true;
}
示例4: SubclassDynamicTypeBuilder
import net.bytebuddy.ClassFileVersion; //导入依赖的package包/类
/**
* Creates a new type builder for creating a subclass.
*
* @param instrumentedType An instrumented type representing the subclass.
* @param classFileVersion The class file version to use for types that are not based on an existing class file.
* @param auxiliaryTypeNamingStrategy The naming strategy to use for naming auxiliary types.
* @param annotationValueFilterFactory The annotation value filter factory to use.
* @param annotationRetention The annotation retention strategy to use.
* @param implementationContextFactory The implementation context factory to use.
* @param methodGraphCompiler The method graph compiler to use.
* @param typeValidation Determines if a type should be explicitly validated.
* @param ignoredMethods A matcher for identifying methods that should be excluded from instrumentation.
* @param constructorStrategy The constructor strategy to apply onto the instrumented type.
*/
public SubclassDynamicTypeBuilder(InstrumentedType.WithFlexibleName instrumentedType,
ClassFileVersion classFileVersion,
AuxiliaryType.NamingStrategy auxiliaryTypeNamingStrategy,
AnnotationValueFilter.Factory annotationValueFilterFactory,
AnnotationRetention annotationRetention,
Implementation.Context.Factory implementationContextFactory,
MethodGraph.Compiler methodGraphCompiler,
TypeValidation typeValidation,
LatentMatcher<? super MethodDescription> ignoredMethods,
ConstructorStrategy constructorStrategy) {
this(instrumentedType,
new FieldRegistry.Default(),
new MethodRegistry.Default(),
TypeAttributeAppender.ForInstrumentedType.INSTANCE,
AsmVisitorWrapper.NoOp.INSTANCE,
classFileVersion,
auxiliaryTypeNamingStrategy,
annotationValueFilterFactory,
annotationRetention,
implementationContextFactory,
methodGraphCompiler,
typeValidation,
ignoredMethods,
constructorStrategy);
}
示例5: visitMethod
import net.bytebuddy.ClassFileVersion; //导入依赖的package包/类
@Override
public MethodVisitor visitMethod(int modifiers,
String internalName,
String descriptor,
String genericSignature,
String[] exceptionName) {
if (internalName.equals(MethodDescription.TYPE_INITIALIZER_INTERNAL_NAME)) {
MethodVisitor methodVisitor = super.visitMethod(modifiers, internalName, descriptor, genericSignature, exceptionName);
return methodVisitor == null
? IGNORE_METHOD
: (MethodVisitor) (initializationHandler = InitializationHandler.Appending.of(implementationContext.isEnabled(),
methodVisitor,
instrumentedType,
methodPool,
annotationValueFilterFactory,
(writerFlags & ClassWriter.COMPUTE_FRAMES) == 0 && implementationContext.getClassFileVersion().isAtLeast(ClassFileVersion.JAVA_V6),
(readerFlags & ClassReader.EXPAND_FRAMES) != 0));
} else {
MethodDescription methodDescription = declarableMethods.remove(internalName + descriptor);
return methodDescription == null
? super.visitMethod(modifiers, internalName, descriptor, genericSignature, exceptionName)
: redefine(methodDescription, (modifiers & Opcodes.ACC_ABSTRACT) != 0, genericSignature);
}
}
示例6: testInstrumentationLegacyClassFileArrayType
import net.bytebuddy.ClassFileVersion; //导入依赖的package包/类
@Test
public void testInstrumentationLegacyClassFileArrayType() throws Exception {
ClassVisitor classVisitor = TypeConstantAdjustment.INSTANCE.wrap(mock(TypeDescription.class),
this.classVisitor,
mock(Implementation.Context.class),
mock(TypePool.class),
new FieldList.Empty<FieldDescription.InDefinedShape>(),
new MethodList.Empty<MethodDescription>(),
IGNORED,
IGNORED);
classVisitor.visit(ClassFileVersion.JAVA_V4.getMinorMajorVersion(), FOOBAR, FOO, BAR, QUX, new String[]{BAZ});
MethodVisitor methodVisitor = classVisitor.visitMethod(FOOBAR, FOO, BAR, QUX, new String[]{BAZ});
assertThat(methodVisitor, not(this.methodVisitor));
methodVisitor.visitLdcInsn(Type.getType(Object[].class));
verify(this.classVisitor).visit(ClassFileVersion.JAVA_V4.getMinorMajorVersion(), FOOBAR, FOO, BAR, QUX, new String[]{BAZ});
verify(this.classVisitor).visitMethod(FOOBAR, FOO, BAR, QUX, new String[]{BAZ});
verifyNoMoreInteractions(this.classVisitor);
verify(this.methodVisitor).visitLdcInsn(Type.getType(Object[].class).getInternalName().replace('/', '.'));
verify(this.methodVisitor).visitMethodInsn(Opcodes.INVOKESTATIC,
Type.getType(Class.class).getInternalName(),
"forName",
Type.getType(Class.class.getDeclaredMethod("forName", String.class)).getDescriptor(),
false);
verifyNoMoreInteractions(this.methodVisitor);
}
示例7: apply
import net.bytebuddy.ClassFileVersion; //导入依赖的package包/类
@Override
public Statement apply(Statement base, FrameworkMethod method, Object target) {
Enforce enforce = method.getAnnotation(Enforce.class);
if (enforce != null) {
if (!currentVersion.isAtLeast(ClassFileVersion.ofJavaVersion(enforce.value()))) {
return new NoOpStatement(enforce.value(), "at least");
} else if (!currentVersion.isAtMost(ClassFileVersion.ofJavaVersion(enforce.atMost()))) {
return new NoOpStatement(enforce.atMost(), "at most");
} else if (!hotSpot) {
for (int javaVersion : enforce.hotSpot()) {
if (currentVersion.getJavaVersion() == javaVersion) {
return new NoOpHotSpotStatement(javaVersion);
}
}
}
}
return base;
}
示例8: makeTypeWithAnnotation
import net.bytebuddy.ClassFileVersion; //导入依赖的package包/类
private Class<?> makeTypeWithAnnotation(Annotation annotation) throws Exception {
when(valueFilter.isRelevant(any(AnnotationDescription.class), any(MethodDescription.InDefinedShape.class))).thenReturn(true);
ClassWriter classWriter = new ClassWriter(AsmVisitorWrapper.NO_FLAGS);
classWriter.visit(ClassFileVersion.ofThisVm().getMinorMajorVersion(),
Opcodes.ACC_PUBLIC,
BAR.replace('.', '/'),
null,
Type.getInternalName(Object.class),
null);
AnnotationVisitor annotationVisitor = classWriter.visitAnnotation(Type.getDescriptor(annotation.annotationType()), true);
when(target.visit(any(String.class), anyBoolean())).thenReturn(annotationVisitor);
AnnotationDescription annotationDescription = AnnotationDescription.ForLoadedAnnotation.of(annotation);
annotationAppender.append(annotationDescription, valueFilter);
classWriter.visitEnd();
Class<?> bar = new ByteArrayClassLoader(getClass().getClassLoader(), Collections.singletonMap(BAR, classWriter.toByteArray())).loadClass(BAR);
assertThat(bar.getName(), is(BAR));
assertThat(bar.getSuperclass(), CoreMatchers.<Class<?>>is(Object.class));
return bar;
}
示例9: makeTypeWithSuperClassAnnotation
import net.bytebuddy.ClassFileVersion; //导入依赖的package包/类
private Class<?> makeTypeWithSuperClassAnnotation(Annotation annotation) throws Exception {
when(valueFilter.isRelevant(any(AnnotationDescription.class), any(MethodDescription.InDefinedShape.class))).thenReturn(true);
ClassWriter classWriter = new ClassWriter(AsmVisitorWrapper.NO_FLAGS);
classWriter.visit(ClassFileVersion.ofThisVm().getMinorMajorVersion(),
Opcodes.ACC_PUBLIC,
BAR.replace('.', '/'),
null,
Type.getInternalName(Object.class),
null);
AnnotationVisitor annotationVisitor = classWriter.visitTypeAnnotation(TypeReference.newSuperTypeReference(-1).getValue(),
null,
Type.getDescriptor(annotation.annotationType()),
true);
when(target.visit(any(String.class), anyBoolean())).thenReturn(annotationVisitor);
AnnotationDescription annotationDescription = AnnotationDescription.ForLoadedAnnotation.of(annotation);
annotationAppender.append(annotationDescription, valueFilter);
classWriter.visitEnd();
Class<?> bar = new ByteArrayClassLoader(getClass().getClassLoader(), Collections.singletonMap(BAR, classWriter.toByteArray())).loadClass(BAR);
assertThat(bar.getName(), is(BAR));
assertThat(bar.getSuperclass(), CoreMatchers.<Class<?>>is(Object.class));
return bar;
}
示例10: testConstantCreationModernVisible
import net.bytebuddy.ClassFileVersion; //导入依赖的package包/类
@Test
public void testConstantCreationModernVisible() throws Exception {
when(classFileVersion.isAtLeast(ClassFileVersion.JAVA_V5)).thenReturn(true);
when(declaringType.isVisibleTo(instrumentedType)).thenReturn(true);
StackManipulation stackManipulation = new FieldConstant(fieldDescription);
assertThat(stackManipulation.isValid(), is(true));
StackManipulation.Size size = stackManipulation.apply(methodVisitor, implementationContext);
assertThat(size.getSizeImpact(), is(1));
assertThat(size.getMaximalSize(), is(2));
verify(methodVisitor).visitLdcInsn(Type.getObjectType(QUX));
verify(methodVisitor).visitLdcInsn(BAR);
verify(methodVisitor).visitMethodInsn(Opcodes.INVOKEVIRTUAL,
"java/lang/Class",
"getDeclaredField",
"(Ljava/lang/String;)Ljava/lang/reflect/Field;",
false);
verifyNoMoreInteractions(methodVisitor);
}
示例11: testConstantCreationModernInvisible
import net.bytebuddy.ClassFileVersion; //导入依赖的package包/类
@Test
public void testConstantCreationModernInvisible() throws Exception {
when(classFileVersion.isAtLeast(ClassFileVersion.JAVA_V5)).thenReturn(true);
when(declaringType.isVisibleTo(instrumentedType)).thenReturn(false);
StackManipulation stackManipulation = new FieldConstant(fieldDescription);
assertThat(stackManipulation.isValid(), is(true));
StackManipulation.Size size = stackManipulation.apply(methodVisitor, implementationContext);
assertThat(size.getSizeImpact(), is(1));
assertThat(size.getMaximalSize(), is(2));
verify(methodVisitor).visitLdcInsn(BAZ);
verify(methodVisitor).visitMethodInsn(Opcodes.INVOKESTATIC,
Type.getInternalName(Class.class),
"forName",
Type.getMethodDescriptor(Type.getType(Class.class), Type.getType(String.class)),
false);
verify(methodVisitor).visitLdcInsn(BAR);
verify(methodVisitor).visitMethodInsn(Opcodes.INVOKEVIRTUAL,
"java/lang/Class",
"getDeclaredField",
"(Ljava/lang/String;)Ljava/lang/reflect/Field;",
false);
verifyNoMoreInteractions(methodVisitor);
}
示例12: testConstantCreationLegacy
import net.bytebuddy.ClassFileVersion; //导入依赖的package包/类
@Test
public void testConstantCreationLegacy() throws Exception {
when(classFileVersion.isAtLeast(ClassFileVersion.JAVA_V5)).thenReturn(false);
when(declaringType.isVisibleTo(instrumentedType)).thenReturn(true);
StackManipulation stackManipulation = new FieldConstant(fieldDescription);
assertThat(stackManipulation.isValid(), is(true));
StackManipulation.Size size = stackManipulation.apply(methodVisitor, implementationContext);
assertThat(size.getSizeImpact(), is(1));
assertThat(size.getMaximalSize(), is(2));
verify(methodVisitor).visitLdcInsn(BAZ);
verify(methodVisitor).visitMethodInsn(Opcodes.INVOKESTATIC,
Type.getInternalName(Class.class),
"forName",
Type.getMethodDescriptor(Type.getType(Class.class), Type.getType(String.class)),
false);
verify(methodVisitor).visitLdcInsn(BAR);
verify(methodVisitor).visitMethodInsn(Opcodes.INVOKEVIRTUAL,
"java/lang/Class",
"getDeclaredField",
"(Ljava/lang/String;)Ljava/lang/reflect/Field;",
false);
verifyNoMoreInteractions(methodVisitor);
}
示例13: testClassConstantModernVisible
import net.bytebuddy.ClassFileVersion; //导入依赖的package包/类
@Test
public void testClassConstantModernVisible() throws Exception {
when(typeDescription.isVisibleTo(instrumentedType)).thenReturn(true);
when(classFileVersion.isAtLeast(ClassFileVersion.JAVA_V5)).thenReturn(true);
when(typeDescription.getDescriptor()).thenReturn(FOO);
StackManipulation stackManipulation = ClassConstant.of(typeDescription);
assertThat(stackManipulation.isValid(), is(true));
StackManipulation.Size size = stackManipulation.apply(methodVisitor, implementationContext);
assertThat(size.getSizeImpact(), is(1));
assertThat(size.getMaximalSize(), is(1));
verify(typeDescription).getDescriptor();
verify(typeDescription).isVisibleTo(instrumentedType);
verify(typeDescription, times(9)).represents(any(Class.class));
verifyNoMoreInteractions(typeDescription);
verify(methodVisitor).visitLdcInsn(Type.getType(FOO));
verifyNoMoreInteractions(methodVisitor);
}
示例14: testClassConstantModernInvisible
import net.bytebuddy.ClassFileVersion; //导入依赖的package包/类
@Test
public void testClassConstantModernInvisible() throws Exception {
when(typeDescription.isVisibleTo(instrumentedType)).thenReturn(false);
when(classFileVersion.isAtLeast(ClassFileVersion.JAVA_V5)).thenReturn(true);
when(typeDescription.getName()).thenReturn(FOO);
StackManipulation stackManipulation = ClassConstant.of(typeDescription);
assertThat(stackManipulation.isValid(), is(true));
StackManipulation.Size size = stackManipulation.apply(methodVisitor, implementationContext);
assertThat(size.getSizeImpact(), is(1));
assertThat(size.getMaximalSize(), is(1));
verify(typeDescription).getName();
verify(typeDescription).isVisibleTo(instrumentedType);
verify(typeDescription, times(9)).represents(any(Class.class));
verifyNoMoreInteractions(typeDescription);
verify(methodVisitor).visitLdcInsn(FOO);
verify(methodVisitor).visitMethodInsn(Opcodes.INVOKESTATIC,
Type.getInternalName(Class.class),
"forName",
Type.getMethodDescriptor(Type.getType(Class.class), Type.getType(String.class)),
false);
verifyNoMoreInteractions(methodVisitor);
}
示例15: testClassConstantLegacy
import net.bytebuddy.ClassFileVersion; //导入依赖的package包/类
@Test
public void testClassConstantLegacy() throws Exception {
when(typeDescription.isVisibleTo(instrumentedType)).thenReturn(true);
when(classFileVersion.isAtLeast(ClassFileVersion.JAVA_V5)).thenReturn(false);
when(typeDescription.getName()).thenReturn(FOO);
StackManipulation stackManipulation = ClassConstant.of(typeDescription);
assertThat(stackManipulation.isValid(), is(true));
StackManipulation.Size size = stackManipulation.apply(methodVisitor, implementationContext);
assertThat(size.getSizeImpact(), is(1));
assertThat(size.getMaximalSize(), is(1));
verify(typeDescription).getName();
verify(typeDescription, times(9)).represents(any(Class.class));
verifyNoMoreInteractions(typeDescription);
verify(methodVisitor).visitLdcInsn(FOO);
verify(methodVisitor).visitMethodInsn(Opcodes.INVOKESTATIC,
Type.getInternalName(Class.class),
"forName",
Type.getMethodDescriptor(Type.getType(Class.class), Type.getType(String.class)),
false);
verifyNoMoreInteractions(methodVisitor);
}