use of org.apache.tapestry5.internal.plastic.asm.tree.ClassNode in project tapestry-5 by apache.
the class CheckClassAdapter method verify.
/**
* Checks the given class.
*
* @param classReader the class to be checked.
* @param loader a <code>ClassLoader</code> which will be used to load referenced classes. May be
* {@literal null}.
* @param printResults whether to print the results of the bytecode verification.
* @param printWriter where the results (or the stack trace in case of error) must be printed.
*/
public static void verify(final ClassReader classReader, final ClassLoader loader, final boolean printResults, final PrintWriter printWriter) {
ClassNode classNode = new ClassNode();
classReader.accept(new CheckClassAdapter(/*latest*/
Opcodes.ASM10_EXPERIMENTAL, classNode, false) {
}, ClassReader.SKIP_DEBUG);
Type syperType = classNode.superName == null ? null : Type.getObjectType(classNode.superName);
List<MethodNode> methods = classNode.methods;
List<Type> interfaces = new ArrayList<>();
for (String interfaceName : classNode.interfaces) {
interfaces.add(Type.getObjectType(interfaceName));
}
for (MethodNode method : methods) {
SimpleVerifier verifier = new SimpleVerifier(Type.getObjectType(classNode.name), syperType, interfaces, (classNode.access & Opcodes.ACC_INTERFACE) != 0);
Analyzer<BasicValue> analyzer = new Analyzer<>(verifier);
if (loader != null) {
verifier.setClassLoader(loader);
}
try {
analyzer.analyze(classNode.name, method);
} catch (AnalyzerException e) {
e.printStackTrace(printWriter);
}
if (printResults) {
printAnalyzerResult(method, analyzer, printWriter);
}
}
printWriter.flush();
}
use of org.apache.tapestry5.internal.plastic.asm.tree.ClassNode in project tapestry-5 by apache.
the class PlasticClassPool method toBytecode.
private byte[] toBytecode(ClassNode classNode) {
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
classNode.accept(writer);
return writer.toByteArray();
}
use of org.apache.tapestry5.internal.plastic.asm.tree.ClassNode in project tapestry-5 by apache.
the class PlasticClassPool method readClassNode.
static ClassNode readClassNode(String className, ClassLoader classLoader) throws IOException {
ClassNode classNode = new ClassNode();
final String location = PlasticInternalUtils.toInternalName(className) + ".class";
InputStream inputStream = classLoader.getResourceAsStream(location);
BufferedInputStream bis = new BufferedInputStream(inputStream);
ClassReader classReader = new ClassReader(inputStream);
inputStream.close();
bis.close();
classReader.accept(classNode, 0);
return classNode;
}
use of org.apache.tapestry5.internal.plastic.asm.tree.ClassNode in project tapestry-5 by apache.
the class PlasticInternalUtils method convertBytecodeToClassNode.
public static ClassNode convertBytecodeToClassNode(byte[] bytecode) {
ClassReader cr = new ClassReader(bytecode);
ClassNode result = new ClassNode();
ClassVisitor adapter = new ClassVisitor(Opcodes.ASM9, result) {
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
MethodVisitor delegate = super.visitMethod(access, name, desc, signature, exceptions);
return new JSRInlinerAdapter(delegate, access, name, desc, signature, exceptions);
}
};
cr.accept(adapter, 0);
return result;
}
use of org.apache.tapestry5.internal.plastic.asm.tree.ClassNode in project tapestry-5 by apache.
the class PlasticInternalUtils method dissasembleBytecode.
public static String dissasembleBytecode(ClassNode classNode) {
StringWriter stringWriter = new StringWriter();
PrintWriter writer = new PrintWriter(stringWriter);
TraceClassVisitor visitor = new TraceClassVisitor(writer);
classNode.accept(visitor);
writer.close();
return stringWriter.toString();
}
Aggregations