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


Java TextConstant类代码示例

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


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

示例1: testChainingNonVoid

import net.bytebuddy.implementation.bytecode.constant.TextConstant; //导入依赖的package包/类
@Test
public void testChainingNonVoid() throws Exception {
    NonVoidInterceptor nonVoidInterceptor = new NonVoidInterceptor();

    DynamicType.Loaded<Foo> dynamicType = new ByteBuddy().subclass(Foo.class)
            .method(isDeclaredBy(Foo.class))
            .intercept(MethodDelegation.
                    withDefaultConfiguration()
                    .filter(isDeclaredBy(NonVoidInterceptor.class))
                    .to(nonVoidInterceptor)
                    .andThen(new Implementation.Simple(new TextConstant(FOO), MethodReturn.REFERENCE)))
            .make()
            .load(Foo.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER);
    assertThat(dynamicType.getLoaded().getDeclaredConstructor().newInstance().foo(), is(FOO));
    assertThat(nonVoidInterceptor.intercepted, is(true));
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:17,代码来源:MethodDelegationChainedTest.java

示例2: testWithExplicitArgumentStackManipulation

import net.bytebuddy.implementation.bytecode.constant.TextConstant; //导入依赖的package包/类
@Test
public void testWithExplicitArgumentStackManipulation() throws Exception {
    DynamicType.Loaded<MethodCallWithExplicitArgument> loaded = new ByteBuddy()
            .subclass(MethodCallWithExplicitArgument.class)
            .method(isDeclaredBy(MethodCallWithExplicitArgument.class))
            .intercept(MethodCall.invokeSuper().with(new TextConstant(FOO), String.class))
            .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(0));
    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: testImplementationAppendingMethod

import net.bytebuddy.implementation.bytecode.constant.TextConstant; //导入依赖的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

示例4: testImplementationAppendingConstructor

import net.bytebuddy.implementation.bytecode.constant.TextConstant; //导入依赖的package包/类
@Test
public void testImplementationAppendingConstructor() throws Exception {
    DynamicType.Loaded<MethodCallAppending> loaded = new ByteBuddy()
            .subclass(MethodCallAppending.class)
            .method(isDeclaredBy(MethodCallAppending.class))
            .intercept(MethodCall.construct(Object.class.getDeclaredConstructor())
                    .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.assertZeroCalls();
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:21,代码来源:MethodCallTest.java

示例5: testExplicitTypeInitializer

import net.bytebuddy.implementation.bytecode.constant.TextConstant; //导入依赖的package包/类
@Test
public void testExplicitTypeInitializer() throws Exception {
    assertThat(createPlain()
            .defineField(FOO, String.class, Ownership.STATIC, Visibility.PUBLIC)
            .initializer(new ByteCodeAppender() {
                @Override
                public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext, MethodDescription instrumentedMethod) {
                    return new Size(new StackManipulation.Compound(
                            new TextConstant(FOO),
                            FieldAccess.forField(instrumentedMethod.getDeclaringType().getDeclaredFields().filter(named(FOO)).getOnly()).write()
                    ).apply(methodVisitor, implementationContext).getMaximalSize(), instrumentedMethod.getStackSize());
                }
            }).make()
            .load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER)
            .getLoaded()
            .getDeclaredField(FOO)
            .get(null), is((Object) FOO));
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:19,代码来源:AbstractDynamicTypeBuilderTest.java

示例6: testDefaultInterfaceSubInterface

import net.bytebuddy.implementation.bytecode.constant.TextConstant; //导入依赖的package包/类
@Test
@JavaVersionRule.Enforce(8)
public void testDefaultInterfaceSubInterface() throws Exception {
    Class<?> interfaceType = Class.forName(DEFAULT_METHOD_INTERFACE);
    Class<?> dynamicInterfaceType = new ByteBuddy()
            .redefine(interfaceType)
            .method(named(FOO)).intercept(new Implementation.Simple(new TextConstant(BAR), MethodReturn.REFERENCE))
            .make()
            .load(getClass().getClassLoader(), ClassLoadingStrategy.Default.CHILD_FIRST)
            .getLoaded();
    Class<?> dynamicClassType = new ByteBuddy()
            .subclass(dynamicInterfaceType)
            .make()
            .load(dynamicInterfaceType.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER)
            .getLoaded();
    assertThat(dynamicClassType.getMethod(FOO).invoke(dynamicClassType.getDeclaredConstructor().newInstance()), is((Object) BAR));
    assertThat(dynamicInterfaceType.getDeclaredMethods().length, is(1));
    assertThat(dynamicClassType.getDeclaredMethods().length, is(0));
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:20,代码来源:RedefinitionDynamicTypeBuilderTest.java

示例7: apply

import net.bytebuddy.implementation.bytecode.constant.TextConstant; //导入依赖的package包/类
@Override
public Size apply(
    MethodVisitor methodVisitor,
    Context implementationContext,
    MethodDescription instrumentedMethod) {
  Map<String, FieldDescription> fieldsByName = CodeGenUtil.fieldsByName(implementationContext);
  StackManipulation.Size operandStackSize =
      new StackManipulation.Compound(
              new TextConstant(unserializedFieldValue),
              SerializeSupport_serializeString,
              FieldAccess.forField(fieldsByName.get(fieldName)).write())
          .apply(methodVisitor, implementationContext);
  return new Size(operandStackSize.getMaximalSize(), instrumentedMethod.getStackSize());
}
 
开发者ID:curioswitch,项目名称:curiostack,代码行数:15,代码来源:SetSerializedFieldName.java

示例8: appender

import net.bytebuddy.implementation.bytecode.constant.TextConstant; //导入依赖的package包/类
@Override
public ByteCodeAppender appender(Target implementationTarget) {
    TypeDescription serializedLambda;
    try {
        serializedLambda = new TypeDescription.ForLoadedType(Class.forName("java.lang.invoke.SerializedLambda"));
    } catch (ClassNotFoundException exception) {
        throw new IllegalStateException("Cannot find class for lambda serialization", exception);
    }
    List<StackManipulation> lambdaArguments = new ArrayList<StackManipulation>(implementationTarget.getInstrumentedType().getDeclaredFields().size());
    for (FieldDescription.InDefinedShape fieldDescription : implementationTarget.getInstrumentedType().getDeclaredFields()) {
        lambdaArguments.add(new StackManipulation.Compound(MethodVariableAccess.loadThis(),
                FieldAccess.forField(fieldDescription).read(),
                Assigner.DEFAULT.assign(fieldDescription.getType(), TypeDescription.Generic.OBJECT, Assigner.Typing.STATIC)));
    }
    return new ByteCodeAppender.Simple(new StackManipulation.Compound(
            TypeCreation.of(serializedLambda),
            Duplication.SINGLE,
            ClassConstant.of(targetType),
            new TextConstant(lambdaType.getInternalName()),
            new TextConstant(lambdaMethodName),
            new TextConstant(lambdaMethod.getDescriptor()),
            IntegerConstant.forValue(targetMethod.getHandleType().getIdentifier()),
            new TextConstant(targetMethod.getOwnerType().getInternalName()),
            new TextConstant(targetMethod.getName()),
            new TextConstant(targetMethod.getDescriptor()),
            new TextConstant(specializedMethod.getDescriptor()),
            ArrayFactory.forType(TypeDescription.Generic.OBJECT).withValues(lambdaArguments),
            MethodInvocation.invoke(serializedLambda.getDeclaredMethods().filter(isConstructor()).getOnly()),
            MethodReturn.REFERENCE
    ));
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:32,代码来源:AgentBuilder.java

示例9: make

import net.bytebuddy.implementation.bytecode.constant.TextConstant; //导入依赖的package包/类
@Override
public StackManipulation make() {
    return new StackManipulation.Compound(
            TypeCreation.of(exceptionType),
            Duplication.SINGLE,
            new TextConstant(message),
            MethodInvocation.invoke(targetConstructor));
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:9,代码来源:ExceptionMethod.java

示例10: apply

import net.bytebuddy.implementation.bytecode.constant.TextConstant; //导入依赖的package包/类
@Override
public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext, MethodDescription instrumentedMethod) {
    try {
        return new ByteCodeAppender.Simple(new StackManipulation.Compound(
                MethodInvocation.invoke(new MethodDescription.ForLoadedMethod(ClassLoader.class.getMethod("getSystemClassLoader"))),
                new TextConstant(Nexus.class.getName()),
                MethodInvocation.invoke(new MethodDescription.ForLoadedMethod(ClassLoader.class.getMethod("loadClass", String.class))),
                new TextConstant("initialize"),
                ArrayFactory.forType(new TypeDescription.Generic.OfNonGenericType.ForLoadedType(Class.class))
                        .withValues(Arrays.asList(
                                ClassConstant.of(TypeDescription.CLASS),
                                ClassConstant.of(new TypeDescription.ForLoadedType(int.class)))),
                MethodInvocation.invoke(new MethodDescription.ForLoadedMethod(Class.class.getMethod("getMethod", String.class, Class[].class))),
                NullConstant.INSTANCE,
                ArrayFactory.forType(TypeDescription.Generic.OBJECT)
                        .withValues(Arrays.asList(
                                ClassConstant.of(instrumentedMethod.getDeclaringType().asErasure()),
                                new StackManipulation.Compound(
                                        IntegerConstant.forValue(identification),
                                        MethodInvocation.invoke(new MethodDescription.ForLoadedMethod(Integer.class.getMethod("valueOf", int.class)))))),
                MethodInvocation.invoke(new MethodDescription.ForLoadedMethod(Method.class.getMethod("invoke", Object.class, Object[].class))),
                Removal.SINGLE
        )).apply(methodVisitor, implementationContext, instrumentedMethod);
    } catch (NoSuchMethodException exception) {
        throw new IllegalStateException("Cannot locate method", exception);
    }
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:28,代码来源:NexusAccessor.java

示例11: bind

import net.bytebuddy.implementation.bytecode.constant.TextConstant; //导入依赖的package包/类
@Override
public MethodDelegationBinder.ParameterBinding<?> bind(AnnotationDescription.Loadable<StringValue> annotation,
                                                       MethodDescription source,
                                                       ParameterDescription target,
                                                       Implementation.Target implementationTarget,
                                                       Assigner assigner,
                                                       Assigner.Typing typing) {
    if (!target.getType().asErasure().represents(String.class)) {
        throw new IllegalStateException(target + " makes wrong use of StringValue");
    }
    StackManipulation constant = new TextConstant(annotation.loadSilent().value());
    return new MethodDelegationBinder.ParameterBinding.Anonymous(constant);
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:14,代码来源:ByteBuddyTutorialExamplesTest.java

示例12: testChainingVoid

import net.bytebuddy.implementation.bytecode.constant.TextConstant; //导入依赖的package包/类
@Test
public void testChainingVoid() throws Exception {
    VoidInterceptor voidInterceptor = new VoidInterceptor();
    DynamicType.Loaded<Foo> dynamicType = new ByteBuddy().subclass(Foo.class)
            .method(isDeclaredBy(Foo.class))
            .intercept(MethodDelegation.withDefaultConfiguration()
                    .filter(isDeclaredBy(VoidInterceptor.class))
                    .to(voidInterceptor)
                    .andThen(new Implementation.Simple(new TextConstant(FOO), MethodReturn.REFERENCE)))
            .make()
            .load(Foo.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER);
    assertThat(dynamicType.getLoaded().getDeclaredConstructor().newInstance().foo(), is(FOO));
    assertThat(voidInterceptor.intercepted, is(true));
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:15,代码来源:MethodDelegationChainedTest.java

示例13: testAndThen

import net.bytebuddy.implementation.bytecode.constant.TextConstant; //导入依赖的package包/类
@Test
public void testAndThen() throws Exception {
    DynamicType.Loaded<Foo> loaded = new ByteBuddy()
            .subclass(Foo.class)
            .method(isDeclaredBy(Foo.class))
            .intercept(SuperMethodCall.INSTANCE.andThen(new Implementation.Simple(new TextConstant(FOO), MethodReturn.REFERENCE)))
            .make()
            .load(Foo.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER);
    Foo foo = loaded.getLoaded().getDeclaredConstructor().newInstance();
    assertThat(foo.foo(), is(FOO));
    foo.assertOnlyCall(FOO);
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:13,代码来源:SuperMethodCallOtherTest.java

示例14: testMethodDefinition

import net.bytebuddy.implementation.bytecode.constant.TextConstant; //导入依赖的package包/类
@Test
public void testMethodDefinition() throws Exception {
    Class<?> type = createPlain()
            .defineMethod(FOO, Object.class, Visibility.PUBLIC)
            .throwing(Exception.class)
            .intercept(new Implementation.Simple(new TextConstant(FOO), MethodReturn.REFERENCE))
            .make()
            .load(new URLClassLoader(new URL[0], null), ClassLoadingStrategy.Default.WRAPPER)
            .getLoaded();
    Method method = type.getDeclaredMethod(FOO);
    assertThat(method.getReturnType(), CoreMatchers.<Class<?>>is(Object.class));
    assertThat(method.getExceptionTypes(), is(new Class<?>[]{Exception.class}));
    assertThat(method.getModifiers(), is(Modifier.PUBLIC));
    assertThat(method.invoke(type.getDeclaredConstructor().newInstance()), is((Object) FOO));
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:16,代码来源:AbstractDynamicTypeBuilderTest.java

示例15: testApplicationOrder

import net.bytebuddy.implementation.bytecode.constant.TextConstant; //导入依赖的package包/类
@Test
public void testApplicationOrder() throws Exception {
    assertThat(createPlain()
            .method(named(TO_STRING)).intercept(new Implementation.Simple(new TextConstant(FOO), MethodReturn.REFERENCE))
            .method(named(TO_STRING)).intercept(new Implementation.Simple(new TextConstant(BAR), MethodReturn.REFERENCE))
            .make()
            .load(new URLClassLoader(new URL[0], null), ClassLoadingStrategy.Default.WRAPPER)
            .getLoaded()
            .getDeclaredConstructor()
            .newInstance()
            .toString(), is(BAR));
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:13,代码来源:AbstractDynamicTypeBuilderTest.java


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