use of javassist.CtClass in project pinpoint by naver.
the class JavassistMethod method addLocalVariable.
private void addLocalVariable(String name, Class<?> type) throws CannotCompileException, NotFoundException {
final String interceptorClassName = type.getName();
final CtClass interceptorCtClass = behavior.getDeclaringClass().getClassPool().get(interceptorClassName);
behavior.addLocalVariable(name, interceptorCtClass);
}
use of javassist.CtClass in project pinpoint by naver.
the class JavassistMethod method addAfterInterceptor.
private void addAfterInterceptor(InterceptorDefinition interceptorDefinition, int interceptorId, boolean localVarsInitialized, int originalCodeOffset) throws NotFoundException, CannotCompileException {
final Class<?> interceptorClass = interceptorDefinition.getInterceptorClass();
final CaptureType captureType = interceptorDefinition.getCaptureType();
if (!isAfterInterceptor(captureType)) {
return;
}
final Method interceptorMethod = interceptorDefinition.getAfterMethod();
if (interceptorMethod == null) {
if (isDebug) {
logger.debug("Skip adding after interceptor because the interceptor doesn't have after method: {}", interceptorClass.getName());
}
return;
}
InvokeAfterCodeGenerator catchGenerator = new InvokeAfterCodeGenerator(interceptorId, interceptorDefinition, declaringClass, this, apiMetaDataService, localVarsInitialized, true);
String catchCode = catchGenerator.generate();
if (isDebug) {
logger.debug("addAfterInterceptor catch behavior:{} code:{}", behavior.getLongName(), catchCode);
}
CtClass throwable = behavior.getDeclaringClass().getClassPool().get("java.lang.Throwable");
insertCatch(originalCodeOffset, catchCode, throwable, "$e");
InvokeAfterCodeGenerator afterGenerator = new InvokeAfterCodeGenerator(interceptorId, interceptorDefinition, declaringClass, this, apiMetaDataService, localVarsInitialized, false);
final String afterCode = afterGenerator.generate();
if (isDebug) {
logger.debug("addAfterInterceptor after behavior:{} code:{}", behavior.getLongName(), afterCode);
}
behavior.insertAfter(afterCode);
}
use of javassist.CtClass in project pinpoint by naver.
the class JavaAssistTest method innerClass.
@Test
public void innerClass() throws NotFoundException {
CtClass testClass = pool.get("com.navercorp.pinpoint.test.javasssit.TestClass");
logger.debug(testClass.toString());
CtClass[] nestedClasses = testClass.getNestedClasses();
for (CtClass nested : nestedClasses) {
logger.debug("nestedClass:{}", nested);
}
CtClass innerClass = pool.get("com.navercorp.pinpoint.test.javasssit.TestClass$InnerClass");
logger.debug("{}", innerClass);
CtClass class1 = pool.get("com.navercorp.pinpoint.test.javasssit.TestClass$1");
logger.debug("{}", class1);
}
use of javassist.CtClass in project pinpoint by naver.
the class TestBootstrapClass method test.
@Test
public void test() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, IOException, CannotCompileException {
URLClassLoader classLoader = new URLClassLoader(new URL[] {});
LoaderClassPath loaderClassPath = new LoaderClassPath(classLoader);
ClassPool cp = new ClassPool();
cp.appendClassPath(loaderClassPath);
CtClass ctClass = cp.makeClass(TEST_CLASS_NAME);
byte[] bytes = ctClass.toBytecode();
logger.debug(classLoader.getClass().getName());
Class<?> aClass = BytecodeUtils.defineClass(classLoader, TEST_CLASS_NAME, bytes);
logger.debug("{}", aClass.getName());
}
use of javassist.CtClass in project pinpoint by naver.
the class JavaAssistTest method genericTest.
@Test
public void genericTest() throws NotFoundException {
CtClass testClass = pool.get("com.navercorp.pinpoint.test.javasssit.TestClass");
// CtMethod setb = testClass.getMethod("setb");
CtMethod[] declaredMethods = testClass.getDeclaredMethods();
for (CtMethod declaredMethod : declaredMethods) {
logger.debug(declaredMethod.toString());
logger.debug(declaredMethod.getGenericSignature());
logger.debug(declaredMethod.getSignature());
logger.debug("paramTypes:{}", Arrays.toString(declaredMethod.getParameterTypes()));
logger.debug(declaredMethod.getMethodInfo2().getDescriptor());
logger.debug(declaredMethod.getMethodInfo().getDescriptor());
// logger.debug(declaredMethod.());
}
CtMethod setb = testClass.getDeclaredMethod("setA", new CtClass[] { pool.get("int") });
logger.debug(setb.toString());
CtMethod setStringArray = testClass.getDeclaredMethod("setStringArray", new CtClass[] { pool.get("java.lang.String[]") });
logger.debug(setStringArray.toString());
}
Aggregations