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


Java ByteCodeAppender类代码示例

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


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

示例1: apply

import net.bytebuddy.implementation.bytecode.ByteCodeAppender; //导入依赖的package包/类
/**
 * Applies an implementation that delegates to a invocation handler.
 *
 * @param methodVisitor         The method visitor for writing the byte code to.
 * @param implementationContext The implementation context for the current implementation.
 * @param instrumentedMethod    The method that is instrumented.
 * @param preparingManipulation A stack manipulation that applies any preparation to the operand stack.
 * @param fieldDescription      The field that contains the value for the invocation handler.
 * @return The size of the applied assignment.
 */
protected ByteCodeAppender.Size apply(MethodVisitor methodVisitor,
                                      Context implementationContext,
                                      MethodDescription instrumentedMethod,
                                      StackManipulation preparingManipulation,
                                      FieldDescription fieldDescription) {
    if (instrumentedMethod.isStatic()) {
        throw new IllegalStateException("It is not possible to apply an invocation handler onto the static method " + instrumentedMethod);
    }
    StackManipulation.Size stackSize = new StackManipulation.Compound(
            preparingManipulation,
            FieldAccess.forField(fieldDescription).read(),
            MethodVariableAccess.loadThis(),
            cacheMethods
                    ? MethodConstant.forMethod(instrumentedMethod.asDefined()).cached()
                    : MethodConstant.forMethod(instrumentedMethod.asDefined()),
            ArrayFactory.forType(TypeDescription.Generic.OBJECT).withValues(argumentValuesOf(instrumentedMethod)),
            MethodInvocation.invoke(INVOCATION_HANDLER_TYPE.getDeclaredMethods().getOnly()),
            assigner.assign(TypeDescription.Generic.OBJECT, instrumentedMethod.getReturnType(), Assigner.Typing.DYNAMIC),
            MethodReturn.of(instrumentedMethod.getReturnType())
    ).apply(methodVisitor, implementationContext);
    return new ByteCodeAppender.Size(stackSize.getMaximalSize(), instrumentedMethod.getStackSize());
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:33,代码来源:InvocationHandlerAdapter.java

示例2: apply

import net.bytebuddy.implementation.bytecode.ByteCodeAppender; //导入依赖的package包/类
/**
 * Blueprint method that for applying the actual implementation.
 *
 * @param methodVisitor           The method visitor to which the implementation is applied to.
 * @param implementationContext   The implementation context for the given implementation.
 * @param instrumentedMethod      The instrumented method that is target of the implementation.
 * @param fixedValueType          A description of the type of the fixed value that is loaded by the
 *                                {@code valueLoadingInstruction}.
 * @param valueLoadingInstruction A stack manipulation that represents the loading of the fixed value onto the
 *                                operand stack.
 * @return A representation of the stack and variable array sized that are required for this implementation.
 */
protected ByteCodeAppender.Size apply(MethodVisitor methodVisitor,
                                      Context implementationContext,
                                      MethodDescription instrumentedMethod,
                                      TypeDescription.Generic fixedValueType,
                                      StackManipulation valueLoadingInstruction) {
    StackManipulation assignment = assigner.assign(fixedValueType, instrumentedMethod.getReturnType(), typing);
    if (!assignment.isValid()) {
        throw new IllegalArgumentException("Cannot return value of type " + fixedValueType + " for " + instrumentedMethod);
    }
    StackManipulation.Size stackSize = new StackManipulation.Compound(
            valueLoadingInstruction,
            assignment,
            MethodReturn.of(instrumentedMethod.getReturnType())
    ).apply(methodVisitor, implementationContext);
    return new ByteCodeAppender.Size(stackSize.getMaximalSize(), instrumentedMethod.getStackSize());
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:29,代码来源:FixedValue.java

示例3: initializer

import net.bytebuddy.implementation.bytecode.ByteCodeAppender; //导入依赖的package包/类
@Override
public Builder<U> initializer(ByteCodeAppender byteCodeAppender) {
    return materialize(instrumentedType.withInitializer(byteCodeAppender),
            fieldRegistry,
            methodRegistry,
            typeAttributeAppender,
            asmVisitorWrapper,
            classFileVersion,
            auxiliaryTypeNamingStrategy,
            annotationValueFilterFactory,
            annotationRetention,
            implementationContextFactory,
            methodGraphCompiler,
            typeValidation,
            ignoredMethods);
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:17,代码来源:DynamicType.java

示例4: withInitializer

import net.bytebuddy.implementation.bytecode.ByteCodeAppender; //导入依赖的package包/类
@Override
public WithFlexibleName withInitializer(ByteCodeAppender byteCodeAppender) {
    return new Default(name,
            modifiers,
            superClass,
            typeVariables,
            interfaceTypes,
            fieldTokens,
            methodTokens,
            annotationDescriptions,
            typeInitializer.expandWith(byteCodeAppender),
            loadedTypeInitializer,
            declaringType,
            enclosingMethod,
            enclosingType,
            declaredTypes,
            memberClass,
            anonymousClass,
            localClass);
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:21,代码来源:InstrumentedType.java

示例5: testExplicitTypeInitializer

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

import net.bytebuddy.implementation.bytecode.ByteCodeAppender; //导入依赖的package包/类
@Before
@SuppressWarnings("unchecked")
public void setUp() throws Exception {
    when(methodDescription.getInternalName()).thenReturn(FOO);
    when(methodDescription.getDescriptor()).thenReturn(BAR);
    when(methodDescription.getGenericSignature()).thenReturn(QUX);
    when(methodDescription.getExceptionTypes()).thenReturn(exceptionTypes);
    when(methodDescription.getActualModifiers(anyBoolean(), any(Visibility.class))).thenReturn(MODIFIERS);
    when(exceptionTypes.asErasures()).thenReturn(rawExceptionTypes);
    when(rawExceptionTypes.toInternalNames()).thenReturn(new String[]{BAZ});
    when(classVisitor.visitMethod(MODIFIERS, FOO, BAR, QUX, new String[]{BAZ})).thenReturn(methodVisitor);
    when(methodDescription.getParameters()).thenReturn((ParameterList) new ParameterList.Explicit<ParameterDescription>(parameterDescription));
    when(parameterDescription.getName()).thenReturn(FOO);
    when(parameterDescription.getModifiers()).thenReturn(MODIFIERS);
    when(methodVisitor.visitAnnotationDefault()).thenReturn(annotationVisitor);
    when(byteCodeAppender.apply(methodVisitor, implementationContext, methodDescription))
            .thenReturn(new ByteCodeAppender.Size(ONE, TWO));
    when(otherAppender.apply(methodVisitor, implementationContext, methodDescription))
            .thenReturn(new ByteCodeAppender.Size(ONE * MULTIPLIER, TWO * MULTIPLIER));
    when(annotationValueFilterFactory.on(methodDescription)).thenReturn(annotationValueFilter);
    when(methodDescription.getVisibility()).thenReturn(Visibility.PUBLIC);
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:23,代码来源:TypeWriterMethodPoolRecordTest.java

示例7: apply

import net.bytebuddy.implementation.bytecode.ByteCodeAppender; //导入依赖的package包/类
@Override
public ByteCodeAppender.Size apply(MethodVisitor mv, Implementation.Context p2, MethodDescription p3) {
	mv.visitVarInsn(ALOAD, 0);
	mv.visitMethodInsn(INVOKESPECIAL, "br/com/brjdevs/highhacks/eventbus/ASMEventHandler", "<init>", "()V", false);
	if (!isStatic) {
		mv.visitVarInsn(ALOAD, 0);
		mv.visitVarInsn(ALOAD, 1);
		mv.visitFieldInsn(PUTFIELD, thisClass, "instance", "Ljava/lang/Object;");
	}
	mv.visitInsn(RETURN);
	mv.visitMaxs(2, 2);
	return new ByteCodeAppender.Size(2, 2);
}
 
开发者ID:Mantaro,项目名称:MantaroRPG,代码行数:14,代码来源:ASMEventHandlerConstructor.java

示例8: apply

import net.bytebuddy.implementation.bytecode.ByteCodeAppender; //导入依赖的package包/类
@Override
public ByteCodeAppender.Size apply(MethodVisitor mv, Implementation.Context implementationContext, MethodDescription instrumentedMethod) {
	mv.visitVarInsn(ALOAD, 0);
	if (!isStatic) {
		mv.visitFieldInsn(GETFIELD, thisClass, "instance", "Ljava/lang/Object;");
		mv.visitTypeInsn(CHECKCAST, listenerClass);
	}
	mv.visitVarInsn(ALOAD, 1);
	mv.visitTypeInsn(CHECKCAST, eventClass);
	mv.visitMethodInsn(isStatic ? INVOKESTATIC : INVOKEVIRTUAL, listenerClass, callback.getName(), Type.getMethodDescriptor(callback), false);
	mv.visitInsn(RETURN);
	mv.visitMaxs(2, 2);
	return new Size(2, 2);
}
 
开发者ID:Mantaro,项目名称:MantaroRPG,代码行数:15,代码来源:ASMEventHandlerHandle.java

示例9: appender

import net.bytebuddy.implementation.bytecode.ByteCodeAppender; //导入依赖的package包/类
@Override
public ByteCodeAppender appender(final Target implementationTarget) {
  return new ByteCodeAppender() {
    @Override
    public Size apply(
        MethodVisitor methodVisitor,
        Context implementationContext,
        MethodDescription instrumentedMethod) {
      StackManipulation.Size size =
          new StackManipulation.Compound(
                  // Load the this reference
                  MethodVariableAccess.REFERENCE.loadFrom(0),
                  // Load the delegate argument
                  MethodVariableAccess.REFERENCE.loadFrom(1),
                  // Invoke the super constructor (default constructor of Object)
                  MethodInvocation.invoke(
                      new TypeDescription.ForLoadedType(DoFnInvokerBase.class)
                          .getDeclaredMethods()
                          .filter(
                              ElementMatchers.isConstructor()
                                  .and(ElementMatchers.takesArguments(DoFn.class)))
                          .getOnly()),
                  // Return void.
                  MethodReturn.VOID)
              .apply(methodVisitor, implementationContext);
      return new Size(size.getMaximalSize(), instrumentedMethod.getStackSize());
    }
  };
}
 
开发者ID:apache,项目名称:beam,代码行数:30,代码来源:ByteBuddyDoFnInvokerFactory.java

示例10: appender

import net.bytebuddy.implementation.bytecode.ByteCodeAppender; //导入依赖的package包/类
@Override
public ByteCodeAppender appender(final Target implementationTarget) {
  return new ByteCodeAppender() {
    @Override
    public Size apply(
        MethodVisitor methodVisitor,
        Context implementationContext,
        MethodDescription instrumentedMethod) {
      StackManipulation.Size size =
          new StackManipulation.Compound(
                  // Load the this reference
                  MethodVariableAccess.REFERENCE.loadFrom(0),
                  // Invoke the super constructor (default constructor of Object)
                  MethodInvocation.invoke(
                      new TypeDescription.ForLoadedType(Object.class)
                          .getDeclaredMethods()
                          .filter(
                              ElementMatchers.isConstructor()
                                  .and(ElementMatchers.takesArguments(0)))
                          .getOnly()),
                  // Load the this reference
                  MethodVariableAccess.REFERENCE.loadFrom(0),
                  // Load the delegate argument
                  MethodVariableAccess.REFERENCE.loadFrom(1),
                  // Assign the delegate argument to the delegate field
                  FieldAccess.forField(
                          implementationTarget
                              .getInstrumentedType()
                              .getDeclaredFields()
                              .filter(ElementMatchers.named(FN_DELEGATE_FIELD_NAME))
                              .getOnly())
                      .write(),
                  // Return void.
                  MethodReturn.VOID)
              .apply(methodVisitor, implementationContext);
      return new Size(size.getMaximalSize(), instrumentedMethod.getStackSize());
    }
  };
}
 
开发者ID:apache,项目名称:beam,代码行数:40,代码来源:ByteBuddyOnTimerInvokerFactory.java

示例11: appender

import net.bytebuddy.implementation.bytecode.ByteCodeAppender; //导入依赖的package包/类
@Override
public ByteCodeAppender appender(Target implementationTarget) {
    FieldLocator.Resolution resolution = fieldLocatorFactory.make(implementationTarget.getInstrumentedType()).locate(fieldName);
    if (!resolution.isResolved()) {
        throw new IllegalStateException("Could not find a field named '" + fieldName + "' for " + implementationTarget.getInstrumentedType());
    } else if (!resolution.getField().getType().asErasure().isAssignableTo(InvocationHandler.class)) {
        throw new IllegalStateException("Field " + resolution.getField() + " does not declare a type that is assignable to invocation handler");
    }
    return new Appender(implementationTarget.getInstrumentedType(), resolution.getField());
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:11,代码来源:InvocationHandlerAdapter.java

示例12: appender

import net.bytebuddy.implementation.bytecode.ByteCodeAppender; //导入依赖的package包/类
@Override
public ByteCodeAppender appender(Target implementationTarget) {
    ByteCodeAppender[] byteCodeAppender = new ByteCodeAppender[implementations.size()];
    int index = 0;
    for (Implementation implementation : implementations) {
        byteCodeAppender[index++] = implementation.appender(implementationTarget);
    }
    return new ByteCodeAppender.Compound(byteCodeAppender);
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:10,代码来源:Implementation.java

示例13: appender

import net.bytebuddy.implementation.bytecode.ByteCodeAppender; //导入依赖的package包/类
@Override
public ByteCodeAppender appender(Target implementationTarget) {
    ImplementationDelegate.Compiled compiled = implementationDelegate.compile(implementationTarget.getInstrumentedType());
    return new Appender(implementationTarget,
            new MethodDelegationBinder.Processor(compiled.getRecords(), ambiguityResolver, bindingResolver),
            terminationHandler,
            assigner,
            compiled);
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:10,代码来源:MethodDelegation.java

示例14: apply

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

示例15: WithBody

import net.bytebuddy.implementation.bytecode.ByteCodeAppender; //导入依赖的package包/类
/**
 * Creates a new entry for a method that defines a method as byte code.
 *
 * @param methodDescription       The implemented method.
 * @param byteCodeAppender        The byte code appender to apply.
 * @param methodAttributeAppender The method attribute appender to apply.
 * @param visibility              The represented method's minimum visibility.
 */
public WithBody(MethodDescription methodDescription,
                ByteCodeAppender byteCodeAppender,
                MethodAttributeAppender methodAttributeAppender,
                Visibility visibility) {
    this.methodDescription = methodDescription;
    this.byteCodeAppender = byteCodeAppender;
    this.methodAttributeAppender = methodAttributeAppender;
    this.visibility = visibility;
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:18,代码来源:TypeWriter.java


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