本文整理汇总了Java中net.bytebuddy.ClassFileVersion类的典型用法代码示例。如果您正苦于以下问题:Java ClassFileVersion类的具体用法?Java ClassFileVersion怎么用?Java ClassFileVersion使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ClassFileVersion类属于net.bytebuddy包,在下文中一共展示了ClassFileVersion类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:Diorite,项目名称:Diorite,代码行数:24,代码来源:TransformerInvokerGenerator.java
示例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);
}
}
开发者ID:Diorite,项目名称:Diorite,代码行数:23,代码来源:QualifierAndScopeImplementationGenerator.java
示例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;
}
开发者ID:raphw,项目名称:byte-buddy,代码行数:27,代码来源:Implementation.java
示例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);
}
开发者ID:raphw,项目名称:byte-buddy,代码行数:40,代码来源:SubclassDynamicTypeBuilder.java
示例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);
}
}
开发者ID:raphw,项目名称:byte-buddy,代码行数:25,代码来源:TypeWriter.java
示例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);
}
开发者ID:raphw,项目名称:byte-buddy,代码行数:26,代码来源:TypeConstantAdjustmentTest.java
示例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;
}
开发者ID:raphw,项目名称:byte-buddy,代码行数:19,代码来源:JavaVersionRule.java
示例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;
}
开发者ID:raphw,项目名称:byte-buddy,代码行数:20,代码来源:AnnotationAppenderDefaultTest.java
示例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;
}
开发者ID:raphw,项目名称:byte-buddy,代码行数:23,代码来源:AnnotationAppenderDefaultTest.java
示例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);
}
开发者ID:raphw,项目名称:byte-buddy,代码行数:19,代码来源:FieldConstantTest.java
示例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);
}
开发者ID:raphw,项目名称:byte-buddy,代码行数:24,代码来源:FieldConstantTest.java
示例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);
}
开发者ID:raphw,项目名称:byte-buddy,代码行数:24,代码来源:FieldConstantTest.java
示例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);
}
开发者ID:raphw,项目名称:byte-buddy,代码行数:18,代码来源:ClassConstantReferenceTest.java
示例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);
}
开发者ID:raphw,项目名称:byte-buddy,代码行数:23,代码来源:ClassConstantReferenceTest.java
示例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);
}
开发者ID:raphw,项目名称:byte-buddy,代码行数:22,代码来源:ClassConstantReferenceTest.java
示例16: getPropertyNameExtractor
import net.bytebuddy.ClassFileVersion; //导入依赖的package包/类
public static <T> T getPropertyNameExtractor(Class<T> type) {
DynamicType.Builder<?> builder = new ByteBuddy(ClassFileVersion.JAVA_V8)
.subclass(type.isInterface() ? Object.class : type);
if (type.isInterface()) {
builder = builder.implement(type);
}
Class<?> proxyType = builder
.method(ElementMatchers.any())
.intercept(MethodDelegation.to(PropertyNameExtractorInterceptor.class))
.make()
.load(
PropertyNames.class.getClassLoader(),
ClassLoadingStrategy.Default.WRAPPER
)
.getLoaded();
try {
@SuppressWarnings("unchecked")
Class<T> typed = (Class<T>) proxyType;
return typed.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
throw new RuntimeException(
"Couldn't instantiate proxy for method name retrieval", e
);
}
}
开发者ID:strangeway-org,项目名称:nameof,代码行数:29,代码来源:PropertyNames.java
示例17: create
import net.bytebuddy.ClassFileVersion; //导入依赖的package包/类
private static Class<? extends Page> create(Class<? extends Page> pageType) {
String className = pageType.getCanonicalName() + "$$Impl";
ClassLoader classLoader = pageType.getClassLoader();
InvocationHandler identifyUsingHandler = new IdentifyUsingInvocationHandler();
Builder<BasePage> pageTypeBuilder = new ByteBuddy()//
.with(ClassFileVersion.JAVA_V8)
.subclass(BasePage.class, ConstructorStrategy.Default.IMITATE_SUPER_CLASS)
.implement(pageType)
.name(className);
if (ClasspathUtils.KOTLIN_MODULE_LOADED) {
pageTypeBuilder = addKotlinImplementations(pageTypeBuilder, pageType);
}
pageTypeBuilder = pageTypeBuilder//
.method(isDefaultMethod())//
.intercept(Advice.to(ActionAdvice.class)//
.wrap(DefaultMethodCall.prioritize(pageType)));
pageTypeBuilder = pageTypeBuilder//
.method(isAbstract().and(isAnnotatedWith(IdentifyUsing.class)).and(takesArguments(0)))
.intercept(InvocationHandlerAdapter.of(identifyUsingHandler));
return pageTypeBuilder.make().load(classLoader).getLoaded();
}
开发者ID:testIT-WebTester,项目名称:webtester2-core,代码行数:30,代码来源:PageImplementation.java
示例18: create
import net.bytebuddy.ClassFileVersion; //导入依赖的package包/类
private static Class<? extends PageFragment> create(Class<? extends PageFragment> pageFragmentType) {
String className = pageFragmentType.getCanonicalName() + "$$Impl";
ClassLoader classLoader = pageFragmentType.getClassLoader();
InvocationHandler identifyUsingHandler = new IdentifyUsingInvocationHandler();
InvocationHandler attributeHandler = new AttributeInvocationHandler();
Builder<BasePageFragment> pageFragmentTypeBuilder = new ByteBuddy()//
.with(ClassFileVersion.JAVA_V8)
.subclass(BasePageFragment.class, ConstructorStrategy.Default.IMITATE_SUPER_CLASS)
.implement(pageFragmentType)
.name(className);
if (ClasspathUtils.KOTLIN_MODULE_LOADED) {
pageFragmentTypeBuilder = addKotlinImplementations(pageFragmentTypeBuilder, pageFragmentType);
}
pageFragmentTypeBuilder = pageFragmentTypeBuilder//
.method(isDefaultMethod())//
.intercept(Advice.to(ActionAdvice.class)//
.wrap(Advice.to(MarkingAdvice.class)//
.wrap(Advice.to(EventProducerAdvice.class)//
.wrap(DefaultMethodCall.prioritize(pageFragmentType)))));
pageFragmentTypeBuilder = pageFragmentTypeBuilder//
.method(isAbstract().and(isAnnotatedWith(IdentifyUsing.class)).and(takesArguments(0)))
.intercept(InvocationHandlerAdapter.of(identifyUsingHandler));
pageFragmentTypeBuilder = pageFragmentTypeBuilder//
.method(isAbstract().and(isAnnotatedWith(Attribute.class)).and(takesArguments(0)))
.intercept(Advice.to(MarkingAdvice.class)//
.wrap(InvocationHandlerAdapter.of(attributeHandler)));
return pageFragmentTypeBuilder.make().load(classLoader).getLoaded();
}
开发者ID:testIT-WebTester,项目名称:webtester2-core,代码行数:38,代码来源:PageFragmentImplementation.java
示例19: transform
import net.bytebuddy.ClassFileVersion; //导入依赖的package包/类
/**
* Applies all registered transformations.
*
* @param root The root directory to process.
* @param entryPoint The transformation's entry point.
* @param classPath A list of class path elements expected by the processed classes.
* @param plugins The plugins to apply.
* @throws IOException If an I/O exception occurs.
*/
private void transform(File root, Iterable<? extends File> classPath, EntryPoint entryPoint, List<Plugin> plugins) throws IOException {
List<ClassFileLocator> classFileLocators = new ArrayList<ClassFileLocator>();
classFileLocators.add(new ClassFileLocator.ForFolder(root));
for (File artifact : classPath) {
classFileLocators.add(artifact.isFile()
? ClassFileLocator.ForJarFile.of(artifact)
: new ClassFileLocator.ForFolder(artifact));
}
ClassFileLocator classFileLocator = new ClassFileLocator.Compound(classFileLocators);
try {
TypePool typePool = new TypePool.Default.WithLazyResolution(new TypePool.CacheProvider.Simple(),
classFileLocator,
TypePool.Default.ReaderMode.FAST,
TypePool.ClassLoading.ofBootPath());
project.getLogger().info("Processing class files located in in: {}", root);
JavaPluginConvention convention = (JavaPluginConvention) project.getConvention().getPlugins().get("java");
ByteBuddy byteBuddy;
try {
byteBuddy = entryPoint.byteBuddy(convention == null
? ClassFileVersion.ofThisVm()
: ClassFileVersion.ofJavaVersion(Integer.parseInt(convention.getTargetCompatibility().getMajorVersion())));
} catch (Throwable throwable) {
throw new GradleException("Cannot create Byte Buddy instance", throwable);
}
processDirectory(root,
root,
byteBuddy,
entryPoint,
byteBuddyExtension.getMethodNameTransformer(),
classFileLocator,
typePool,
plugins);
} finally {
classFileLocator.close();
}
}
开发者ID:raphw,项目名称:byte-buddy,代码行数:46,代码来源:TransformationAction.java
示例20: testAllLegalNotIgnoreFinalizer
import net.bytebuddy.ClassFileVersion; //导入依赖的package包/类
@Test
public void testAllLegalNotIgnoreFinalizer() throws Exception {
when(implementationTarget.getInstrumentedType()).thenReturn(foo);
when(invocationFactory.invoke(eq(implementationTarget), eq(foo), any(MethodDescription.class)))
.thenReturn(specialMethodInvocation);
when(specialMethodInvocation.isValid()).thenReturn(true);
when(specialMethodInvocation.apply(any(MethodVisitor.class), any(Implementation.Context.class)))
.thenReturn(new StackManipulation.Size(0, 0));
when(methodAccessorFactory.registerAccessorFor(specialMethodInvocation, MethodAccessorFactory.AccessType.DEFAULT)).thenReturn(proxyMethod);
TypeDescription dynamicType = new TypeProxy(foo,
implementationTarget,
invocationFactory,
false,
false)
.make(BAR, ClassFileVersion.ofThisVm(), methodAccessorFactory)
.getTypeDescription();
assertThat(dynamicType.getModifiers(), is(modifiers));
assertThat(dynamicType.getSuperClass().asErasure(), is(foo));
assertThat(dynamicType.getInterfaces(), is((TypeList.Generic) new TypeList.Generic.Empty()));
assertThat(dynamicType.getName(), is(BAR));
assertThat(dynamicType.getDeclaredMethods().size(), is(2));
assertThat(dynamicType.isAssignableTo(Serializable.class), is(false));
verify(methodAccessorFactory, times(fooMethods.size() + 1)).registerAccessorFor(specialMethodInvocation, MethodAccessorFactory.AccessType.DEFAULT);
for (MethodDescription methodDescription : fooMethods) {
verify(invocationFactory).invoke(implementationTarget, foo, methodDescription);
}
verify(invocationFactory).invoke(implementationTarget, foo,
new MethodDescription.ForLoadedMethod(Object.class.getDeclaredMethod("finalize")));
verifyNoMoreInteractions(invocationFactory);
verify(specialMethodInvocation, times(fooMethods.size() + 1)).isValid();
verifyNoMoreInteractions(specialMethodInvocation);
}
开发者ID:raphw,项目名称:byte-buddy,代码行数:33,代码来源:TypeProxyCreationTest.java
注:本文中的net.bytebuddy.ClassFileVersion类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论