org.robolectric.internal.bytecode.ClassNodeProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sandbox Show documentation
Show all versions of sandbox Show documentation
An alternative Android testing framework.
The newest version!
package org.robolectric.internal.bytecode;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.tree.ClassNode;
public abstract class ClassNodeProvider {
private final Map classNodes = new ConcurrentHashMap<>();
protected abstract byte[] getClassBytes(String className) throws ClassNotFoundException;
ClassNode getClassNode(String internalClassName) throws ClassNotFoundException {
ClassNode classNode = classNodes.get(internalClassName);
if (classNode == null) {
classNode = createClassNode(internalClassName);
classNodes.put(internalClassName, classNode);
}
return classNode;
}
private ClassNode createClassNode(String internalClassName) throws ClassNotFoundException {
byte[] byteCode = getClassBytes(internalClassName);
ClassReader classReader = new ClassReader(byteCode);
ClassNode classNode = new ClassNode();
classReader.accept(
classNode, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
return classNode;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy