Search in sources :

Example 6 with ClassFile

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

the class FieldInitLink method instrument.

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

Example 7 with ClassFile

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

the class FieldInitLink method removeMethod.

public void removeMethod(CtMethod m) throws NotFoundException {
    checkModify();
    MethodInfo mi = m.getMethodInfo2();
    ClassFile cf = getClassFile2();
    if (cf.getMethods().remove(mi)) {
        getMembers().remove(m);
        gcConstPool = true;
    } else
        throw new NotFoundException(m.toString());
}
Also used : ClassFile(org.hotswap.agent.javassist.bytecode.ClassFile) MethodInfo(org.hotswap.agent.javassist.bytecode.MethodInfo)

Example 8 with ClassFile

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

the class FieldInitLink method hasAnnotation.

// @Override
public boolean hasAnnotation(String annotationName) {
    ClassFile cf = getClassFile2();
    AnnotationsAttribute ainfo = (AnnotationsAttribute) cf.getAttribute(AnnotationsAttribute.invisibleTag);
    AnnotationsAttribute ainfo2 = (AnnotationsAttribute) cf.getAttribute(AnnotationsAttribute.visibleTag);
    return hasAnnotationType(annotationName, getClassPool(), ainfo, ainfo2);
}
Also used : ClassFile(org.hotswap.agent.javassist.bytecode.ClassFile) AnnotationsAttribute(org.hotswap.agent.javassist.bytecode.AnnotationsAttribute) ParameterAnnotationsAttribute(org.hotswap.agent.javassist.bytecode.ParameterAnnotationsAttribute)

Example 9 with ClassFile

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

the class FieldInitLink method removeField.

public void removeField(CtField f) throws NotFoundException {
    checkModify();
    FieldInfo fi = f.getFieldInfo2();
    ClassFile cf = getClassFile2();
    if (cf.getFields().remove(fi)) {
        getMembers().remove(f);
        gcConstPool = true;
    } else
        throw new NotFoundException(f.toString());
}
Also used : ClassFile(org.hotswap.agent.javassist.bytecode.ClassFile) FieldInfo(org.hotswap.agent.javassist.bytecode.FieldInfo)

Example 10 with ClassFile

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

the class FieldInitLink method makeNestedClass.

public CtClass makeNestedClass(String name, boolean isStatic) {
    if (!isStatic)
        throw new RuntimeException("sorry, only nested static class is supported");
    checkModify();
    CtClass c = classPool.makeNestedClass(getName() + "$" + name);
    ClassFile cf = getClassFile2();
    ClassFile cf2 = c.getClassFile2();
    InnerClassesAttribute ica = (InnerClassesAttribute) cf.getAttribute(InnerClassesAttribute.tag);
    if (ica == null) {
        ica = new InnerClassesAttribute(cf.getConstPool());
        cf.addAttribute(ica);
    }
    ica.append(c.getName(), this.getName(), name, (cf2.getAccessFlags() & ~AccessFlag.SUPER) | AccessFlag.STATIC);
    cf2.addAttribute(ica.copy(cf2.getConstPool(), null));
    return c;
}
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