当前位置: 首页>>代码示例>>Java>>正文


Java DynamicType.Loaded方法代码示例

本文整理汇总了Java中net.bytebuddy.dynamic.DynamicType.Loaded方法的典型用法代码示例。如果您正苦于以下问题:Java DynamicType.Loaded方法的具体用法?Java DynamicType.Loaded怎么用?Java DynamicType.Loaded使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.bytebuddy.dynamic.DynamicType的用法示例。


在下文中一共展示了DynamicType.Loaded方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testStaticMethodBinding

import net.bytebuddy.dynamic.DynamicType; //导入方法依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testStaticMethodBinding() throws Exception {
    DynamicType.Loaded<T> loaded = new ByteBuddy()
            .subclass(sourceType)
            .method(isDeclaredBy(sourceType))
            .intercept(MethodDelegation.to(targetType))
            .make()
            .load(sourceType.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER);
    assertThat(loaded.getLoadedAuxiliaryTypes().size(), is(0));
    assertThat(loaded.getLoaded().getDeclaredMethods().length, is(1));
    assertThat(loaded.getLoaded().getDeclaredFields().length, is(0));
    T instance = loaded.getLoaded().getDeclaredConstructor().newInstance();
    assertThat(instance.getClass(), not(CoreMatchers.<Class<?>>is(sourceType)));
    assertThat(instance, instanceOf(sourceType));
    assertThat(loaded.getLoaded().getDeclaredMethod(FOO, parameterTypes).invoke(instance, arguments), (Matcher) matcher);
    instance.assertZeroCalls();
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:19,代码来源:MethodDelegationTest.java

示例2: testWithExplicitArgumentField

import net.bytebuddy.dynamic.DynamicType; //导入方法依赖的package包/类
@Test
public void testWithExplicitArgumentField() throws Exception {
    DynamicType.Loaded<MethodCallWithExplicitArgument> loaded = new ByteBuddy()
            .subclass(MethodCallWithExplicitArgument.class)
            .method(isDeclaredBy(MethodCallWithExplicitArgument.class))
            .intercept(MethodCall.invokeSuper().withReference(FOO))
            .make()
            .load(MethodCallWithExplicitArgument.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER);
    assertThat(loaded.getLoadedAuxiliaryTypes().size(), is(0));
    assertThat(loaded.getLoaded().getDeclaredMethods().length, is(1));
    assertThat(loaded.getLoaded().getDeclaredMethod(FOO, String.class), not(nullValue(Method.class)));
    assertThat(loaded.getLoaded().getDeclaredConstructors().length, is(1));
    assertThat(loaded.getLoaded().getDeclaredFields().length, is(1));
    MethodCallWithExplicitArgument instance = loaded.getLoaded().getDeclaredConstructor().newInstance();
    assertThat(instance.getClass(), not(CoreMatchers.<Class<?>>is(MethodCallWithExplicitArgument.class)));
    assertThat(instance, instanceOf(MethodCallWithExplicitArgument.class));
    assertThat(instance.foo(BAR), is(FOO));
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:19,代码来源:MethodCallTest.java

示例3: testBootstrapWithThisValue

import net.bytebuddy.dynamic.DynamicType; //导入方法依赖的package包/类
@Test
@JavaVersionRule.Enforce(7)
public void testBootstrapWithThisValue() throws Exception {
    TypeDescription typeDescription = new TypeDescription.ForLoadedType(Class.forName(ARGUMENT_BOOTSTRAP));
    DynamicType.Loaded<Simple> dynamicType = new ByteBuddy()
            .subclass(Simple.class)
            .method(isDeclaredBy(Simple.class))
            .intercept(InvokeDynamic.bootstrap(typeDescription.getDeclaredMethods().filter(named(BOOTSTRAP)).getOnly())
                    .invoke(BAZ, String.class)
                    .withThis(Object.class))
            .make()
            .load(getClass().getClassLoader(), ClassLoadingStrategy.Default.WRAPPER);
    assertThat(dynamicType.getLoaded().getDeclaredFields().length, is(0));
    Simple simple = dynamicType.getLoaded().getDeclaredConstructor().newInstance();
    assertThat(simple.foo(), is(simple.toString()));
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:17,代码来源:InvokeDynamicTest.java

示例4: testInstanceMethodInvocationWithoutArguments

import net.bytebuddy.dynamic.DynamicType; //导入方法依赖的package包/类
@Test
public void testInstanceMethodInvocationWithoutArguments() throws Exception {
    DynamicType.Loaded<InstanceMethod> loaded = new ByteBuddy()
            .subclass(InstanceMethod.class)
            .method(named(FOO))
            .intercept(MethodCall.invoke(InstanceMethod.class.getDeclaredMethod(BAR)))
            .make()
            .load(SimpleMethod.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER);
    assertThat(loaded.getLoadedAuxiliaryTypes().size(), is(0));
    assertThat(loaded.getLoaded().getDeclaredMethods().length, is(1));
    assertThat(loaded.getLoaded().getDeclaredFields().length, is(0));
    InstanceMethod instance = loaded.getLoaded().getDeclaredConstructor().newInstance();
    assertThat(instance.foo(), is(BAR));
    assertThat(instance.getClass(), not(CoreMatchers.<Class<?>>is(InstanceMethod.class)));
    assertThat(instance, instanceOf(InstanceMethod.class));
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:17,代码来源:MethodCallTest.java

示例5: testUnloadedType

import net.bytebuddy.dynamic.DynamicType; //导入方法依赖的package包/类
@Test
public void testUnloadedType() throws Exception {
    DynamicType.Loaded<SimpleMethod> loaded = new ByteBuddy()
            .subclass(SimpleMethod.class)
            .method(named(FOO))
            .intercept(MethodCall.invoke(Foo.class.getDeclaredMethod(BAR, Object.class, Object.class)).with(TypeDescription.OBJECT, TypeDescription.STRING))
            .make()
            .load(SimpleMethod.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER);
    assertThat(loaded.getLoadedAuxiliaryTypes().size(), is(0));
    assertThat(loaded.getLoaded().getDeclaredMethods().length, is(1));
    assertThat(loaded.getLoaded().getDeclaredFields().length, is(0));
    SimpleMethod instance = loaded.getLoaded().getDeclaredConstructor().newInstance();
    assertThat(instance.foo(), is("" + Object.class + String.class));
    assertThat(instance.getClass(), not(CoreMatchers.<Class<?>>is(SimpleMethod.class)));
    assertThat(instance, instanceOf(SimpleMethod.class));
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:17,代码来源:MethodCallTest.java

示例6: testBootstrapWithArrayArgumentsWithoutArguments

import net.bytebuddy.dynamic.DynamicType; //导入方法依赖的package包/类
@Test
@JavaVersionRule.Enforce(7)
public void testBootstrapWithArrayArgumentsWithoutArguments() throws Exception {
    Class<?> type = Class.forName(PARAMETER_BOOTSTRAP);
    Field field = type.getDeclaredField(ARGUMENTS_FIELD_NAME);
    field.set(null, null);
    TypeDescription typeDescription = new TypeDescription.ForLoadedType(type);
    DynamicType.Loaded<Simple> dynamicType = new ByteBuddy()
            .subclass(Simple.class)
            .method(isDeclaredBy(Simple.class))
            .intercept(InvokeDynamic.bootstrap(typeDescription.getDeclaredMethods().filter(named(BOOTSTRAP_ARRAY_ARGUMENTS)).getOnly())
                    .withoutArguments())
            .make()
            .load(getClass().getClassLoader(), ClassLoadingStrategy.Default.WRAPPER);
    assertThat(dynamicType.getLoaded().getDeclaredConstructor().newInstance().foo(), is(FOO));
    Object[] arguments = (Object[]) field.get(null);
    assertThat(arguments.length, is(0));
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:19,代码来源:InvokeDynamicTest.java

示例7: testImplementationAppendingMethod

import net.bytebuddy.dynamic.DynamicType; //导入方法依赖的package包/类
@Test
public void testImplementationAppendingMethod() throws Exception {
    DynamicType.Loaded<MethodCallAppending> loaded = new ByteBuddy()
            .subclass(MethodCallAppending.class)
            .method(isDeclaredBy(MethodCallAppending.class))
            .intercept(MethodCall.invokeSuper().andThen(new Implementation.Simple(new TextConstant(FOO), MethodReturn.REFERENCE)))
            .make()
            .load(MethodCallAppending.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER);
    assertThat(loaded.getLoadedAuxiliaryTypes().size(), is(0));
    assertThat(loaded.getLoaded().getDeclaredMethods().length, is(1));
    assertThat(loaded.getLoaded().getDeclaredMethod(FOO), not(nullValue(Method.class)));
    assertThat(loaded.getLoaded().getDeclaredConstructors().length, is(1));
    assertThat(loaded.getLoaded().getDeclaredFields().length, is(0));
    MethodCallAppending instance = loaded.getLoaded().getDeclaredConstructor().newInstance();
    assertThat(instance.getClass(), not(CoreMatchers.<Class<?>>is(MethodCallAppending.class)));
    assertThat(instance, instanceOf(MethodCallAppending.class));
    assertThat(instance.foo(), is((Object) FOO));
    instance.assertOnlyCall(FOO);
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:20,代码来源:MethodCallTest.java

示例8: testBootstrapOfMethodsWithParametersWrapperReference

import net.bytebuddy.dynamic.DynamicType; //导入方法依赖的package包/类
@Test
@JavaVersionRule.Enforce(7)
public void testBootstrapOfMethodsWithParametersWrapperReference() throws Exception {
    TypeDescription typeDescription = new TypeDescription.ForLoadedType(Class.forName(ARGUMENT_BOOTSTRAP));
    Object value = new Object();
    DynamicType.Loaded<Simple> dynamicType = new ByteBuddy()
            .subclass(Simple.class)
            .method(isDeclaredBy(Simple.class))
            .intercept(InvokeDynamic.bootstrap(typeDescription.getDeclaredMethods().filter(named(BOOTSTRAP)).getOnly())
                    .invoke(BAR, String.class)
                    .withReference(BOOLEAN, BYTE, SHORT, CHARACTER, INTEGER, LONG, FLOAT, DOUBLE, FOO, CLASS, makeEnum(), makeMethodType(CLASS))
                    .withReference(makeMethodHandle()).as(JavaType.METHOD_HANDLE.load()) // avoid direct method handle
                    .withReference(value))
            .make()
            .load(getClass().getClassLoader(), ClassLoadingStrategy.Default.WRAPPER);
    assertThat(dynamicType.getLoaded().getDeclaredFields().length, is(14));
    assertThat(dynamicType.getLoaded().getDeclaredConstructor().newInstance().foo(),
            is("" + BOOLEAN + BYTE + SHORT + CHARACTER + INTEGER + LONG + FLOAT + DOUBLE + FOO + CLASS + makeEnum()
                    + makeMethodType(CLASS) + makeMethodHandle() + value));
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:21,代码来源:InvokeDynamicTest.java

示例9: testExternalStaticMethodInvocationWithoutArguments

import net.bytebuddy.dynamic.DynamicType; //导入方法依赖的package包/类
@Test
public void testExternalStaticMethodInvocationWithoutArguments() throws Exception {
    DynamicType.Loaded<SimpleMethod> loaded = new ByteBuddy()
            .subclass(SimpleMethod.class)
            .method(named(FOO))
            .intercept(MethodCall.invoke(StaticExternalMethod.class.getDeclaredMethod(BAR)))
            .make()
            .load(SimpleMethod.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER);
    assertThat(loaded.getLoadedAuxiliaryTypes().size(), is(0));
    assertThat(loaded.getLoaded().getDeclaredMethods().length, is(1));
    assertThat(loaded.getLoaded().getDeclaredFields().length, is(0));
    SimpleMethod instance = loaded.getLoaded().getDeclaredConstructor().newInstance();
    assertThat(instance.foo(), is(BAR));
    assertThat(instance.getClass(), not(CoreMatchers.<Class<?>>is(SimpleMethod.class)));
    assertThat(instance, instanceOf(SimpleMethod.class));
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:17,代码来源:MethodCallTest.java

示例10: testPipeToIncompatibleTypeThrowsException

import net.bytebuddy.dynamic.DynamicType; //导入方法依赖的package包/类
@Test(expected = ClassCastException.class)
public void testPipeToIncompatibleTypeThrowsException() throws Exception {
    DynamicType.Loaded<Foo> loaded = new ByteBuddy()
            .subclass(Foo.class)
            .method(isDeclaredBy(Foo.class))
            .intercept(MethodDelegation.withDefaultConfiguration()
                    .withBinders(Pipe.Binder.install(ForwardingType.class))
                    .to(new ForwardingInterceptor(new Object())))
            .make()
            .load(Foo.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER);
    Foo instance = loaded.getLoaded().getDeclaredConstructor().newInstance();
    instance.foo(QUX);
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:14,代码来源:MethodDelegationPipeTest.java

示例11: testDefaultInterface

import net.bytebuddy.dynamic.DynamicType; //导入方法依赖的package包/类
@Test
@JavaVersionRule.Enforce(8)
public void testDefaultInterface() throws Exception {
    DynamicType.Loaded<?> loaded = new ByteBuddy()
            .subclass(Object.class)
            .implement(Class.forName(DEFAULT_INTERFACE))
            .intercept(MethodDelegation.to(Class.forName(DELEGATION_TARGET)))
            .make()
            .load(Class.forName(DEFAULT_INTERFACE).getClassLoader(), ClassLoadingStrategy.Default.WRAPPER);
    Object instance = loaded.getLoaded().getDeclaredConstructor().newInstance();
    assertThat(instance.getClass().getDeclaredMethod(FOO).invoke(instance), is((Object) (FOO + BAR)));
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:13,代码来源:MethodDelegationDefaultTest.java

示例12: testDefaultMethodImplicit

import net.bytebuddy.dynamic.DynamicType; //导入方法依赖的package包/类
@Test
@JavaVersionRule.Enforce(8)
public void testDefaultMethodImplicit() throws Exception {
    DynamicType.Loaded<Object> loaded = new ByteBuddy()
            .subclass(Object.class)
            .implement(Class.forName(DEFAULT_INTERFACE))
            .intercept(MethodDelegation.withDefaultConfiguration()
                    .withBinders(Morph.Binder.install(Morphing.class))
                    .to(Class.forName(DEFAULT_INTERFACE_TARGET_IMPLICIT)))
            .make()
            .load(getClass().getClassLoader(), ClassLoadingStrategy.Default.WRAPPER);
    Object instance = loaded.getLoaded().getDeclaredConstructor().newInstance();
    assertThat(instance.getClass().getDeclaredMethod(FOO, String.class)
            .invoke(instance, QUX), is((Object) (FOO + BAR)));
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:16,代码来源:MethodDelegationMorphTest.java

示例13: testExplicitFieldAccessDuplex

import net.bytebuddy.dynamic.DynamicType; //导入方法依赖的package包/类
@Test
public void testExplicitFieldAccessDuplex() throws Exception {
    DynamicType.Loaded<Explicit> loaded = new ByteBuddy()
            .subclass(Explicit.class)
            .method(isDeclaredBy(Explicit.class))
            .intercept(MethodDelegation.withDefaultConfiguration().withBinders(FieldProxy.Binder.install(GetSet.class)).to(SwapDuplex.class))
            .make()
            .load(Explicit.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER);
    Explicit explicit = loaded.getLoaded().getDeclaredConstructor().newInstance();
    assertThat(explicit.foo, is(FOO));
    explicit.swap();
    assertThat(explicit.foo, is(FOO + BAR));
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:14,代码来源:MethodDelegationFieldProxyTest.java

示例14: testExplicitDefaultCall

import net.bytebuddy.dynamic.DynamicType; //导入方法依赖的package包/类
@Test
@JavaVersionRule.Enforce(8)
public void testExplicitDefaultCall() throws Exception {
    DynamicType.Loaded<?> loaded = new ByteBuddy()
            .subclass(Object.class)
            .implement(Class.forName(SINGLE_DEFAULT_METHOD), Class.forName(CONFLICTING_INTERFACE))
            .intercept(MethodDelegation.to(Class.forName(PREFERRING_INTERCEPTOR)))
            .make()
            .load(getClass().getClassLoader(), ClassLoadingStrategy.Default.WRAPPER);
    Object instance = loaded.getLoaded().getDeclaredConstructor().newInstance();
    Method method = loaded.getLoaded().getMethod(FOO);
    assertThat(method.invoke(instance), is((Object) FOO));
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:14,代码来源:MethodDelegationDefaultCallTest.java

示例15: testSlackNonBindable

import net.bytebuddy.dynamic.DynamicType; //导入方法依赖的package包/类
@Test
public void testSlackNonBindable() throws Exception {
    DynamicType.Loaded<Qux> loaded = new ByteBuddy()
            .subclass(Qux.class)
            .method(isDeclaredBy(Qux.class))
            .intercept(MethodDelegation.to(BazSlack.class))
            .make()
            .load(Foo.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER);
    Qux instance = loaded.getLoaded().getDeclaredConstructor().newInstance();
    assertThat(instance.foo(FOOBAR, BAZ), is((Object) (QUX + BAZ)));
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:12,代码来源:MethodDelegationAllArgumentsTest.java


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