本文整理汇总了Java中net.bytebuddy.agent.builder.AgentBuilder.Transformer方法的典型用法代码示例。如果您正苦于以下问题:Java AgentBuilder.Transformer方法的具体用法?Java AgentBuilder.Transformer怎么用?Java AgentBuilder.Transformer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.bytebuddy.agent.builder.AgentBuilder
的用法示例。
在下文中一共展示了AgentBuilder.Transformer方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createAgentBuilder
import net.bytebuddy.agent.builder.AgentBuilder; //导入方法依赖的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;
}
示例2: getTransformer
import net.bytebuddy.agent.builder.AgentBuilder; //导入方法依赖的package包/类
@Override
public AgentBuilder.Transformer getTransformer() {
return new AgentBuilder.Transformer() {
@Override
public DynamicType.Builder<?> transform(DynamicType.Builder<?> builder, TypeDescription typeDescription,
ClassLoader classLoader, JavaModule module) {
onTypeMatch(typeDescription);
return builder;
}
};
}
示例3: getTransformer
import net.bytebuddy.agent.builder.AgentBuilder; //导入方法依赖的package包/类
public AgentBuilder.Transformer getTransformer() {
final AsmVisitorWrapper.ForDeclaredMethods advice = getAdvice();
if (advice == null) {
return AgentBuilder.Transformer.NoOp.INSTANCE;
} else {
return new AgentBuilder.Transformer() {
@Override
public DynamicType.Builder<?> transform(DynamicType.Builder<?> builder, TypeDescription typeDescription,
ClassLoader classLoader, JavaModule module) {
beforeTransformation(typeDescription, classLoader);
return builder.visit(advice);
}
};
}
}