Search in sources :

Example 1 with ClassFile

use of org.hotswap.agent.javassist.bytecode.ClassFile 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 ClassFile

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

the class FieldInitLink method setGenericSignature.

public void setGenericSignature(String sig) {
    ClassFile cf = getClassFile();
    SignatureAttribute sa = new SignatureAttribute(cf.getConstPool(), sig);
    cf.addAttribute(sa);
}
Also used : SignatureAttribute(org.hotswap.agent.javassist.bytecode.SignatureAttribute) ClassFile(org.hotswap.agent.javassist.bytecode.ClassFile)

Example 3 with ClassFile

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

the class FieldInitLink method instrument.

public void instrument(CodeConverter converter) throws CannotCompileException {
    checkModify();
    ClassFile cf = getClassFile2();
    ConstPool cp = cf.getConstPool();
    List list = cf.getMethods();
    int n = list.size();
    for (int i = 0; i < n; ++i) {
        MethodInfo minfo = (MethodInfo) list.get(i);
        converter.doit(this, minfo, cp);
    }
}
Also used : ConstPool(org.hotswap.agent.javassist.bytecode.ConstPool) ClassFile(org.hotswap.agent.javassist.bytecode.ClassFile) ArrayList(java.util.ArrayList) List(java.util.List) MethodInfo(org.hotswap.agent.javassist.bytecode.MethodInfo)

Example 4 with ClassFile

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

the class FieldInitLink method setModifiers.

public void setModifiers(int mod) {
    checkModify();
    updateInnerEntry(mod, getName(), this, true);
    ClassFile cf = getClassFile2();
    cf.setAccessFlags(AccessFlag.of(mod & ~Modifier.STATIC));
}
Also used : ClassFile(org.hotswap.agent.javassist.bytecode.ClassFile)

Example 5 with ClassFile

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

the class FieldInitLink method updateInnerEntry.

private static void updateInnerEntry(int newMod, String name, CtClass clazz, boolean outer) {
    ClassFile cf = clazz.getClassFile2();
    InnerClassesAttribute ica = (InnerClassesAttribute) cf.getAttribute(InnerClassesAttribute.tag);
    if (ica != null) {
        // If the class is a static inner class, its modifier
        // does not contain the static bit.  Its inner class attribute
        // contains the static bit.
        int mod = newMod & ~Modifier.STATIC;
        int i = ica.find(name);
        if (i >= 0) {
            int isStatic = ica.accessFlags(i) & AccessFlag.STATIC;
            if (isStatic != 0 || !Modifier.isStatic(newMod)) {
                clazz.checkModify();
                ica.setAccessFlags(i, AccessFlag.of(mod) | isStatic);
                String outName = ica.outerClass(i);
                if (outName != null && outer)
                    try {
                        CtClass parent = clazz.getClassPool().get(outName);
                        updateInnerEntry(mod, name, parent, false);
                    } catch (NotFoundException e) {
                        throw new RuntimeException("cannot find the declaring class: " + outName);
                    }
                return;
            }
        }
    }
    if (Modifier.isStatic(newMod))
        throw new RuntimeException("cannot change " + Descriptor.toJavaName(name) + " into a static class");
}
Also used : ClassFile(org.hotswap.agent.javassist.bytecode.ClassFile) InnerClassesAttribute(org.hotswap.agent.javassist.bytecode.InnerClassesAttribute)

Aggregations

ClassFile (org.hotswap.agent.javassist.bytecode.ClassFile)28 MethodInfo (org.hotswap.agent.javassist.bytecode.MethodInfo)5 IOException (java.io.IOException)4 InnerClassesAttribute (org.hotswap.agent.javassist.bytecode.InnerClassesAttribute)4 ArrayList (java.util.ArrayList)3 AnnotationsAttribute (org.hotswap.agent.javassist.bytecode.AnnotationsAttribute)3 ParameterAnnotationsAttribute (org.hotswap.agent.javassist.bytecode.ParameterAnnotationsAttribute)3 DataInputStream (java.io.DataInputStream)2 InputStream (java.io.InputStream)2 List (java.util.List)2 EnclosingMethodAttribute (org.hotswap.agent.javassist.bytecode.EnclosingMethodAttribute)2 BufferedInputStream (java.io.BufferedInputStream)1 BufferedOutputStream (java.io.BufferedOutputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataOutputStream (java.io.DataOutputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 LinkedList (java.util.LinkedList)1 CtClass (org.hotswap.agent.javassist.CtClass)1 NotFoundException (org.hotswap.agent.javassist.NotFoundException)1