use of com.navercorp.pinpoint.profiler.instrument.ASMFieldNodeAdapter in project pinpoint by naver.
the class MethodInterfaceTest method addField.
@Test(expected = ClassFormatError.class)
public void addField() throws Exception {
final String targetInterfaceName = "com.navercorp.test.pinpoint.jdk8.interfaces.MethodInterface";
final String targetClassName = "com.navercorp.test.pinpoint.jdk8.interfaces.MethodInterfaceClass";
final String accessorClassName = "com.navercorp.test.pinpoint.jdk8.interfaces.SimpleAccessor";
TestClassLoader classLoader = new TestClassLoader();
classLoader.addTargetClassName(targetClassName);
classLoader.addTargetClassName(targetInterfaceName);
classLoader.setTrace(false);
classLoader.setCallbackHandler(new CallbackHandler() {
@Override
public void handle(ClassNode classNode) {
logger.debug("Add field class={}", classNode.name);
ASMClassNodeAdapter classNodeAdapter = new ASMClassNodeAdapter(pluginContext, null, null, classNode);
classNodeAdapter.addField("_$PINPOINT$_" + JavaAssistUtils.javaClassNameToVariableName(accessorClassName), Type.getDescriptor(int.class));
classNodeAdapter.addInterface(accessorClassName);
ASMFieldNodeAdapter fieldNodeAdapter = classNodeAdapter.getField("_$PINPOINT$_" + JavaAssistUtils.javaClassNameToVariableName(accessorClassName), null);
classNodeAdapter.addGetterMethod("_$PINPOINT$_getTraceInt", fieldNodeAdapter);
classNodeAdapter.addSetterMethod("_$PINPOINT$_setTraceInt", fieldNodeAdapter);
}
});
logger.debug("Interface static method");
Class<?> clazz = classLoader.loadClass(targetInterfaceName);
Method method = clazz.getDeclaredMethod("currentTimeMillis");
method.invoke(null);
}
Aggregations