Search in sources :

Example 11 with NotFoundException

use of org.hotswap.agent.javassist.NotFoundException 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);
}
Also used : NotFoundException(org.hotswap.agent.javassist.NotFoundException) CtMethod(org.hotswap.agent.javassist.CtMethod) ReInitializableHelper(org.hotswap.agent.plugin.hibernate3.session.proxy.ReInitializableHelper)

Example 12 with NotFoundException

use of org.hotswap.agent.javassist.NotFoundException in project HotswapAgent by HotswapProjects.

the class Type method getDeclaredInterfaces.

Map getDeclaredInterfaces(CtClass clazz, Map map) {
    if (map == null)
        map = new HashMap();
    if (clazz.isInterface())
        map.put(clazz.getName(), clazz);
    CtClass[] interfaces;
    try {
        interfaces = clazz.getInterfaces();
    } catch (NotFoundException e) {
        throw new RuntimeException(e);
    }
    for (int i = 0; i < interfaces.length; i++) {
        CtClass intf = interfaces[i];
        map.put(intf.getName(), intf);
        getDeclaredInterfaces(intf, map);
    }
    return map;
}
Also used : CtClass(org.hotswap.agent.javassist.CtClass) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) NotFoundException(org.hotswap.agent.javassist.NotFoundException)

Example 13 with NotFoundException

use of org.hotswap.agent.javassist.NotFoundException in project HotswapAgent by HotswapProjects.

the class Type method getAllInterfaces.

Map getAllInterfaces(CtClass clazz, Map map) {
    if (map == null)
        map = new HashMap();
    if (clazz.isInterface())
        map.put(clazz.getName(), clazz);
    do {
        try {
            CtClass[] interfaces = clazz.getInterfaces();
            for (int i = 0; i < interfaces.length; i++) {
                CtClass intf = interfaces[i];
                map.put(intf.getName(), intf);
                getAllInterfaces(intf, map);
            }
            clazz = clazz.getSuperclass();
        } catch (NotFoundException e) {
            throw new RuntimeException(e);
        }
    } while (clazz != null);
    return map;
}
Also used : CtClass(org.hotswap.agent.javassist.CtClass) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) NotFoundException(org.hotswap.agent.javassist.NotFoundException)

Example 14 with NotFoundException

use of org.hotswap.agent.javassist.NotFoundException in project HotswapAgent by HotswapProjects.

the class Type method findCommonInterfaces.

Map findCommonInterfaces(Map typeMap, Map alterMap) {
    Iterator i = alterMap.keySet().iterator();
    while (i.hasNext()) {
        if (!typeMap.containsKey(i.next()))
            i.remove();
    }
    // Reduce to subinterfaces
    // This does not need to be recursive since we make a copy,
    // and that copy contains all super types for the whole hierarchy
    i = new ArrayList(alterMap.values()).iterator();
    while (i.hasNext()) {
        CtClass intf = (CtClass) i.next();
        CtClass[] interfaces;
        try {
            interfaces = intf.getInterfaces();
        } catch (NotFoundException e) {
            throw new RuntimeException(e);
        }
        for (int c = 0; c < interfaces.length; c++) alterMap.remove(interfaces[c].getName());
    }
    return alterMap;
}
Also used : CtClass(org.hotswap.agent.javassist.CtClass) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) NotFoundException(org.hotswap.agent.javassist.NotFoundException)

Example 15 with NotFoundException

use of org.hotswap.agent.javassist.NotFoundException in project HotswapAgent by HotswapProjects.

the class Analyzer method buildExceptionInfo.

private ExceptionInfo[] buildExceptionInfo(MethodInfo method) {
    ConstPool constPool = method.getConstPool();
    ClassPool classes = clazz.getClassPool();
    ExceptionTable table = method.getCodeAttribute().getExceptionTable();
    ExceptionInfo[] exceptions = new ExceptionInfo[table.size()];
    for (int i = 0; i < table.size(); i++) {
        int index = table.catchType(i);
        Type type;
        try {
            type = index == 0 ? Type.THROWABLE : Type.get(classes.get(constPool.getClassInfo(index)));
        } catch (NotFoundException e) {
            throw new IllegalStateException(e.getMessage());
        }
        exceptions[i] = new ExceptionInfo(table.startPc(i), table.endPc(i), table.handlerPc(i), type);
    }
    return exceptions;
}
Also used : ConstPool(org.hotswap.agent.javassist.bytecode.ConstPool) ClassPool(org.hotswap.agent.javassist.ClassPool) NotFoundException(org.hotswap.agent.javassist.NotFoundException) ExceptionTable(org.hotswap.agent.javassist.bytecode.ExceptionTable)

Aggregations

NotFoundException (org.hotswap.agent.javassist.NotFoundException)33 CtClass (org.hotswap.agent.javassist.CtClass)19 CtMethod (org.hotswap.agent.javassist.CtMethod)15 OnClassLoadEvent (org.hotswap.agent.annotation.OnClassLoadEvent)8 CannotCompileException (org.hotswap.agent.javassist.CannotCompileException)8 CtField (org.hotswap.agent.javassist.CtField)7 CtConstructor (org.hotswap.agent.javassist.CtConstructor)5 ClassPool (org.hotswap.agent.javassist.ClassPool)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 IdentityHashMap (java.util.IdentityHashMap)2 BadBytecode (org.hotswap.agent.javassist.bytecode.BadBytecode)2 ConstPool (org.hotswap.agent.javassist.bytecode.ConstPool)2 ExceptionTable (org.hotswap.agent.javassist.bytecode.ExceptionTable)2 ExprEditor (org.hotswap.agent.javassist.expr.ExprEditor)2 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1