Search in sources :

Example 1 with EnclosingMethodAttribute

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

the class FieldInitLink method getEnclosingBehavior.

public CtBehavior getEnclosingBehavior() throws NotFoundException {
    ClassFile cf = getClassFile2();
    EnclosingMethodAttribute ema = (EnclosingMethodAttribute) cf.getAttribute(EnclosingMethodAttribute.tag);
    if (ema == null)
        return null;
    else {
        CtClass enc = classPool.get(ema.className());
        String name = ema.methodName();
        if (MethodInfo.nameInit.equals(name))
            return enc.getConstructor(ema.methodDescriptor());
        else if (MethodInfo.nameClinit.equals(name))
            return enc.getClassInitializer();
        else
            return enc.getMethod(name, ema.methodDescriptor());
    }
}
Also used : ClassFile(org.hotswap.agent.javassist.bytecode.ClassFile) EnclosingMethodAttribute(org.hotswap.agent.javassist.bytecode.EnclosingMethodAttribute)

Example 2 with EnclosingMethodAttribute

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

the class FieldInitLink method getDeclaringClass.

public CtClass getDeclaringClass() throws NotFoundException {
    ClassFile cf = getClassFile2();
    InnerClassesAttribute ica = (InnerClassesAttribute) cf.getAttribute(InnerClassesAttribute.tag);
    if (ica == null)
        return null;
    String name = getName();
    int n = ica.tableLength();
    for (int i = 0; i < n; ++i) if (name.equals(ica.innerClass(i))) {
        String outName = ica.outerClass(i);
        if (outName != null)
            return classPool.get(outName);
        else {
            // maybe anonymous or local class.
            EnclosingMethodAttribute ema = (EnclosingMethodAttribute) cf.getAttribute(EnclosingMethodAttribute.tag);
            if (ema != null)
                return classPool.get(ema.className());
        }
    }
    return null;
}
Also used : ClassFile(org.hotswap.agent.javassist.bytecode.ClassFile) InnerClassesAttribute(org.hotswap.agent.javassist.bytecode.InnerClassesAttribute) EnclosingMethodAttribute(org.hotswap.agent.javassist.bytecode.EnclosingMethodAttribute)

Aggregations

ClassFile (org.hotswap.agent.javassist.bytecode.ClassFile)2 EnclosingMethodAttribute (org.hotswap.agent.javassist.bytecode.EnclosingMethodAttribute)2 InnerClassesAttribute (org.hotswap.agent.javassist.bytecode.InnerClassesAttribute)1