本文整理汇总了Java中net.bytebuddy.implementation.bytecode.member.MethodReturn类的典型用法代码示例。如果您正苦于以下问题:Java MethodReturn类的具体用法?Java MethodReturn怎么用?Java MethodReturn使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MethodReturn类属于net.bytebuddy.implementation.bytecode.member包,在下文中一共展示了MethodReturn类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: apply
import net.bytebuddy.implementation.bytecode.member.MethodReturn; //导入依赖的package包/类
@Override
public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext,
MethodDescription instrumentedMethod) {
switch (returnType) {
case REFERENCE:
return new Size(MethodReturn.REFERENCE.apply(methodVisitor, implementationContext).getMaximalSize(),
instrumentedMethod.getStackSize());
case VOID:
return new Size(MethodReturn.VOID.apply(methodVisitor, implementationContext).getMaximalSize(),
instrumentedMethod.getStackSize());
case INT:
return new Size(MethodReturn.INTEGER.apply(methodVisitor, implementationContext).getMaximalSize(),
instrumentedMethod.getStackSize());
default:
throw new IllegalStateException("Illegal opType");
}
}
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:19,代码来源:ReturnAppender.java
示例2: inPlaceSet
import net.bytebuddy.implementation.bytecode.member.MethodReturn; //导入依赖的package包/类
@Test
public void inPlaceSet() throws Exception {
DynamicType.Unloaded<SetValueInPlace> val =
new ByteBuddy().subclass(SetValueInPlace.class)
.method(ElementMatchers.isDeclaredBy(SetValueInPlace.class))
.intercept(new StackManipulationImplementation(new StackManipulation.Compound(
MethodVariableAccess.REFERENCE.loadOffset(1),
MethodVariableAccess.INTEGER.loadOffset(2),
MethodVariableAccess.INTEGER.loadOffset(3),
ArrayStackManipulation.store(), MethodReturn.VOID)))
.make();
val.saveIn(new File("target"));
SetValueInPlace dv = val.load(getClass().getClassLoader(), ClassLoadingStrategy.Default.WRAPPER).getLoaded()
.newInstance();
int[] ret = {2, 4};
int[] assertion = {1, 4};
dv.update(ret, 0, 1);
assertArrayEquals(assertion, ret);
}
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:21,代码来源:AssignImplementationTest.java
示例3: inPlaceDivide
import net.bytebuddy.implementation.bytecode.member.MethodReturn; //导入依赖的package包/类
@Test
public void inPlaceDivide() throws Exception {
DynamicType.Unloaded<SetValueInPlace> val = new ByteBuddy().subclass(SetValueInPlace.class)
.method(ElementMatchers.isDeclaredBy(SetValueInPlace.class))
.intercept(new StackManipulationImplementation(new StackManipulation.Compound(
MethodVariableAccess.REFERENCE.loadOffset(1),
MethodVariableAccess.INTEGER.loadOffset(2), Duplication.DOUBLE,
ArrayStackManipulation.load(), MethodVariableAccess.INTEGER.loadOffset(3),
OpStackManipulation.div(), ArrayStackManipulation.store(), MethodReturn.VOID)))
.make();
val.saveIn(new File("target"));
SetValueInPlace dv = val.load(getClass().getClassLoader(), ClassLoadingStrategy.Default.WRAPPER).getLoaded()
.newInstance();
int[] ret = {2, 4};
int[] assertion = {1, 4};
dv.update(ret, 0, 2);
assertArrayEquals(assertion, ret);
}
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:20,代码来源:AssignImplementationTest.java
示例4: apply
import net.bytebuddy.implementation.bytecode.member.MethodReturn; //导入依赖的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
示例5: apply
import net.bytebuddy.implementation.bytecode.member.MethodReturn; //导入依赖的package包/类
@Override
public Size apply(MethodVisitor methodVisitor, Context implementationContext, MethodDescription instrumentedMethod) {
FieldList<?> fieldList = instrumentedType.getDeclaredFields();
StackManipulation[] fieldLoading = new StackManipulation[fieldList.size()];
int index = 0;
for (FieldDescription fieldDescription : fieldList) {
fieldLoading[index] = new StackManipulation.Compound(
MethodVariableAccess.loadThis(),
MethodVariableAccess.load(instrumentedMethod.getParameters().get(index)),
FieldAccess.forField(fieldDescription).write()
);
index++;
}
StackManipulation.Size stackSize = new StackManipulation.Compound(
MethodVariableAccess.loadThis(),
MethodInvocation.invoke(ConstructorCall.INSTANCE.objectTypeDefaultConstructor),
new StackManipulation.Compound(fieldLoading),
MethodReturn.VOID
).apply(methodVisitor, implementationContext);
return new Size(stackSize.getMaximalSize(), instrumentedMethod.getStackSize());
}
开发者ID:raphw,项目名称:byte-buddy,代码行数:22,代码来源:MethodCallProxy.java
示例6: apply
import net.bytebuddy.implementation.bytecode.member.MethodReturn; //导入依赖的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
示例7: apply
import net.bytebuddy.implementation.bytecode.member.MethodReturn; //导入依赖的package包/类
@Override
public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext, MethodDescription instrumentedMethod) {
if (!instrumentedMethod.isMethod()) {
throw new IllegalArgumentException(instrumentedMethod + " does not describe a field getter or setter");
}
FieldDescription fieldDescription = fieldLocation.resolve(instrumentedMethod);
StackManipulation implementation;
if (!instrumentedMethod.getReturnType().represents(void.class)) {
implementation = new StackManipulation.Compound(getter(fieldDescription, instrumentedMethod), MethodReturn.of(instrumentedMethod.getReturnType()));
} else if (instrumentedMethod.getReturnType().represents(void.class) && instrumentedMethod.getParameters().size() == 1) {
implementation = new StackManipulation.Compound(setter(fieldDescription, instrumentedMethod.getParameters().get(0)), MethodReturn.VOID);
} else {
throw new IllegalArgumentException("Method " + implementationContext + " is no bean property");
}
return new Size(implementation.apply(methodVisitor, implementationContext).getMaximalSize(), instrumentedMethod.getStackSize());
}
开发者ID:raphw,项目名称:byte-buddy,代码行数:17,代码来源:FieldAccessor.java
示例8: testChainingNonVoid
import net.bytebuddy.implementation.bytecode.member.MethodReturn; //导入依赖的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
示例9: testImplementationAppendingMethod
import net.bytebuddy.implementation.bytecode.member.MethodReturn; //导入依赖的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
示例10: testImplementationAppendingConstructor
import net.bytebuddy.implementation.bytecode.member.MethodReturn; //导入依赖的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
示例11: testDefaultInterfaceSubInterface
import net.bytebuddy.implementation.bytecode.member.MethodReturn; //导入依赖的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
示例12: SmtInvokeObjectsHash
import net.bytebuddy.implementation.bytecode.member.MethodReturn; //导入依赖的package包/类
public SmtInvokeObjectsHash() {
super(
new StackManipulation.Compound(
MethodInvocation.invoke(new MethodDescription.ForLoadedMethod(OBJECTS_HASH)),
MethodReturn.INTEGER
)
);
}
开发者ID:project-avral,项目名称:oo-atom,代码行数:9,代码来源:SmtInvokeObjectsHash.java
示例13: result
import net.bytebuddy.implementation.bytecode.member.MethodReturn; //导入依赖的package包/类
@Override
public final Result<StackManipulation> result() {
return new RSuccess<>(
new StackManipulation.Compound(
IntegerConstant.forValue(index),
MethodReturn.INTEGER
)
);
}
开发者ID:project-avral,项目名称:oo-atom,代码行数:10,代码来源:SmtReturnInteger.java
示例14: SmtAtomHashCode
import net.bytebuddy.implementation.bytecode.member.MethodReturn; //导入依赖的package包/类
public SmtAtomHashCode(TypeDescription type) {
super(
new SmtLoadArrayOfFields(type),
new SmtInvokeAtomHashCode(type),
new SmtStatic(
MethodReturn.INTEGER
)
);
}
开发者ID:project-avral,项目名称:oo-atom,代码行数:10,代码来源:SmtAtomHashCode.java
示例15: afterDelegation
import net.bytebuddy.implementation.bytecode.member.MethodReturn; //导入依赖的package包/类
@Override
protected StackManipulation afterDelegation(MethodDescription instrumentedMethod) {
if (TypeDescription.VOID.equals(targetMethod.getReturnType().asErasure())) {
return new StackManipulation.Compound(
MethodInvocation.invoke(PROCESS_CONTINUATION_STOP_METHOD), MethodReturn.REFERENCE);
} else {
return MethodReturn.of(targetMethod.getReturnType().asErasure());
}
}
开发者ID:apache,项目名称:beam,代码行数:10,代码来源:ByteBuddyDoFnInvokerFactory.java
示例16: appender
import net.bytebuddy.implementation.bytecode.member.MethodReturn; //导入依赖的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
示例17: appender
import net.bytebuddy.implementation.bytecode.member.MethodReturn; //导入依赖的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
示例18: buildStack
import net.bytebuddy.implementation.bytecode.member.MethodReturn; //导入依赖的package包/类
private StackManipulation buildStack() throws NoSuchFieldException, NoSuchMethodException {
if (length == 0) {
return MethodReturn.VOID;
}
final int remainder = (int) (length % COPY_STRIDE);
final int iterations = (int) ((length - remainder) / COPY_STRIDE);
// Construct a sequence of stack manipulations
List<StackManipulation> stack = new ArrayList<>();
buildSetupStack(stack);
if (iterations > 0) {
buildLongCopyStack(stack, iterations);
if (remainder == 0) {
// The last increment is not needed
stack.remove(stack.size() - 1);
}
}
if (remainder > 0) {
// Do a couple of more byte by byte copies
buildByteCopyStack(stack, remainder);
// The last increment is not needed
stack.remove(stack.size() - 1);
}
stack.add(MethodReturn.VOID);
return toStackManipulation(stack);
}
开发者ID:bramp,项目名称:unsafe,代码行数:37,代码来源:CopierImplementation.java
示例19: apply
import net.bytebuddy.implementation.bytecode.member.MethodReturn; //导入依赖的package包/类
@Override
public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext,
MethodDescription instrumentedMethod) {
//initialize the stack with the array access with this as reference 0 and the array (first argument) as reference 1
StackManipulation compound = assignOperation();
StackManipulation.Size size = compound.apply(methodVisitor, implementationContext);
//resolve the opType to store in the array and retrieve the store command
StackManipulation store = ArrayAccess.of(typePool.describe("int").resolve()).store();
size = size.aggregate(store.apply(methodVisitor, implementationContext));
//set the return opType (ALWAYS REMEMBER TO DO THIS)
StackManipulation returnOp = MethodReturn.VOID;
size = size.aggregate(returnOp.apply(methodVisitor, implementationContext));
return new Size(size.getMaximalSize(), instrumentedMethod.getStackSize());
}
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:15,代码来源:AssignArrayValueAppender.java
示例20: apply
import net.bytebuddy.implementation.bytecode.member.MethodReturn; //导入依赖的package包/类
@Override
public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext,
MethodDescription instrumentedMethod) {
StackManipulation createArray = IntArrayCreation.intCreationOfLength(length);
StackManipulation.Compound size = new StackManipulation.Compound(createArray, MethodReturn.REFERENCE);
StackManipulation.Size size1 = size.apply(methodVisitor, implementationContext);
return new Size(size1.getMaximalSize(), instrumentedMethod.getStackSize());
}
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:11,代码来源:CreateArrayByteCodeAppender.java
注:本文中的net.bytebuddy.implementation.bytecode.member.MethodReturn类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论