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);
}
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;
}
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;
}
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;
}
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;
}
Aggregations