use of org.hotswap.agent.javassist.bytecode.ClassFile in project HotswapAgent by HotswapProjects.
the class FieldInitLink method subtypeOf.
public boolean subtypeOf(CtClass clazz) throws NotFoundException {
int i;
String cname = clazz.getName();
if (this == clazz || getName().equals(cname))
return true;
ClassFile file = getClassFile2();
String supername = file.getSuperclass();
if (supername != null && supername.equals(cname))
return true;
String[] ifs = file.getInterfaces();
int num = ifs.length;
for (i = 0; i < num; ++i) if (ifs[i].equals(cname))
return true;
if (supername != null && classPool.get(supername).subtypeOf(clazz))
return true;
for (i = 0; i < num; ++i) if (classPool.get(ifs[i]).subtypeOf(clazz))
return true;
return false;
}
use of org.hotswap.agent.javassist.bytecode.ClassFile in project HotswapAgent by HotswapProjects.
the class ClassPathAnnotationScanner method scanPlugins.
/**
* Run the scan - search path for files containing annotation.
*
* @param classLoader classloader to resolve path
* @param path path to scan {@link org.hotswap.agent.util.scanner.Scanner#scan(ClassLoader, String, ScannerVisitor)}
* @return list of class names containing the annotation
* @throws IOException scan exception.
*/
public List<String> scanPlugins(ClassLoader classLoader, String path) throws IOException {
final List<String> files = new LinkedList<String>();
scanner.scan(classLoader, path, new ScannerVisitor() {
@Override
public void visit(InputStream file) throws IOException {
ClassFile cf;
try {
DataInputStream dstream = new DataInputStream(file);
cf = new ClassFile(dstream);
} catch (IOException e) {
throw new IOException("Stream not a valid classFile", e);
}
if (hasAnnotation(cf))
files.add(cf.getName());
}
});
return files;
}
use of org.hotswap.agent.javassist.bytecode.ClassFile in project HotswapAgent by HotswapProjects.
the class FactoryHelper method writeFile0.
private static void writeFile0(ClassFile cf, String directoryName) throws CannotCompileException, IOException {
String classname = cf.getName();
String filename = directoryName + File.separatorChar + classname.replace('.', File.separatorChar) + ".class";
int pos = filename.lastIndexOf(File.separatorChar);
if (pos > 0) {
String dir = filename.substring(0, pos);
if (!dir.equals("."))
new File(dir).mkdirs();
}
DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(filename)));
try {
cf.write(out);
} catch (IOException e) {
throw e;
} finally {
out.close();
}
}
use of org.hotswap.agent.javassist.bytecode.ClassFile in project HotswapAgent by HotswapProjects.
the class Dump method main.
/**
* Main method.
*
* @param args <code>args[0]</code> is the class file name.
*/
public static void main(String[] args) throws Exception {
if (args.length != 1) {
System.err.println("Usage: java Dump <class file name>");
return;
}
DataInputStream in = new DataInputStream(new FileInputStream(args[0]));
ClassFile w = new ClassFile(in);
PrintWriter out = new PrintWriter(System.out, true);
out.println("*** constant pool ***");
w.getConstPool().print(out);
out.println();
out.println("*** members ***");
ClassFilePrinter.print(w, out);
}
use of org.hotswap.agent.javassist.bytecode.ClassFile in project HotswapAgent by HotswapProjects.
the class AnnotationImpl method getDefault.
private Object getDefault(String name, Method method) throws ClassNotFoundException, RuntimeException {
String classname = annotation.getTypeName();
if (pool != null) {
try {
CtClass cc = pool.get(classname);
ClassFile cf = cc.getClassFile2();
MethodInfo minfo = cf.getMethod(name);
if (minfo != null) {
AnnotationDefaultAttribute ainfo = (AnnotationDefaultAttribute) minfo.getAttribute(AnnotationDefaultAttribute.tag);
if (ainfo != null) {
MemberValue mv = ainfo.getDefaultValue();
return mv.getValue(classLoader, pool, method);
}
}
} catch (NotFoundException e) {
throw new RuntimeException("cannot find a class file: " + classname);
}
}
throw new RuntimeException("no default value: " + classname + "." + name + "()");
}
Aggregations