Search in sources :

Example 16 with ClassFile

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

the class CtClass method getRefClasses.

/**
 * Returns a collection of the names of all the classes
 * referenced in this class.
 * That collection includes the name of this class.
 *
 * <p>This method may return <code>null</code>.
 *
 * @return a <code>Collection&lt;String&gt;</code> object.
 */
public synchronized Collection getRefClasses() {
    ClassFile cf = getClassFile2();
    if (cf != null) {
        ClassMap cm = new ClassMap() {

            public void put(String oldname, String newname) {
                put0(oldname, newname);
            }

            public Object get(Object jvmClassName) {
                String n = toJavaName((String) jvmClassName);
                put0(n, n);
                return null;
            }

            public void fix(String name) {
            }
        };
        cf.getRefClasses(cm);
        return cm.values();
    } else
        return null;
}
Also used : ClassFile(org.hotswap.agent.javassist.bytecode.ClassFile)

Example 17 with ClassFile

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

the class FieldInitLink method getClassFile3.

public ClassFile getClassFile3(boolean doCompress) {
    ClassFile cfile = classfile;
    if (cfile != null)
        return cfile;
    if (doCompress)
        classPool.compress();
    if (rawClassfile != null) {
        try {
            ClassFile cf = new ClassFile(new DataInputStream(new ByteArrayInputStream(rawClassfile)));
            rawClassfile = null;
            getCount = GET_THRESHOLD;
            return setClassFile(cf);
        } catch (IOException e) {
            throw new RuntimeException(e.toString(), e);
        }
    }
    InputStream fin = null;
    try {
        fin = classPool.openClassfile(getName());
        if (fin == null)
            throw new NotFoundException(getName());
        fin = new BufferedInputStream(fin);
        ClassFile cf = new ClassFile(new DataInputStream(fin));
        if (!cf.getName().equals(qualifiedName))
            throw new RuntimeException("cannot find " + qualifiedName + ": " + cf.getName() + " found in " + qualifiedName.replace('.', '/') + ".class");
        return setClassFile(cf);
    } catch (NotFoundException e) {
        throw new RuntimeException(e.toString(), e);
    } catch (IOException e) {
        throw new RuntimeException(e.toString(), e);
    } finally {
        if (fin != null)
            try {
                fin.close();
            } catch (IOException e) {
            }
    }
}
Also used : ClassFile(org.hotswap.agent.javassist.bytecode.ClassFile) ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedInputStream(java.io.BufferedInputStream) DataInputStream(java.io.DataInputStream) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream)

Example 18 with ClassFile

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

the class FieldInitLink method getAnnotation.

public Object getAnnotation(Class clz) throws ClassNotFoundException {
    ClassFile cf = getClassFile2();
    AnnotationsAttribute ainfo = (AnnotationsAttribute) cf.getAttribute(AnnotationsAttribute.invisibleTag);
    AnnotationsAttribute ainfo2 = (AnnotationsAttribute) cf.getAttribute(AnnotationsAttribute.visibleTag);
    return getAnnotationType(clz, 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 19 with ClassFile

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

the class FieldInitLink method removeConstructor.

public void removeConstructor(CtConstructor 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 20 with ClassFile

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

the class FieldInitLink method getNestedClasses.

public CtClass[] getNestedClasses() throws NotFoundException {
    ClassFile cf = getClassFile2();
    InnerClassesAttribute ica = (InnerClassesAttribute) cf.getAttribute(InnerClassesAttribute.tag);
    if (ica == null)
        return new CtClass[0];
    String thisName = cf.getName() + "$";
    int n = ica.tableLength();
    ArrayList list = new ArrayList(n);
    for (int i = 0; i < n; i++) {
        String name = ica.innerClass(i);
        if (name != null)
            if (name.startsWith(thisName)) {
                // if it is an immediate nested class
                if (name.lastIndexOf('$') < thisName.length())
                    list.add(classPool.get(name));
            }
    }
    return (CtClass[]) list.toArray(new CtClass[list.size()]);
}
Also used : ClassFile(org.hotswap.agent.javassist.bytecode.ClassFile) ArrayList(java.util.ArrayList) 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