Search in sources :

Example 66 with ClassPool

use of javassist.ClassPool in project powermock by powermock.

the class ClassMockTransformerTest method shouldIgnoreSyntheticNonBridgeMethods.

@Test
public void shouldIgnoreSyntheticNonBridgeMethods() throws Throwable {
    final ClassPool classPool = new ClassPool(true);
    CtClass ctClass = prepareClassesForTest(classPool, "return;");
    new ClassMockTransformer().transform(ctClass);
    runTestWithNewClassLoader(classPool, ShouldIgnoreSyntheticNonBridgeMethods.class.getName());
}
Also used : CtClass(javassist.CtClass) ClassPool(javassist.ClassPool) Test(org.junit.Test)

Example 67 with ClassPool

use of javassist.ClassPool in project ratpack by ratpack.

the class ClosureBackedHandler method describeTo.

@Override
public void describeTo(StringBuilder stringBuilder) {
    ClosureUtil.SourceInfo sourceInfo = ClosureUtil.getSourceInfo(invoker.getClosure());
    if (sourceInfo == null) {
        ClassPool pool = ClassPool.getDefault();
        try {
            CtClass ctClass = pool.get(invoker.getClosure().getClass().getName());
            CtMethod ctMethod = ctClass.getDeclaredMethod("doCall");
            int lineNumber = ctMethod.getMethodInfo().getLineNumber(0);
            ClassFile classFile = ctClass.getClassFile();
            String sourceFile = classFile.getSourceFile();
            if (lineNumber != -1 && sourceFile != null) {
                stringBuilder.append("closure at line ").append(lineNumber).append(" of ").append(sourceFile);
            } else {
                stringBuilder.append("closure ").append(invoker.getClosure().getClass().getName());
            }
        } catch (NotFoundException e) {
            stringBuilder.append(invoker.getClosure().getClass().getName());
        }
    } else {
        stringBuilder.append("closure at line ").append(sourceInfo.getLineNumber()).append(" of ").append(sourceInfo.getUri());
    }
}
Also used : CtClass(javassist.CtClass) ClassFile(javassist.bytecode.ClassFile) ClassPool(javassist.ClassPool) NotFoundException(javassist.NotFoundException) ClosureUtil(ratpack.groovy.internal.ClosureUtil) CtMethod(javassist.CtMethod)

Example 68 with ClassPool

use of javassist.ClassPool in project pinpoint by naver.

the class TestClassLoader method addTranslator.

public void addTranslator() {
    final InstrumentEngine instrumentEngine = applicationContext.getInstrumentEngine();
    if (instrumentEngine instanceof JavassistEngine) {
        logger.info("JAVASSIST BCI engine");
        ClassPool classPool = ((JavassistEngine) instrumentEngine).getClassPool(this);
        this.instrumentTranslator = new JavassistTranslator(this, classPool, applicationContext.getClassFileTransformerDispatcher());
        this.addTranslator(instrumentTranslator);
    } else if (instrumentEngine instanceof ASMEngine) {
        logger.info("ASM BCI engine");
        this.instrumentTranslator = new DefaultTranslator(this, applicationContext.getClassFileTransformerDispatcher());
        this.addTranslator(instrumentTranslator);
    } else {
        logger.info("Unknown BCI engine");
        this.instrumentTranslator = new DefaultTranslator(this, applicationContext.getClassFileTransformerDispatcher());
        this.addTranslator(instrumentTranslator);
    }
}
Also used : ASMEngine(com.navercorp.pinpoint.profiler.instrument.ASMEngine) JavassistEngine(com.navercorp.pinpoint.profiler.instrument.JavassistEngine) ClassPool(javassist.ClassPool) InstrumentEngine(com.navercorp.pinpoint.profiler.instrument.InstrumentEngine)

Example 69 with ClassPool

use of javassist.ClassPool in project pinpoint by naver.

the class LegacyProfilerPluginClassInjector method loadFromOtherClassLoader.

private Class<?> loadFromOtherClassLoader(ClassLoader classLoader, String className) throws NotFoundException, IllegalArgumentException, IOException, CannotCompileException, IllegalAccessException, InvocationTargetException {
    ClassPool pool = new ClassPool();
    pool.appendClassPath(new LoaderClassPath(classLoader));
    pool.appendClassPath(new LoaderClassPath(sourceClassLoader));
    return loadFromOtherClassLoader(pool, classLoader, className);
}
Also used : ClassPool(javassist.ClassPool) LoaderClassPath(javassist.LoaderClassPath)

Example 70 with ClassPool

use of javassist.ClassPool in project pinpoint by naver.

the class JavassistEngineTest method getTransformByteCode.

public byte[] getTransformByteCode() {
    try {
        final ClassPool pool = new ClassPool(true);
        final CtClass ctClass = pool.get(mock);
        final ConstPool constPool = ctClass.getClassFile2().getConstPool();
        MethodInfo info = new MethodInfo(constPool, "transformMethod", "()V");
        final CtMethod newMethod = CtMethod.make(info, ctClass);
        ctClass.addMethod(newMethod);
        return ctClass.toBytecode();
    } catch (Exception ex) {
        throw new RuntimeException(ex.getMessage(), ex);
    }
}
Also used : CtClass(javassist.CtClass) ConstPool(javassist.bytecode.ConstPool) ClassPool(javassist.ClassPool) MethodInfo(javassist.bytecode.MethodInfo) CtMethod(javassist.CtMethod)

Aggregations

ClassPool (javassist.ClassPool)120 CtClass (javassist.CtClass)93 CtMethod (javassist.CtMethod)48 NotFoundException (javassist.NotFoundException)40 CannotCompileException (javassist.CannotCompileException)28 IOException (java.io.IOException)23 LoaderClassPath (javassist.LoaderClassPath)21 CtField (javassist.CtField)20 CtConstructor (javassist.CtConstructor)17 Test (org.junit.Test)17 ClassFile (javassist.bytecode.ClassFile)15 File (java.io.File)13 Method (java.lang.reflect.Method)13 ByteArrayInputStream (java.io.ByteArrayInputStream)12 ConstPool (javassist.bytecode.ConstPool)12 FileNotFoundException (java.io.FileNotFoundException)11 IllegalClassFormatException (java.lang.instrument.IllegalClassFormatException)9 AnnotationsAttribute (javassist.bytecode.AnnotationsAttribute)9 ClassClassPath (javassist.ClassClassPath)7 MethodInfo (javassist.bytecode.MethodInfo)7