本文整理汇总了Java中net.bytebuddy.implementation.Implementation类的典型用法代码示例。如果您正苦于以下问题:Java Implementation类的具体用法?Java Implementation怎么用?Java Implementation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Implementation类属于net.bytebuddy.implementation包,在下文中一共展示了Implementation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: check
import net.bytebuddy.implementation.Implementation; //导入依赖的package包/类
@Override
public final void check() throws Exception {
Implementation.Context implementationContext = EasyMock.createMock(
Implementation.Context.class
);
final MethodVisitorRecorder patternMvr = new MethodVisitorRecorder();
final MethodVisitorRecorder actualMvr = new MethodVisitorRecorder();
pattern.accept(patternMvr);
System.out.println("Expectation:");
patternMvr.trace();
sm.apply(actualMvr, implementationContext);
System.out.println("Reality:");
actualMvr.trace();
assertThat(actualMvr).isEqualTo(patternMvr);
}
示例2: createAgentBuilder
import net.bytebuddy.implementation.Implementation; //导入依赖的package包/类
/**
* Creates the AgentBuilder that will redefine the System class.
* @param inst instrumentation instance.
* @return an agent builder.
*/
private static AgentBuilder createAgentBuilder(Instrumentation inst) {
// Find me a class called "java.lang.System"
final ElementMatcher.Junction<NamedElement> systemType = ElementMatchers.named("java.lang.System");
// And then find a method called setSecurityManager and tell MySystemInterceptor to
// intercept it (the method binding is smart enough to take it from there)
final AgentBuilder.Transformer transformer =
(b, typeDescription) -> b.method(ElementMatchers.named("setSecurityManager"))
.intercept(MethodDelegation.to(MySystemInterceptor.class));
// Disable a bunch of stuff and turn on redefine as the only option
final ByteBuddy byteBuddy = new ByteBuddy().with(Implementation.Context.Disabled.Factory.INSTANCE);
final AgentBuilder agentBuilder = new AgentBuilder.Default()
.withByteBuddy(byteBuddy)
.withInitializationStrategy(AgentBuilder.InitializationStrategy.NoOp.INSTANCE)
.withRedefinitionStrategy(AgentBuilder.RedefinitionStrategy.REDEFINITION)
.withTypeStrategy(AgentBuilder.TypeStrategy.Default.REDEFINE)
.type(systemType)
.transform(transformer);
return agentBuilder;
}
示例3: apply
import net.bytebuddy.implementation.Implementation; //导入依赖的package包/类
public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext) {
switch (variableIndex) {
case 0:
methodVisitor.visitInsn(storeOpcode + storeOpcodeShortcutOffset);
break;
case 1:
methodVisitor.visitInsn(storeOpcode + storeOpcodeShortcutOffset + 1);
break;
case 2:
methodVisitor.visitInsn(storeOpcode + storeOpcodeShortcutOffset + 2);
break;
case 3:
methodVisitor.visitInsn(storeOpcode + storeOpcodeShortcutOffset + 3);
break;
default:
methodVisitor.visitVarInsn(storeOpcode, variableIndex);
break;
}
return size;
}
示例4: apply
import net.bytebuddy.implementation.Implementation; //导入依赖的package包/类
public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext,
MethodDescription instrumentedMethod) {
checkMethodSignature(instrumentedMethod);
try {
StackManipulation stack = buildStack();
StackManipulation.Size finalStackSize = stack.apply(methodVisitor, implementationContext);
return new Size(finalStackSize.getMaximalSize(),
instrumentedMethod.getStackSize() + 2); // 2 stack slots for a single local variable
} catch (NoSuchMethodException | NoSuchFieldException e) {
throw new RuntimeException(e);
}
}
示例5: apply
import net.bytebuddy.implementation.Implementation; //导入依赖的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");
}
}
示例6: apply
import net.bytebuddy.implementation.Implementation; //导入依赖的package包/类
@Override
public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext,
MethodDescription instrumentedMethod) {
int numArgs = instrumentedMethod.getParameters().asTypeList().getStackSize();
/**
* Load the desired id
* relative to the method arguments.
* The idea here would be to load references
* to declared variables
*/
//references start with zero if its an instance or zero if its static
//think of it like an implicit self in python without actually being defined
int start = instrumentedMethod.isStatic() ? 1 : 0;
StackManipulation arg0 = MethodVariableAccess.REFERENCE
.loadOffset(numArgs + start + OpCodeUtil.getAloadInstructionForReference(refId));
StackManipulation.Size size = arg0.apply(methodVisitor, implementationContext);
return new Size(size.getMaximalSize(), instrumentedMethod.getStackSize());
}
示例7: testRetrieveFromArray
import net.bytebuddy.implementation.Implementation; //导入依赖的package包/类
@Test
public void testRetrieveFromArray() throws Exception {
DynamicType.Unloaded<RetrieveFromArray> arr = new ByteBuddy().subclass(RetrieveFromArray.class)
.method(ElementMatchers.isDeclaredBy(RetrieveFromArray.class))
.intercept(new Implementation.Compound(new LoadReferenceParamImplementation(1),
new RelativeRetrieveArrayImplementation(1),
new ReturnAppenderImplementation(ReturnAppender.ReturnType.INT)))
.make();
Class<?> dynamicType = arr.load(RetrieveFromArray.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER)
.getLoaded();
RetrieveFromArray test = (RetrieveFromArray) dynamicType.newInstance();
int result = test.returnVal(0, 1);
assertEquals(1, result);
}
示例8: testCreateAndAssign
import net.bytebuddy.implementation.Implementation; //导入依赖的package包/类
@Test
public void testCreateAndAssign() throws Exception {
DynamicType.Unloaded<CreateAndAssignArray> arr = new ByteBuddy().subclass(CreateAndAssignArray.class)
.method(ElementMatchers.isDeclaredBy(CreateAndAssignArray.class))
.intercept(new Implementation.Compound(new IntArrayCreation(5), new DuplicateImplementation(),
new RelativeArrayAssignWithValueImplementation(0, 5),
new ReturnAppenderImplementation(ReturnAppender.ReturnType.REFERENCE)))
.make();
Class<?> dynamicType =
arr.load(CreateAndAssignArray.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER)
.getLoaded();
CreateAndAssignArray test = (CreateAndAssignArray) dynamicType.newInstance();
int[] result = test.create();
assertEquals(5, result[0]);
}
示例9: testCreateInt
import net.bytebuddy.implementation.Implementation; //导入依赖的package包/类
@Test
public void testCreateInt() throws Exception {
DynamicType.Unloaded<CreateAndAssignIntArray> arr = new ByteBuddy().subclass(CreateAndAssignIntArray.class)
.method(ElementMatchers.isDeclaredBy(CreateAndAssignIntArray.class))
.intercept(new Implementation.Compound(new ConstantIntImplementation(1),
new StoreIntImplementation(0), new LoadIntegerImplementation(0),
new ReturnAppenderImplementation(ReturnAppender.ReturnType.INT)))
.make();
Class<?> dynamicType =
arr.load(CreateAndAssignIntArray.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER)
.getLoaded();
CreateAndAssignIntArray test = (CreateAndAssignIntArray) dynamicType.newInstance();
int result = test.returnVal();
assertEquals(1, result);
}
示例10: disableClassFormatChanges
import net.bytebuddy.implementation.Implementation; //导入依赖的package包/类
@Override
public AgentBuilder disableClassFormatChanges() {
return new Default(byteBuddy.with(Implementation.Context.Disabled.Factory.INSTANCE),
listener,
circularityLock,
poolStrategy,
TypeStrategy.Default.REDEFINE_FROZEN,
locationStrategy,
NativeMethodStrategy.Disabled.INSTANCE,
InitializationStrategy.NoOp.INSTANCE,
redefinitionStrategy,
redefinitionDiscoveryStrategy,
redefinitionBatchAllocator,
redefinitionListener,
redefinitionResubmissionStrategy,
bootstrapInjectionStrategy,
lambdaInstrumentationStrategy,
descriptionStrategy,
fallbackStrategy,
installationListener,
ignoredTypeMatcher,
transformation);
}
示例11: bind
import net.bytebuddy.implementation.Implementation; //导入依赖的package包/类
@Override
public Bound.ForMethodEnter bind(TypeDescription instrumentedType,
MethodDescription instrumentedMethod,
MethodVisitor methodVisitor,
Implementation.Context implementationContext,
Assigner assigner,
MethodSizeHandler.ForInstrumentedMethod methodSizeHandler,
StackMapFrameHandler.ForInstrumentedMethod stackMapFrameHandler,
StackManipulation exceptionHandler) {
return new AdviceMethodInliner(instrumentedType,
instrumentedMethod,
methodVisitor,
implementationContext,
assigner,
methodSizeHandler,
stackMapFrameHandler,
suppressionHandler.bind(exceptionHandler),
classReader,
skipDispatcher);
}
示例12: AdviceMethodInliner
import net.bytebuddy.implementation.Implementation; //导入依赖的package包/类
/**
* Creates a new advice method inliner for a method enter.
*
* @param instrumentedType A description of the instrumented type.
* @param instrumentedMethod A description of the instrumented method.
* @param methodVisitor The method visitor for writing the instrumented method.
* @param implementationContext The implementation context to use.
* @param assigner The assigner to use.
* @param methodSizeHandler A handler for computing the method size requirements.
* @param stackMapFrameHandler A handler for translating and injecting stack map frames.
* @param suppressionHandler A bound suppression handler that is used for suppressing exceptions of this advice method.
* @param classReader A class reader for parsing the class file containing the represented advice method.
* @param skipDispatcher The skip dispatcher to use.
*/
protected AdviceMethodInliner(TypeDescription instrumentedType,
MethodDescription instrumentedMethod,
MethodVisitor methodVisitor,
Implementation.Context implementationContext,
Assigner assigner,
MethodSizeHandler.ForInstrumentedMethod methodSizeHandler,
StackMapFrameHandler.ForInstrumentedMethod stackMapFrameHandler,
SuppressionHandler.Bound suppressionHandler,
ClassReader classReader,
SkipDispatcher skipDispatcher) {
super(instrumentedType,
instrumentedMethod,
methodVisitor,
implementationContext,
assigner,
methodSizeHandler,
stackMapFrameHandler,
suppressionHandler,
classReader);
this.skipDispatcher = skipDispatcher;
}
示例13: ForMethodEnter
import net.bytebuddy.implementation.Implementation; //导入依赖的package包/类
/**
* Creates a new advice method writer.
*
* @param adviceMethod The advice method.
* @param instrumentedMethod The instrumented method.
* @param offsetMappings The offset mappings available to this advice.
* @param methodVisitor The method visitor for writing the instrumented method.
* @param implementationContext The implementation context to use.
* @param methodSizeHandler A handler for computing the method size requirements.
* @param stackMapFrameHandler A handler for translating and injecting stack map frames.
* @param suppressionHandler A bound suppression handler that is used for suppressing exceptions of this advice method.
* @param skipDispatcher The skip dispatcher to use.
*/
protected ForMethodEnter(MethodDescription.InDefinedShape adviceMethod,
MethodDescription instrumentedMethod,
List<OffsetMapping.Target> offsetMappings,
MethodVisitor methodVisitor,
Implementation.Context implementationContext,
MethodSizeHandler.ForAdvice methodSizeHandler,
StackMapFrameHandler.ForAdvice stackMapFrameHandler,
SuppressionHandler.Bound suppressionHandler,
Resolved.ForMethodEnter.SkipDispatcher skipDispatcher) {
super(adviceMethod,
instrumentedMethod,
offsetMappings,
methodVisitor,
implementationContext,
methodSizeHandler,
stackMapFrameHandler,
suppressionHandler);
this.skipDispatcher = skipDispatcher;
}
示例14: resolve
import net.bytebuddy.implementation.Implementation; //导入依赖的package包/类
@Override
protected Bound.ForMethodEnter resolve(TypeDescription instrumentedType,
MethodDescription instrumentedMethod,
MethodVisitor methodVisitor,
Implementation.Context implementationContext,
Assigner assigner,
MethodSizeHandler.ForInstrumentedMethod methodSizeHandler,
StackMapFrameHandler.ForInstrumentedMethod stackMapFrameHandler,
StackManipulation exceptionHandler) {
List<OffsetMapping.Target> offsetMappings = new ArrayList<OffsetMapping.Target>(this.offsetMappings.size());
for (OffsetMapping offsetMapping : this.offsetMappings) {
offsetMappings.add(offsetMapping.resolve(instrumentedType,
instrumentedMethod,
assigner,
OffsetMapping.Context.ForMethodEntry.of(instrumentedMethod)));
}
return new AdviceMethodWriter.ForMethodEnter(adviceMethod,
instrumentedMethod,
offsetMappings,
methodVisitor,
implementationContext,
methodSizeHandler.bindEntry(adviceMethod),
stackMapFrameHandler.bindEntry(adviceMethod),
suppressionHandler.bind(exceptionHandler),
skipDispatcher);
}
示例15: wrap
import net.bytebuddy.implementation.Implementation; //导入依赖的package包/类
@Override
public ModifierAdjustingClassVisitor wrap(TypeDescription instrumentedType,
ClassVisitor classVisitor,
Implementation.Context implementationContext,
TypePool typePool,
FieldList<FieldDescription.InDefinedShape> fields,
MethodList<?> methods,
int writerFlags,
int readerFlags) {
Map<String, FieldDescription.InDefinedShape> mappedFields = new HashMap<String, FieldDescription.InDefinedShape>();
for (FieldDescription.InDefinedShape fieldDescription : fields) {
mappedFields.put(fieldDescription.getInternalName() + fieldDescription.getDescriptor(), fieldDescription);
}
Map<String, MethodDescription> mappedMethods = new HashMap<String, MethodDescription>();
for (MethodDescription methodDescription : CompoundList.<MethodDescription>of(methods, new MethodDescription.Latent.TypeInitializer(instrumentedType))) {
mappedMethods.put(methodDescription.getInternalName() + methodDescription.getDescriptor(), methodDescription);
}
return new ModifierAdjustingClassVisitor(classVisitor,
typeAdjustments,
fieldAdjustments,
methodAdjustments,
instrumentedType,
mappedFields,
mappedMethods);
}