Search in sources :

Example 1 with AnnotationDefaultAttribute

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

the class AnnotationImpl method getDefault.

private Object getDefault(String name, Method method) throws ClassNotFoundException, RuntimeException {
    String classname = annotation.getTypeName();
    if (pool != null) {
        try {
            CtClass cc = pool.get(classname);
            ClassFile cf = cc.getClassFile2();
            MethodInfo minfo = cf.getMethod(name);
            if (minfo != null) {
                AnnotationDefaultAttribute ainfo = (AnnotationDefaultAttribute) minfo.getAttribute(AnnotationDefaultAttribute.tag);
                if (ainfo != null) {
                    MemberValue mv = ainfo.getDefaultValue();
                    return mv.getValue(classLoader, pool, method);
                }
            }
        } catch (NotFoundException e) {
            throw new RuntimeException("cannot find a class file: " + classname);
        }
    }
    throw new RuntimeException("no default value: " + classname + "." + name + "()");
}
Also used : CtClass(org.hotswap.agent.javassist.CtClass) ClassFile(org.hotswap.agent.javassist.bytecode.ClassFile) AnnotationDefaultAttribute(org.hotswap.agent.javassist.bytecode.AnnotationDefaultAttribute) NotFoundException(org.hotswap.agent.javassist.NotFoundException) MethodInfo(org.hotswap.agent.javassist.bytecode.MethodInfo)

Aggregations

CtClass (org.hotswap.agent.javassist.CtClass)1 NotFoundException (org.hotswap.agent.javassist.NotFoundException)1 AnnotationDefaultAttribute (org.hotswap.agent.javassist.bytecode.AnnotationDefaultAttribute)1 ClassFile (org.hotswap.agent.javassist.bytecode.ClassFile)1 MethodInfo (org.hotswap.agent.javassist.bytecode.MethodInfo)1