Search in sources :

Example 21 with ClassFile

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

the class FieldInitLink method replaceClassName.

public void replaceClassName(ClassMap classnames) throws RuntimeException {
    String oldClassName = getName();
    String newClassName = (String) classnames.get(Descriptor.toJvmName(oldClassName));
    if (newClassName != null) {
        newClassName = Descriptor.toJavaName(newClassName);
        // check this in advance although classNameChanged() below does.
        classPool.checkNotFrozen(newClassName);
    }
    super.replaceClassName(classnames);
    ClassFile cf = getClassFile2();
    cf.renameClass(classnames);
    nameReplaced();
    if (newClassName != null) {
        super.setName(newClassName);
        classPool.classNameChanged(oldClassName, this);
    }
}
Also used : ClassFile(org.hotswap.agent.javassist.bytecode.ClassFile)

Example 22 with ClassFile

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

the class FieldInitLink method getModifiers.

public int getModifiers() {
    ClassFile cf = getClassFile2();
    int acc = cf.getAccessFlags();
    acc = AccessFlag.clear(acc, AccessFlag.SUPER);
    int inner = cf.getInnerAccessFlags();
    if (inner != -1 && (inner & AccessFlag.STATIC) != 0)
        acc |= AccessFlag.STATIC;
    return AccessFlag.toModifier(acc);
}
Also used : ClassFile(org.hotswap.agent.javassist.bytecode.ClassFile)

Example 23 with ClassFile

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

the class FieldInitLink method setAttribute.

public void setAttribute(String name, byte[] data) {
    checkModify();
    ClassFile cf = getClassFile2();
    cf.addAttribute(new AttributeInfo(cf.getConstPool(), name, data));
}
Also used : AttributeInfo(org.hotswap.agent.javassist.bytecode.AttributeInfo) ClassFile(org.hotswap.agent.javassist.bytecode.ClassFile)

Example 24 with ClassFile

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

Example 25 with ClassFile

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

the class FieldInitLink method setName.

public void setName(String name) throws RuntimeException {
    String oldname = getName();
    if (name.equals(oldname))
        return;
    // check this in advance although classNameChanged() below does.
    classPool.checkNotFrozen(name);
    ClassFile cf = getClassFile2();
    super.setName(name);
    cf.setName(name);
    nameReplaced();
    classPool.classNameChanged(oldname, this);
}
Also used : ClassFile(org.hotswap.agent.javassist.bytecode.ClassFile)

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