• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java FixedValue类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中net.bytebuddy.implementation.FixedValue的典型用法代码示例。如果您正苦于以下问题:Java FixedValue类的具体用法?Java FixedValue怎么用?Java FixedValue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



FixedValue类属于net.bytebuddy.implementation包,在下文中一共展示了FixedValue类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testRedefinitionReloadingStrategy

import net.bytebuddy.implementation.FixedValue; //导入依赖的package包/类
@Test
@AgentAttachmentRule.Enforce(redefinesClasses = true)
public void testRedefinitionReloadingStrategy() throws Exception {
    assertThat(ByteBuddyAgent.install(), instanceOf(Instrumentation.class));
    Foo foo = new Foo();
    assertThat(foo.foo(), is(FOO));
    ClassReloadingStrategy classReloadingStrategy = new ClassReloadingStrategy(ByteBuddyAgent.getInstrumentation(), ClassReloadingStrategy.Strategy.REDEFINITION);
    new ByteBuddy()
            .redefine(Foo.class)
            .method(named(FOO))
            .intercept(FixedValue.value(BAR))
            .make()
            .load(Foo.class.getClassLoader(), classReloadingStrategy);
    try {
        assertThat(foo.foo(), is(BAR));
    } finally {
        classReloadingStrategy.reset(Foo.class);
        assertThat(foo.foo(), is(FOO));
    }
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:21,代码来源:ClassReloadingStrategyTest.java


示例2: testFromAgentClassReloadingStrategy

import net.bytebuddy.implementation.FixedValue; //导入依赖的package包/类
@Test
@AgentAttachmentRule.Enforce(redefinesClasses = true)
public void testFromAgentClassReloadingStrategy() throws Exception {
    assertThat(ByteBuddyAgent.install(), instanceOf(Instrumentation.class));
    Foo foo = new Foo();
    assertThat(foo.foo(), is(FOO));
    ClassReloadingStrategy classReloadingStrategy = ClassReloadingStrategy.fromInstalledAgent();
    new ByteBuddy()
            .redefine(Foo.class)
            .method(named(FOO))
            .intercept(FixedValue.value(BAR))
            .make()
            .load(Foo.class.getClassLoader(), classReloadingStrategy);
    try {
        assertThat(foo.foo(), is(BAR));
    } finally {
        classReloadingStrategy.reset(Foo.class);
        assertThat(foo.foo(), is(FOO));
    }
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:21,代码来源:ClassReloadingStrategyTest.java


示例3: testFromAgentClassWithAuxiliaryReloadingStrategy

import net.bytebuddy.implementation.FixedValue; //导入依赖的package包/类
@Test
@AgentAttachmentRule.Enforce(redefinesClasses = true)
public void testFromAgentClassWithAuxiliaryReloadingStrategy() throws Exception {
    assertThat(ByteBuddyAgent.install(), instanceOf(Instrumentation.class));
    Foo foo = new Foo();
    assertThat(foo.foo(), is(FOO));
    ClassReloadingStrategy classReloadingStrategy = ClassReloadingStrategy.fromInstalledAgent();
    String randomName = FOO + RandomString.make();
    new ByteBuddy()
            .redefine(Foo.class)
            .method(named(FOO))
            .intercept(FixedValue.value(BAR))
            .make()
            .include(new ByteBuddy().subclass(Object.class).name(randomName).make())
            .load(Foo.class.getClassLoader(), classReloadingStrategy);
    try {
        assertThat(foo.foo(), is(BAR));
    } finally {
        classReloadingStrategy.reset(Foo.class);
        assertThat(foo.foo(), is(FOO));
    }
    assertThat(Class.forName(randomName), notNullValue(Class.class));
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:24,代码来源:ClassReloadingStrategyTest.java


示例4: testRetransformationReloadingStrategy

import net.bytebuddy.implementation.FixedValue; //导入依赖的package包/类
@Test
@AgentAttachmentRule.Enforce(retransformsClasses = true)
public void testRetransformationReloadingStrategy() throws Exception {
    assertThat(ByteBuddyAgent.install(), instanceOf(Instrumentation.class));
    Foo foo = new Foo();
    assertThat(foo.foo(), is(FOO));
    ClassReloadingStrategy classReloadingStrategy = new ClassReloadingStrategy(ByteBuddyAgent.getInstrumentation(), ClassReloadingStrategy.Strategy.RETRANSFORMATION);
    new ByteBuddy()
            .redefine(Foo.class)
            .method(named(FOO))
            .intercept(FixedValue.value(BAR))
            .make()
            .load(Foo.class.getClassLoader(), classReloadingStrategy);
    try {
        assertThat(foo.foo(), is(BAR));
    } finally {
        classReloadingStrategy.reset(Foo.class);
        assertThat(foo.foo(), is(FOO));
    }
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:21,代码来源:ClassReloadingStrategyTest.java


示例5: testAnonymousType

import net.bytebuddy.implementation.FixedValue; //导入依赖的package包/类
@Test
@JavaVersionRule.Enforce(value = 8, atMost = 8)
@AgentAttachmentRule.Enforce(retransformsClasses = true)
public void testAnonymousType() throws Exception {
    ClassLoader classLoader = new ByteArrayClassLoader(ClassLoadingStrategy.BOOTSTRAP_LOADER,
            ClassFileExtraction.of(Class.forName(LAMBDA_SAMPLE_FACTORY)),
            ByteArrayClassLoader.PersistenceHandler.MANIFEST);
    Instrumentation instrumentation = ByteBuddyAgent.install();
    Class<?> factory = classLoader.loadClass(LAMBDA_SAMPLE_FACTORY);
    @SuppressWarnings("unchecked")
    Callable<String> instance = (Callable<String>) factory.getDeclaredMethod("nonCapturing").invoke(factory.getDeclaredConstructor().newInstance());
    // Anonymous types can only be reset to their original format, if a retransformation is applied.
    ClassReloadingStrategy classReloadingStrategy = new ClassReloadingStrategy(instrumentation,
            ClassReloadingStrategy.Strategy.RETRANSFORMATION).preregistered(instance.getClass());
    ClassFileLocator classFileLocator = ClassFileLocator.AgentBased.of(instrumentation, instance.getClass());
    try {
        assertThat(instance.call(), is(FOO));
        new ByteBuddy()
                .redefine(instance.getClass(), classFileLocator)
                .method(named("call"))
                .intercept(FixedValue.value(BAR))
                .make()
                .load(instance.getClass().getClassLoader(), classReloadingStrategy);
        assertThat(instance.call(), is(BAR));
    } finally {
        classReloadingStrategy.reset(classFileLocator, instance.getClass());
        assertThat(instance.call(), is(FOO));
    }
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:30,代码来源:ClassReloadingStrategyTest.java


示例6: testVisibilityBridgeForDefaultMethod

import net.bytebuddy.implementation.FixedValue; //导入依赖的package包/类
@Test
@JavaVersionRule.Enforce(8)
public void testVisibilityBridgeForDefaultMethod() throws Exception {
    Class<?> defaultInterface = new ByteBuddy()
            .makeInterface()
            .merge(Visibility.PACKAGE_PRIVATE)
            .defineMethod(FOO, String.class, Visibility.PUBLIC)
            .intercept(FixedValue.value(BAR))
            .make()
            .load(ClassLoadingStrategy.BOOTSTRAP_LOADER)
            .getLoaded();
    Class<?> type = new ByteBuddy()
            .subclass(defaultInterface)
            .modifiers(Visibility.PUBLIC)
            .make()
            .load(defaultInterface.getClassLoader(), ClassLoadingStrategy.Default.INJECTION)
            .getLoaded();
    assertThat(type.getDeclaredConstructors().length, is(1));
    assertThat(type.getDeclaredMethods().length, is(1));
    Method foo = type.getDeclaredMethod(FOO);
    assertThat(foo.isBridge(), is(true));
    assertThat(foo.invoke(type.getDeclaredConstructor().newInstance()), is((Object) (BAR)));
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:24,代码来源:SubclassDynamicTypeBuilderTest.java


示例7: hello

import net.bytebuddy.implementation.FixedValue; //导入依赖的package包/类
public void hello() throws IllegalAccessException, InstantiationException {

        Class<?> dynamicType = new ByteBuddy()
                .subclass(Bingoo.class)
                        // .name(namingStrategy)
                .method(named("toString")).intercept(FixedValue.value("Hello World!"))
                .make()
                .load(getClass().getClassLoader(), ClassLoadingStrategy.Default.WRAPPER)
                .getLoaded();
        Object instance = dynamicType.newInstance();
        System.out.println(instance.toString()); // "Hello World!"
        System.out.println(dynamicType.getName());
        //assertThat(dynamicType.newInstance().toString(), is("Hello World!"));
    }
 
开发者ID:bingoohuang,项目名称:javacode-demo,代码行数:15,代码来源:ByteBuddyDemo.java


示例8: delegateOrNoop

import net.bytebuddy.implementation.FixedValue; //导入依赖的package包/类
/** Delegates to the given method if available, or does nothing. */
private static Implementation delegateOrNoop(
    TypeDescription doFnType, DoFnSignature.DoFnMethod method) {
  return (method == null)
      ? FixedValue.originType()
      : new DoFnMethodDelegation(doFnType, method.targetMethod());
}
 
开发者ID:apache,项目名称:beam,代码行数:8,代码来源:ByteBuddyDoFnInvokerFactory.java


示例9: addClass

import net.bytebuddy.implementation.FixedValue; //导入依赖的package包/类
private Collection<File> addClass(String name) throws IOException {
    return new ByteBuddy()
            .subclass(Object.class)
            .name(name)
            .defineMethod(FOO, String.class, Visibility.PUBLIC).intercept(FixedValue.value(FOO))
            .defineMethod(BAR, String.class, Visibility.PUBLIC).intercept(FixedValue.value(BAR))
            .make()
            .saveIn(target)
            .values();
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:11,代码来源:TransformationActionTest.java


示例10: addClass

import net.bytebuddy.implementation.FixedValue; //导入依赖的package包/类
private Collection<File> addClass(String name) throws IOException {
    return new ByteBuddy()
            .subclass(Object.class)
            .name(name)
            .defineMethod(FOO, String.class, Visibility.PUBLIC).intercept(FixedValue.value(FOO))
            .defineMethod(BAR, String.class, Visibility.PUBLIC).intercept(FixedValue.value(BAR))
            .make()
            .saveIn(project)
            .values();
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:11,代码来源:ByteBuddyMojoTest.java


示例11: transform

import net.bytebuddy.implementation.FixedValue; //导入依赖的package包/类
@Override
public DynamicType.Builder<?> transform(DynamicType.Builder<?> builder,
                                        TypeDescription typeDescription,
                                        ClassLoader classLoader,
                                        JavaModule module) {
    return builder
            .method(isDeclaredBy(typeDescription).and(named(FOO))).intercept(FixedValue.value(FOO))
            .method(isDeclaredBy(typeDescription).and(named(BAR))).intercept(FixedValue.value(BAR));
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:10,代码来源:AgentBuilderDefaultApplicationSuperTypeLoadingTest.java


示例12: transform

import net.bytebuddy.implementation.FixedValue; //导入依赖的package包/类
@Override
public DynamicType.Builder<?> transform(DynamicType.Builder<?> builder,
                                        TypeDescription typeDescription,
                                        ClassLoader classLoader,
                                        JavaModule module) {
    return builder.method(named(FOO)).intercept(FixedValue.value(BAR));
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:8,代码来源:AgentBuilderDefaultApplicationRedefineTest.java


示例13: testAdviceContainsDeadCode

import net.bytebuddy.implementation.FixedValue; //导入依赖的package包/类
@Test
public void testAdviceContainsDeadCode() throws Exception {
    Class<?> advice = new ByteBuddy(classFileVersion)
            .subclass(Object.class)
            .defineMethod(FOO, void.class, Ownership.STATIC)
            .intercept(new DeadVoidAppender())
            .annotateMethod(AnnotationDescription.Builder.ofType(Advice.OnMethodEnter.class).define("suppress", RuntimeException.class).build())
            .annotateMethod(AnnotationDescription.Builder.ofType(Advice.OnMethodExit.class).define("suppress", RuntimeException.class).build())
            .make()
            .load(getClass().getClassLoader(), ClassLoadingStrategy.Default.WRAPPER_PERSISTENT)
            .getLoaded();
    Class<?> foo = new ByteBuddy(classFileVersion)
            .subclass(Object.class)
            .defineMethod("foo", String.class, Visibility.PUBLIC)
            .intercept(FixedValue.value(FOO))
            .make()
            .load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER_PERSISTENT)
            .getLoaded();
    Class<?> redefined = new ByteBuddy()
            .redefine(foo)
            .visit(Advice.to(advice).on(named(FOO)))
            .make()
            .load(null, ClassLoadingStrategy.Default.CHILD_FIRST)
            .getLoaded();
    assertThat(redefined, not(sameInstance((Object) foo)));
    assertThat(redefined.getDeclaredMethod(FOO).invoke(redefined.getDeclaredConstructor().newInstance()), is((Object) FOO));
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:28,代码来源:AdviceDeadCodeTest.java


示例14: testInconsistentStackSizeAdvice

import net.bytebuddy.implementation.FixedValue; //导入依赖的package包/类
@Test
public void testInconsistentStackSizeAdvice() throws Exception {
    Class<?> advice = new ByteBuddy()
            .subclass(Object.class)
            .defineMethod(FOO, type, Ownership.STATIC)
            .intercept(new InconsistentSizeAppender())
            .annotateMethod(AnnotationDescription.Builder.ofType(Advice.OnMethodEnter.class).define("suppress", RuntimeException.class).build())
            .annotateMethod(AnnotationDescription.Builder.ofType(Advice.OnMethodExit.class).define("suppress", RuntimeException.class).build())
            .make()
            .load(getClass().getClassLoader(), ClassLoadingStrategy.Default.WRAPPER_PERSISTENT)
            .getLoaded();
    Class<?> foo = new ByteBuddy()
            .subclass(Object.class)
            .defineMethod("foo", String.class, Visibility.PUBLIC)
            .intercept(FixedValue.value(FOO))
            .make()
            .load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER_PERSISTENT)
            .getLoaded();
    Class<?> redefined = new ByteBuddy()
            .redefine(foo)
            .visit(Advice.to(advice).on(named(FOO)))
            .make()
            .load(null, ClassLoadingStrategy.Default.CHILD_FIRST)
            .getLoaded();
    assertThat(redefined, not(sameInstance((Object) foo)));
    assertThat(redefined.getDeclaredMethod(FOO).invoke(redefined.getDeclaredConstructor().newInstance()), is((Object) FOO));
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:28,代码来源:AdviceInconsistentStackSizeTest.java


示例15: testGenericMethod

import net.bytebuddy.implementation.FixedValue; //导入依赖的package包/类
@Test
public void testGenericMethod() throws Exception {
    DynamicType.Unloaded<?> unloaded = new ByteBuddy()
            .redefine(GenericMethod.class)
            .method(named(FOO))
            .intercept(FixedValue.nullValue())
            .make();
    Class<?> type = unloaded.load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER).getLoaded();
    MethodDescription createdMethod = new MethodDescription.ForLoadedMethod(type.getDeclaredMethod(FOO, Exception.class));
    MethodDescription originalMethod = new MethodDescription.ForLoadedMethod(GenericMethod.class.getDeclaredMethod(FOO, Exception.class));
    assertThat(createdMethod.getTypeVariables(), is(originalMethod.getTypeVariables()));
    assertThat(createdMethod.getReturnType(), is(originalMethod.getReturnType()));
    assertThat(createdMethod.getParameters().getOnly().getType(), is(originalMethod.getParameters().getOnly().getType()));
    assertThat(createdMethod.getExceptionTypes().getOnly(), is(originalMethod.getExceptionTypes().getOnly()));
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:16,代码来源:GenericSignatureResolutionTest.java


示例16: testGenericMethodWithoutGenericExceptionTypes

import net.bytebuddy.implementation.FixedValue; //导入依赖的package包/类
@Test
public void testGenericMethodWithoutGenericExceptionTypes() throws Exception {
    DynamicType.Unloaded<?> unloaded = new ByteBuddy()
            .redefine(GenericMethod.class)
            .method(named(BAR))
            .intercept(FixedValue.nullValue())
            .make();
    Class<?> type = unloaded.load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER).getLoaded();
    MethodDescription createdMethod = new MethodDescription.ForLoadedMethod(type.getDeclaredMethod(BAR, Object.class));
    MethodDescription originalMethod = new MethodDescription.ForLoadedMethod(GenericMethod.class.getDeclaredMethod(BAR, Object.class));
    assertThat(createdMethod.getTypeVariables(), is(originalMethod.getTypeVariables()));
    assertThat(createdMethod.getReturnType(), is(originalMethod.getReturnType()));
    assertThat(createdMethod.getParameters().getOnly().getType(), is(originalMethod.getParameters().getOnly().getType()));
    assertThat(createdMethod.getExceptionTypes().getOnly(), is(originalMethod.getExceptionTypes().getOnly()));
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:16,代码来源:GenericSignatureResolutionTest.java


示例17: testDefaultMethodOverridden

import net.bytebuddy.implementation.FixedValue; //导入依赖的package包/类
@Test
@JavaVersionRule.Enforce(8)
public void testDefaultMethodOverridden() throws Exception {
    Class<?> interfaceType = Class.forName(DEFAULT_METHOD_INTERFACE);
    Method interfaceMethod = interfaceType.getDeclaredMethod(FOO);
    Class<?> dynamicType = new ByteBuddy()
            .subclass(interfaceType)
            .method(isDeclaredBy(interfaceType)).intercept(FixedValue.value(BAR))
            .make()
            .load(getClass().getClassLoader(), ClassLoadingStrategy.Default.WRAPPER)
            .getLoaded();
    assertThat(dynamicType.getDeclaredFields().length, is(0));
    assertThat(dynamicType.getDeclaredMethods().length, is(1));
    assertThat(interfaceMethod.invoke(dynamicType.getDeclaredConstructor().newInstance()), is((Object) BAR));
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:16,代码来源:SubclassDynamicTypeBuilderTest.java


示例18: testTypeInLegacyConstantPoolRemapped

import net.bytebuddy.implementation.FixedValue; //导入依赖的package包/类
@Test
public void testTypeInLegacyConstantPoolRemapped() throws Exception {
    Class<?> dynamicType = new ByteBuddy(ClassFileVersion.JAVA_V4)
            .with(TypeValidation.DISABLED)
            .subclass(Object.class)
            .defineMethod(FOO, Object.class, Visibility.PUBLIC)
            .intercept(FixedValue.value(Object.class))
            .make()
            .load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER)
            .getLoaded();
    assertThat(dynamicType.getDeclaredMethod(FOO).invoke(dynamicType.getDeclaredConstructor().newInstance()), is((Object) Object.class));
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:13,代码来源:TypeWriterDefaultTest.java


示例19: testArrayTypeInLegacyConstantPoolRemapped

import net.bytebuddy.implementation.FixedValue; //导入依赖的package包/类
@Test
public void testArrayTypeInLegacyConstantPoolRemapped() throws Exception {
    Class<?> dynamicType = new ByteBuddy(ClassFileVersion.JAVA_V4)
            .with(TypeValidation.DISABLED)
            .subclass(Object.class)
            .defineMethod(FOO, Object.class, Visibility.PUBLIC)
            .intercept(FixedValue.value(Object[].class))
            .make()
            .load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER)
            .getLoaded();
    assertThat(dynamicType.getDeclaredMethod(FOO).invoke(dynamicType.getDeclaredConstructor().newInstance()), is((Object) Object[].class));
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:13,代码来源:TypeWriterDefaultTest.java


示例20: testPrimitiveTypeInLegacyConstantPoolRemapped

import net.bytebuddy.implementation.FixedValue; //导入依赖的package包/类
@Test
public void testPrimitiveTypeInLegacyConstantPoolRemapped() throws Exception {
    Class<?> dynamicType = new ByteBuddy(ClassFileVersion.JAVA_V4)
            .with(TypeValidation.DISABLED)
            .subclass(Object.class)
            .defineMethod(FOO, Object.class, Visibility.PUBLIC)
            .intercept(FixedValue.value(int.class))
            .make()
            .load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER)
            .getLoaded();
    assertThat(dynamicType.getDeclaredMethod(FOO).invoke(dynamicType.getDeclaredConstructor().newInstance()), is((Object) int.class));
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:13,代码来源:TypeWriterDefaultTest.java



注:本文中的net.bytebuddy.implementation.FixedValue类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ParseMode类代码示例发布时间:2022-05-23
下一篇:
Java ConnectionInfo类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap