use of javassist.ClassPool in project hibernate-orm by hibernate.
the class EnhancerImpl method buildClassPool.
private ClassPool buildClassPool(JavassistEnhancementContext enhancementContext) {
ClassPool classPool = new ClassPool(false) {
@Override
public ClassLoader getClassLoader() {
return enhancementContext.getLoadingClassLoader();
}
};
ClassLoader loadingClassLoader = enhancementContext.getLoadingClassLoader();
if (loadingClassLoader != null) {
classPool.appendClassPath(new LoaderClassPath(loadingClassLoader));
}
return 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());
}
}
use of javassist.ClassPool in project powermock by powermock.
the class ConcreteClassGenerator method createConcreteSubClass.
public Class<?> createConcreteSubClass(Class<?> clazz) {
if (clazz == null) {
throw new IllegalArgumentException("clazz cannot be null");
}
if (!java.lang.reflect.Modifier.isAbstract(clazz.getModifiers())) {
throw new IllegalArgumentException("clazz must be abstract");
}
ClassPool classpool = ClassPool.getDefault();
final String originalClassName = clazz.getName();
final CtClass originalClassAsCtClass;
final CtClass newClass = classpool.makeClass(generateClassName(clazz));
try {
newClass.setSuperclass(classpool.get(clazz.getName()));
} catch (Exception e1) {
throw new RuntimeException(e1);
}
try {
originalClassAsCtClass = classpool.get(originalClassName);
CtMethod[] declaredMethods = originalClassAsCtClass.getDeclaredMethods();
for (CtMethod ctMethod : declaredMethods) {
if (Modifier.isAbstract(ctMethod.getModifiers())) {
final String code = getReturnCode(ctMethod.getReturnType());
CtNewMethod.make(ctMethod.getReturnType(), ctMethod.getName(), ctMethod.getParameterTypes(), ctMethod.getExceptionTypes(), code, newClass);
}
}
if (!hasInheritableConstructor(originalClassAsCtClass)) {
return null;
}
return newClass.toClass(this.getClass().getClassLoader(), this.getClass().getProtectionDomain());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
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());
}
use of javassist.ClassPool in project dubbo by alibaba.
the class ClassGenerator method getClassPool.
public static ClassPool getClassPool(ClassLoader loader) {
if (loader == null)
return ClassPool.getDefault();
ClassPool pool = POOL_MAP.get(loader);
if (pool == null) {
pool = new ClassPool(true);
pool.appendClassPath(new LoaderClassPath(loader));
POOL_MAP.put(loader, pool);
}
return pool;
}
Aggregations