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<String></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;
}
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) {
}
}
}
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);
}
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());
}
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()]);
}
Aggregations