use of org.hotswap.agent.javassist.CtMethod in project HotswapAgent by HotswapProjects.
the class ELResolverPlugin method patchJBossReflectionUtil.
@OnClassLoadEvent(classNameRegexp = "org.jboss.el.util.ReflectionUtil")
public static void patchJBossReflectionUtil(CtClass ctClass) throws NotFoundException, CannotCompileException {
CtField ctField = new CtField(CtClass.booleanType, "$$ha$haInitialized", ctClass);
ctField.setModifiers(org.hotswap.agent.javassist.Modifier.PRIVATE | org.hotswap.agent.javassist.Modifier.STATIC);
ctClass.addField(ctField, CtField.Initializer.constant(false));
String buildInitializePlugin = PluginManagerInvoker.buildInitializePlugin(ELResolverPlugin.class, "base.getClass().getClassLoader()");
String registerJBossReflectionUtil = PluginManagerInvoker.buildCallPluginMethod("base.getClass().getClassLoader()", ELResolverPlugin.class, "registerJBossReflectionUtil");
CtMethod mFindMethod = ctClass.getDeclaredMethod("findMethod");
mFindMethod.insertAfter("if(!$$ha$haInitialized) {" + "$$ha$haInitialized=true;" + buildInitializePlugin + registerJBossReflectionUtil + "}");
LOGGER.debug("org.jboss.el.util.ReflectionUtil enhanced with resource bundles registration.");
}
use of org.hotswap.agent.javassist.CtMethod in project HotswapAgent by HotswapProjects.
the class ELResolverPlugin method checkJuelEL.
private static boolean checkJuelEL(CtClass ctClass) {
try {
// JUEL, (JSF BeanELResolver[s])
// check if we have purgeBeanClasses method
CtMethod purgeMeth = ctClass.getDeclaredMethod("purgeBeanClasses");
ctClass.addMethod(CtNewMethod.make("public void " + PURGE_CLASS_CACHE_METHOD_NAME + "(java.lang.ClassLoader classLoader) {" + "purgeBeanClasses(classLoader);" + "}", ctClass));
return true;
} catch (NotFoundException | CannotCompileException e) {
// purgeBeanClasses method not found -do nothing
}
return false;
}
use of org.hotswap.agent.javassist.CtMethod in project HotswapAgent by HotswapProjects.
the class ProxyUtil method makeProxy.
/**
* Make proxy.
*
* @param proxy
* the proxy
* @param proxied
* the proxied
* @param classPool
* the class pool
* @param classLoader
* the class loader
* @throws Exception
* the exception
*/
public static void makeProxy(CtClass proxy, CtClass proxied, ClassPool classPool, ClassLoader classLoader) throws Exception {
proxy.setSuperclass(proxied);
for (CtMethod m : proxied.getMethods()) {
int mod = m.getModifiers();
if (//
!Modifier.isFinal(mod) && //
!Modifier.isStatic(mod) && //
isVisible(mod, proxied.getPackageName(), m) && (!m.getDeclaringClass().getName().equals("java.lang.Object"))) {
String meth = toProxy(m);
CtMethod newMethod = CtNewMethod.make(meth, proxy);
proxy.addMethod(newMethod);
}
}
for (CtClass i : proxied.getInterfaces()) {
proxy.addInterface(i);
}
}
use of org.hotswap.agent.javassist.CtMethod in project HotswapAgent by HotswapProjects.
the class ProxyUtil method addMethod.
/**
* Adds the method.
*
* @param classLoader
* the class loader
* @param classPool
* the class pool
* @param clazz
* the clazz
* @param returns
* the returns
* @param method
* the method
* @param args
* the args
* @throws CannotCompileException
* the cannot compile exception
*/
public static void addMethod(ClassLoader classLoader, ClassPool classPool, CtClass clazz, String returns, String method, String[] args) throws CannotCompileException {
try {
CtMethod oldMethod = clazz.getDeclaredMethod(method, getParamTypes(classPool, args));
if (oldMethod != null) {
oldMethod.setName('_' + method);
}
} catch (NotFoundException e) {
}
StringBuilder body = new StringBuilder();
//
body.append(" public ").append(returns).append(' ').append(method).append('(').append(getMethodArgs(args)).append(')').append("{\n");
body.append(" ");
if (!"void".equals(returns)) {
body.append("return ");
}
//
body.append(ReInitializableHelper.class.getName()).append('.').append(method).append('(').append(getCallArgs(args)).append(')').append(";\n");
body.append('}');
CtMethod newMethod = CtNewMethod.make(body.toString(), clazz);
clazz.addMethod(newMethod);
}
use of org.hotswap.agent.javassist.CtMethod in project HotswapAgent by HotswapProjects.
the class Javac method compileMethod.
private CtBehavior compileMethod(Parser p, MethodDecl md) throws CompileError {
int mod = MemberResolver.getModifiers(md.getModifiers());
CtClass[] plist = gen.makeParamList(md);
CtClass[] tlist = gen.makeThrowsList(md);
recordParams(plist, Modifier.isStatic(mod));
md = p.parseMethod2(stable, md);
try {
if (md.isConstructor()) {
CtConstructor cons = new CtConstructor(plist, gen.getThisClass());
cons.setModifiers(mod);
md.accept(gen);
cons.getMethodInfo().setCodeAttribute(bytecode.toCodeAttribute());
cons.setExceptionTypes(tlist);
return cons;
} else {
Declarator r = md.getReturn();
CtClass rtype = gen.resolver.lookupClass(r);
recordReturnType(rtype, false);
CtMethod method = new CtMethod(rtype, r.getVariable().get(), plist, gen.getThisClass());
method.setModifiers(mod);
gen.setThisMethod(method);
md.accept(gen);
if (md.getBody() != null)
method.getMethodInfo().setCodeAttribute(bytecode.toCodeAttribute());
else
method.setModifiers(mod | Modifier.ABSTRACT);
method.setExceptionTypes(tlist);
return method;
}
} catch (NotFoundException e) {
throw new CompileError(e.toString());
}
}
Aggregations